Sign in to follow this  

SDL + OpenGL and video events

This topic is 4239 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am using SDL to create an OpenGL rendering context (Win32 platform), which works fine for the most part. I'm using the event handler to tap into SDL_VIDEOEXPOSE and SDL_VIDEORESIZE events. I have a couble of questions regarding this: Is it normal for a SDL_VIDEOEXPOSE event to occur soon after the windowed display is created? (This also occurs for new full-screen displays.) What is the best (or correct) way of handling SDL_VIDEOEXPOSE events in OpenGL applications? Does that imply that I have to recreate the OpenGL context? [edit: I know this is kinda a stupid question, but I'm not 100% sure what happens behind SDL when this event occurs (i.e.. does it affect the rendering context in any way? Do I have to reinitialise it? etc...)] When a SDL_VIDEORESIZE event occurs, the SDL documentation recommends to call SDL_SetVideoMode( ) for handling a window resize event. Unfortunately this seems to break everything in OpenGL, including textures, display lists, etc.. Is there a way to handle such events without going through the pain of reloading textures and rebuilding display lists?

Share this post


Link to post
Share on other sites
Quote:
Original post by Tachikoma
When a SDL_VIDEORESIZE event occurs, the SDL documentation recommends to call SDL_SetVideoMode( ) for handling a window resize event. Unfortunately this seems to break everything in OpenGL, including textures, display lists, etc.. Is there a way to handle such events without going through the pain of reloading textures and rebuilding display lists?


You're probably re-creating the window when your video mode is changed. You don't need to do that. Just change the video mode and leave the window right there.

Share this post


Link to post
Share on other sites
I can only to do it one way (or so it seems) via calling SDL_SetVideoMode( ). The funtion creates both the window and the rendering context, so I can't really seperate the windowing and the GL surface side of thigs (without getting into OS specific stuff).

Share this post


Link to post
Share on other sites
If I remember correctly SDL re-uses the same window when you call SDL_SetVideoMode() several times, so the OpenGL context should remain between calls. Are you de-initializing SDL when switching modes?

Share this post


Link to post
Share on other sites
Actually, AFAIK, for some unfathomable reason SDL destroys your current openGL context on subsequent calls to SDL_SetVideoMode, so you lose all context data.

I believe you will need to have somewhere where you can reload any textures and display lists, etc. You will need to do all the setup again ( which isn't too hard if you have a single place for it all to happen, a single function or whatever ).

Share this post


Link to post
Share on other sites
Quote:
Original post by rip-off
Actually, AFAIK, for some unfathomable reason SDL destroys your current openGL context on subsequent calls to SDL_SetVideoMode, so you lose all context data.

I believe you will need to have somewhere where you can reload any textures and display lists, etc. You will need to do all the setup again ( which isn't too hard if you have a single place for it all to happen, a single function or whatever ).


I think it doesn't.

Take a look at the Linux/SDL source code of this tutorial at Nehe.

EDIT: Apparently SDL_SetVideoMode behaves differently on Linux than in Windows.
Follow this thread to read more.

Share this post


Link to post
Share on other sites
Quote:
Original post by owl
Quote:
Original post by rip-off
Actually, AFAIK, for some unfathomable reason SDL destroys your current openGL context on subsequent calls to SDL_SetVideoMode, so you lose all context data.

I believe you will need to have somewhere where you can reload any textures and display lists, etc. You will need to do all the setup again ( which isn't too hard if you have a single place for it all to happen, a single function or whatever ).


I think it doesn't.

Take a look at the Linux/SDL source code of this tutorial at Nehe.


See the quote at the bottom of this message (Sam Lantiga, if you do not know, is SDL's original author )

Source
Quote:

> You should free your GL resources before calling SDL_SetVideoMode() and
> reallocate them afterwards. It's not strictly necessary on Linux, but
> doing so keeps things portable. (TODO: keep OpenGL context on Windows)
>
> See ya,
> -Sam Lantinga, Software Engineer, Blizzard Entertainment


I haven't heard that keeping the gl context is guarenteeed to work, so for the moment assume it won't.

Share this post


Link to post
Share on other sites
Thanks for the feedback fellas. After some digging around I concluded that SDL kills the OpenGL context no matter what. SDL_SetVideoMode( ) will completely re-init the display mode and OpenGL context on Win32 platforms. On Linux it's a different story (apparently).

It's one of the few annoyances with SDL - it's a great API, but it seems to be so "incomplete" in a few selected areas. Hopefully they'll fix things in the versions coming up. :)

Share this post


Link to post
Share on other sites

This topic is 4239 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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