   SDL -> OpenGL texture problem.
  Hi,I am having some problems trying to create a opengl texture from a SDL surface.When I have GL_NEAREST it works:glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_NEAREST);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_NEAREST);But then the textures look to pixelated so I tried this.glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);And now my textures wont display. Only a white rectangle in its place..I use the code from the file "testgl.c" found in the SDL source distrubution to create my texture: int MADTexture::Power_of_two(int input){int value = 1;while ( value < input ) {value <<= 1;}return value;}GLuint MADTexture::SDL_GL_LoadTexture(SDL_Surface *surface, GLfloat *texcoord){GLuint texture;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);texcoord[0] = 0.0f;/* Min X */texcoord[1] = 0.0f;/* Min Y */texcoord[2] = (GLfloat)surface->w / w;/* Max X */texcoord[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#else0xFF000000,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, &texture);glBindTexture(GL_TEXTURE_2D, texture);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,w, h,0,GL_RGBA,GL_UNSIGNED_BYTE,image->pixels);SDL_FreeSurface(image); /* No longer needed */return texture;}  Any suggestions ?Thanks =)[edited by - adam_ on February 15, 2004 1:06:01 PM][edited by - adam_ on February 16, 2004 7:45:31 PM]
  GL_LINEAR_MIPMAP_NEAREST requires a complete mipmap set to work, so you have to upload all mipmap levels. Or just set the minification filter to something that does not require a full mipmap set, like GL_LINEAR. ;  Hi,use the GL_BGR_EXT as parameter for glTexImage2D instead of GL_RGBA.It has something to do with the bits of the bitmap (8,16,32 etc)But i know that it works with a 24bit bmp and GL_RGB_EXT, when createing the surface with SDL_LoadBMP.try the following LoadBMP function (from Nehes Tutorial, Lesson 8.. modified for SDL: int LoadGLTextures( void ){    int Status  = FALSE;    // Create Storage Space For The Texture    SDL_Surface *TextureImage[1];    TextureImage[0] = NULL;    // Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit    TextureImage[0] = SDL_LoadBMP("textures/job.bmp");    if ( TextureImage[0] != NULL )    {   // Set The Status To TRUEStatus = TRUE;  // Create 3 Textures   glGenTextures(3, &texture[0]);    // Create Nearest Filtered TextureglBindTexture(GL_TEXTURE_2D, texture[0]);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);    fprintf(stderr,"glBindTexture()\n");   // Generate The TextureglTexImage2D(GL_TEXTURE_2D, 0, 3,  TextureImage[0]->w,  TextureImage[0]->h, 0,  GL_BGR_EXT, GL_UNSIGNED_BYTE,  TextureImage[0]->pixels);   fprintf(stderr,"glTexImage2D() 0\n");   // Create Linear Filtered TextureglBindTexture(GL_TEXTURE_2D, texture[1]);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);   // Generate The TextureglTexImage2D(GL_TEXTURE_2D, 0, 3,  TextureImage[0]->w,  TextureImage[0]->h, 0,  GL_BGR_EXT, GL_UNSIGNED_BYTE,  TextureImage[0]->pixels);    fprintf(stderr,"glTexImage2D() 1\n");// Create MipMapped TextureglBindTexture(GL_TEXTURE_2D, texture[2]);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); // ( NEW )   gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->w, TextureImage[0]->h, GL_BGR_EXT, GL_UNSIGNED_BYTE, TextureImage[0]->pixels);    }    // If Texture Exists    if ( TextureImage[0] != NULL )    {   // Free The Image StructureSDL_FreeSurface(TextureImage[0]);    }   return Status;}Lazzar   [edited by - Lazzar on February 16, 2004 7:31:48 AM] [edited by - Lazzar on February 16, 2004 7:33:57 AM];  Hi,Thanks for your answers.I have tried your code, but I get the follwoing error message from the compiler (Dev-Cpp 4.9.8.5). :**************************************************************In member function `GLuint MADTexture::LoadGLTextures(char*)':`GL_BGR_EXT' undeclared (first use this function)(Each undeclared identifier is reported only once for each [Build Error]  [MADTexture.o] Error 1**************************************************************My first tought was that I might not have the latest OpenGL headers. If that could be the case, where can I find them?Thanks.. [edited by - adam_ on February 16, 2004 7:43:34 PM];  if you would now care to mention what os youre using maybe somebody could answer that. even with the wrong color format you should see _something_. at least after you either throw out the mipmap filter or use mipmaps, but you CANT use trilinear filtering without having mipmaps.frankly, if it worked with nearest and doesnt just because you changed the filter it should be obvious that the color has nothing to do with it. ;  I am using Windows XP Pro.I got the first code to work with GL_LINEAR_MIPMAP_LINERAR.But the textures still dont look like they should, they are smoothed out and a little blurry. I tried different combinations of filtering but couldnt get it right.So what I would like to know is how do I load a *.bmp in a way that it will retain its exact colors and not be blurry?Thanks..   [edited by - adam_ on February 17, 2004 4:13:16 AM];  You need to grab a copy of glext.h and include it.  This will define the token ''GL_BGR_EXT''.Enigma 