I'm using OpenGL and SDL to create window in my program.
How to use SDL_ttf with OpenGL window?
For example i want to load a font and render a text. then i need to draw it in SDL OpenGL surface.
I'm using OpenGL and SDL to create window in my program.
How to use SDL_ttf with OpenGL window?
For example i want to load a font and render a text. then i need to draw it in SDL OpenGL surface.
Here's how to do it:
SDL_SetVideoMode()
. Make sure you pass theSDL_OPENGL
flag.glViewport()
,glMatrixMode()
etc.).Render your text with SDL_ttf using e.g.
TTF_RenderUTF8_Blended()
. The render functions return an SDL_surface, which you have to convert into an OpenGL texture by passing a pointer to the data (surface->pixels
) to OpenGL as well as the format of the data. Like this:Then you can use the texture in OpenGL using
glBindTexture()
etc. Make sure to callSDL_GL_SwapBuffers()
when you're done with drawing.Based off of: http://content.gpwiki.org/index.php/SDL_ttf:Tutorials:Fonts_in_OpenGL
The code below is an example of how you can render the text on top of finished 3D model you may have built.