The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Creating a Renderer within my OpenGL 3.0 context (SDL2)
mynameisjohn


Joined: 26 May 2014
Posts: 4
Hey All.

Basically I've been using SDL to create an OpenGL context, and to handle collision I'm using a series of SDL_Rect structs. For debugging purposes I'd like to render them to the screen, but I'm having trouble drawing them using an SDL_Renderer within my OpenGL context.

I've seen this topic (https://forums.libsdl.org/viewtopic.php?t=9440&sid=087dc25c12164d8521dd92ad6cf5d430), but I can't seem to get that to work with OpenGL 3.0 (maybe the shader overrides it?). A relevant code sample would be lovely (I couldn't get the one above to work), and some underlying explanation would be divine.
Re: Creating a Renderer within my OpenGL 3.0 context (SDL2)
AlexRou


Joined: 31 Jan 2014
Posts: 57
Instead of doing it that way, why not render the rects in openGL without the renderer?

If you want it to be drawn as flat 2D on top of 3D you can do like (note the following is in opengl 2):

3D draw loop();

glViewport( 0, 0, WindowWidth, WindowHeight );
/* change to the projection matrix and set our viewing volume. */
glMatrixMode( GL_PROJECTION );
glLoadIdentity();

glOrtho( 0, w, h, 0, -1, 1 );

/* Make sure we're chaning the model view and not the projection */
glMatrixMode( GL_MODELVIEW );

/* Reset The View */
glLoadIdentity();
glPushMatrix();

2D draw loop
{
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();

draw lines

}

SDL_GL_SwapWindow( m_Window );

mynameisjohn wrote:
Hey All.

Basically I've been using SDL to create an OpenGL context, and to handle collision I'm using a series of SDL_Rect structs. For debugging purposes I'd like to render them to the screen, but I'm having trouble drawing them using an SDL_Renderer within my OpenGL context.

I've seen this topic (https://forums.libsdl.org/viewtopic.php?t=9440&sid=087dc25c12164d8521dd92ad6cf5d430), but I can't seem to get that to work with OpenGL 3.0 (maybe the shader overrides it?). A relevant code sample would be lovely (I couldn't get the one above to work), and some underlying explanation would be divine.