Saturday, December 28, 2013

New OpenGL API: Mix pure OpenGL calls with the SDL2 Render API!

Hello fellow programmers!


I'm writing this post to announce the new API that was added in the library only yesterday, namely SDLU_GL_RenderCacheState() and SDLU_GL_RenderRestoreState().

These two functions allow you to mix pure OpenGL, OpenGL ES or OpenGL ES 2 calls with the SDL2 Render API. They dynamically load the required OpenGL symbols that are used, and so all OpenGL libraries (desktop GL, GLES, GLES2) are supported.

Example:

SDL_RenderClear(sdl_renderer);
SDL_RenderDrawPoint(sdl_renderer, 100, 100);

SDLU_GL_RenderCacheState(sdl_renderer);
glColor3f(1,0,0);
glRecti(150, 150, 200, 200);
SDLU_GL_RenderRestoreState(sdl_renderer);

SDL_RenderPresent(sdl_renderer); 
 
For a complete example, you might want to check out testrender2 (link).

-- Aggelos Kolaitis

No comments: