sdl w/opengl


I am using SDL_TTF, and when I render the SDL_Surface returned by TTF_RenderText_Solid(), I only get a solid quad.

any idea what i’m doing wrong? I only get a solid colored quad.

this link: says that TTF_RenderText_Solid():

Create an 8-bit palettized surface and render the given text at fast quality with the given font and color. The 0 pixel value is the colorkey, giving a transparent background, and the 1 pixel value is set to the text color. The colormap is set to have the desired foreground color at index 1, this allows you to change the color without having to render the text again. Colormap index 0 is of course not drawn, since it is the colorkey, and thus transparent, though it’s actual color is 255 minus each RGB component of the foreground.
Does it have something to do with the way i should use glTexImage2D()? it says the surface is 8-bit, how do i create through glTexImage2D()? How do you set up glTexImage2D() to accept an 8bit surface whose 0 pixel value is the colorkey?


TTF_RenderText_Blended seems more appropriate for OpenGL textures.

  1. 8-bit palettized textures are rarely available, so you have to convert to RGBA (if 0 then 1,1,1,0 else if 1 then 1,1,1,1) and then use alpha testing. And you will have jaggies around your letters.

  2. RGBA high quality text is great and smooth ! Blending textures is easy in opengl.

I don’t know well SDL_Surface, but you should be able to extract an array of values to convert to a texture. Don’t forget that opengl textures must be power of two.

yeah, but TTF_RenderText_Blended() returns an ARGB surface…how do i tell glTexImage2D() that i’m giving it an ARGB surface? i only know of GL_RGB, GL_BGR, GL_RGBA, GL_COLOR_INDEX…


  1. glTexImage2D() can not take a SDL_Surface directly, it takes only an array.

  2. there is an extension named GL_EXT_abgr which add the format GL_ABGR_EXT :
    It seems pretty well supported by cards :

The color will not be correct, but the alpha will. You can correct the color by passing a component-reversed SDL_Color (swap B and R).

Either way, if the texture is not updated in real time, you can swap around the bytes yourself too.