REPLY: does OpenGL care about color depth of surfaces? plus more Q

first, i want to apologize that this isnt direct reply to my post. for some
reason, when i click “follow up”, and try to post hte message, it gives an error
"you are top posting, dont do that". i tried for about 5 minutes trying to
figure out how to reply, but it just wouldnt let me…

thanks guys, but does anyone have any clue why my program crashes when i call

SDL_Surface *img2 =
SDL_CreateRGBSurface(SDL_SWSURFACE,img->w,img->h,video_info->vfmt->BitsPerPixel,
0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);

first, i want to apologize that this isnt direct reply to my post. for some
reason, when i click “follow up”, and try to post hte message, it gives an error
"you are top posting, dont do that". i tried for about 5 minutes trying to
figure out how to reply, but it just wouldnt let me…

thanks guys, but does anyone have any clue why my program crashes when i call

SDL_Surface *img2 =
SDL_CreateRGBSurface(SDL_SWSURFACE,img->w,img->h,video_info->vfmt->BitsPerPixel,
0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);

That’s about what I do, except I replace video_info->vfmt->BitsPerPixel with 32.
When using OpenGL, there are three different meanings to the “bits per pixel” thing :

  • the bpp at which OpenGL displays the graphics. This has no implication on your code except perhaps on the graphics initialization (this has an effect on graphics rendering quality, though).
  • the bpp at which the textures are stored on card (third parameter of the glTexImage2D call). This is the format that the texture has while residing in video card memory. Once again, except changing the third parameter of the call, there’s nothing else to do in your code. Changing the parameter only allows you to spare some memory (by switching from a R8G8B8 to an R5G6B5 format, for example). Obviously, this will also have an impact on graphics quality.
  • the bpp at which you hand the pixels to the glTexImage2D call. That one has implications in your sourcecode. However, it’s not related to the first two, and OpenGL can (and will) do the conversions itself (at no cost) if these are needed. To tell glTexImage2D whan format you used, you have to change the 7th and 8th parameters.

Since OpenGL does the conversion, and since if you aim for wide compatibility you only have RGB/RGBA (24 or 32 bpp) surfaces for the third parameter, here’s what I do :

  • SDL_CreateRGBSurface using a 24/32 bpp R8G8B8(A8) surface (don’t forget to switch the bitmasks if you’re on a big endian architecture).
  • blit my original surface to the 24/32 bpp surface
  • create an OpenGL texture with that new surface using GL_RGB(A), GL_UNSIGNED_BYTE as 7th and 8th parameters.

This has the obvious advantage that this works all the time, on all the OpenGL platforms.

Stephane