#include "opengl.h" #include "material.h" material::~material () { } void simple_material::begin () { glMaterialfv (GL_FRONT, GL_DIFFUSE, (GLfloat *) & diffuse); glMaterialfv (GL_FRONT, GL_SPECULAR, (GLfloat *) & specular); glMaterialfv (GL_FRONT, GL_EMISSION, (GLfloat *) & emission); glMaterialf (GL_FRONT, GL_SHININESS, shininess); } void simple_material::end () { } void osama_material::begin () { cgGLEnableProfile (vsh_profile); cgGLEnableProfile (fsh_profile); cgGLEnableTextureParameter (g_Texture); } void osama_material::end () { cgGLDisableTextureParameter (g_Texture); // cgGLUnbindProgram (vsh_profile); // cgGLUnbindProgram (fsh_profile); cgGLDisableProfile (vsh_profile); cgGLDisableProfile (fsh_profile); } GLuint texture::load_texture (SDL_Surface * surface, GLfloat * tex2oord) { GLuint textur; int w, h; SDL_Surface *image; SDL_Rect area; Uint32 saved_flags; Uint8 saved_alpha; /* Use the surface width and height expanded to powers of 2 */ //w = power_of_two (surface->w); //h = power_of_two (surface->h); w = power_of_two (surface->w); h = power_of_two (surface->h); tex2oord[0] = 0.0f; /* Min X */ tex2oord[1] = 0.0f; /* Min Y */ tex2oord[2] = (GLfloat) surface->w / w; /* Max X */ tex2oord[3] = (GLfloat) surface->h / h; /* Max Y */ image = SDL_CreateRGBSurface (SDL_SWSURFACE, w, h, 32, #if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */ 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000 #else 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF #endif ); if (image == NULL) return 0; /* Save the alpha blending attributes */ saved_flags = surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK); saved_alpha = surface->format->alpha; if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA) SDL_SetAlpha (surface, 0, 0); /* Copy the surface into the GL texture image */ area.x = 0; area.y = 0; area.w = surface->w; area.h = surface->h; SDL_BlitSurface (surface, &area, image, &area); /* Restore the alpha blending attributes */ if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA) SDL_SetAlpha (surface, saved_flags, saved_alpha); /* Create an OpenGL texture for the image */ glGenTextures (1, &textur); glBindTexture (GL_TEXTURE_2D, textur); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri (GL_TEXTURE_2D, 0x8191, GL_TRUE); // GENERATE_MIPMAP_SGIS glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels); SDL_FreeSurface (image); /* No longer needed */ return textur; } CGcontext cgc; void init_shaders () { cgc = cgCreateContext (); }