Sign in to follow this  
trexmaster78

Setting up a GL3 context with SDL

Recommended Posts

I was wondering how do you set up an OpenGL 3.0 rendering context with SDL v1.2.x (I know it'll be taken care of by SDL 1.3.x, but that isn't available yet) ? As far as I know, here's what I'd do : - create the window with SDL_SetVideoMode() - get the window handle with GetActiveWindow() - get the context handle with GetDC() - (re)init the context in GL3 mode with wglCreateContextAttribsARB() - maybe make it the current rendering context with wglMakeContextCurrentARB() Which would give something like that :
SDL_SetVideoMode (width, height, 32, SDL_HWSURFACE|SDL_OPENGL);
HDC context = GetDC(GetActiveWindow());
int attribs []= {
		 WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
		 WGL_CONTEXT_MINOR_VERSION_ARB, 0,
		 WGL_CONTEXT_FLAGS_ARB, 0, 0
                };
HGLRC GL_context = wglCreateContextAttribsARB(context, 0, attribs);
wglMakeContextCurrentARB (context, context, GL_context);

Should this work ?

Share this post


Link to post
Share on other sites
SDL manages the device context for you. You're trying to bypass SDL using WGL, but I think SDL uses WGL itself. (don't quote me on that)
This is how I setup video:

bool setVideoMode()
{
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8 );
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 8);
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
//SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 1);

log_write("+ Vertical-Sync: %d", SDL_GL_SetAttribute( SDL_GL_SWAP_CONTROL, vertical_sync));

if( render::isFullscreen() )
v_flags = SDL_OPENGL | SDL_FULLSCREEN;
else
v_flags = SDL_OPENGL /* | SDL_RESIZABLE*/;

if( SDL_VideoModeOK(render::getWidth(), render::getHeight(), v_bpp, v_flags) != 0 )
{
if(v_screen) SDL_FreeSurface(v_screen);
v_screen = SDL_SetVideoMode(render::getWidth(), render::getHeight(), v_bpp, v_flags);

if(render::isFullscreen()==true && (v_screen->flags==SDL_OPENGL || SDL_FULLSCREEN))
log_write("+ Going fullscreen...");
else
if(render::isFullscreen()==false && v_screen->flags==SDL_OPENGL /* || SDL_RESIZABLE*/)
log_write("+ Going to window mode...");

if(v_screen==NULL)
{
log_write("!!! Video FAILED: (%dx%dx%d): %s" , render::getWidth(), render::getHeight(), v_bpp, SDL_GetError());
return false;
}
else
log_write("+ Video: (%dx%dx%d)", render::getWidth(), render::getHeight(), v_bpp);
}
else
{
log_write("!!! Video mode not available: (%d)x(%d)x(%d)", render::getWidth(), render::getHeight(), v_bpp);
return false;
}
// Information about the current video settings.
v_info = SDL_GetVideoInfo();
return true;
}




If you need the rendering context or window handle try:

SDL_SysWMinfo info;
SDL_VERSION(&info.version); // this must be called before the winfo info is available
SDL_GetWMInfo(&info); //fill the info struct



Hope that helps.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this