[SDL] SDL/OpenGL and texture mapping
paul at theV.net
paul at theV.net
Wed Sep 11 02:59:00 PDT 2002
On Wed, Sep 11, 2002 at 02:19:15AM -0700, Eric Wing wrote:
> First, the image coordinate systems seemed to be
> inverted. In OpenGL, if you imagine your 0,0
Not really as complicated as you have described. As
David Olofson wrote in his glSDL.c, something like
glOrtho(0, width, height, 0, -1.0, 1.0);
will do the coordinates conversion for you. This works
seamlessly with all coordinates (including texture
coordinates) to let you write 2D applications using
normal topleft original.
> For 8-bit images, your life gets harder because the
> image uses palette. I think you will have to manually
> decode each pixel to get the RGB values, and then
> place them in a new 24 (or 32) bit surface which you
> will pass to OpenGL.
A simple SDL_BlitSurface() to a 32-bit RGB surface
will do the above said conversion. The nice thing
about SDL is that programmers do not have to deal
with surface format in much detail, but you still
need to understand what is really going on under
> One more note, SDL_Surfaces will not help you with
> "colorkey" transparency (i.e. your image format
> specifies that a certain color represents
> transparency). If you want to use colorkey
> transparency, you will also have to write this. You
> will need to go through every pixel (assuming the SDL
> color key flag has been set), and check to see if the
> color matches the colorkey. Then you will need to set
> the alpha value to 0 yourself in your OpenGL surface.
David Olofson also wrote this part in his glSDL
implementation. I really learned a lot by reading
his codes, kudos to David!
> formats). If you don't want to go to all this trouble,
> then just use 32-bit format images with actual
> transparency values already set.
Yeah that is actually recommended if you are coding
something specifically targetting at OpenGL. And I say
why not, I use all textures in RGBA format uniformly
throughout my application even when the surface doesn't
need alpha channel. It does not slow down the graphics
hardware in any significant manner.
More information about the SDL