SDL, resizing, fullscreen, and lost rendering contexts

Started by
4 comments, last by LGAB 14 years, 11 months ago
I was working with an SDL/OpenGL app and ran into the same issue with resizing described here: http://www.gamedev.net/community/forums/topic.asp?topic_id=406165 I found that I could avoid calling SDL_SetVideoMode() after a resize -- I could simply call the logic to adjust the Open GL perspective of the scene (aspect ratio, etc) and continue rendering. I did notice that they were saying there might be some issues in doing this down the line - that SDL_GetMouseState() may not work properly. What exactly does this mean? Are they saying this function will not return values exceeding the previous width and height of the window, before it was resized? ================================================================================ I then ran into a similar problem when I added an option to switch between windowed mode / full screen. It seems that SDL_SetVideoMode() is the only way to swap to full screen. This of course will cause you to lose the current Open GL rendering context. I found dicussion of a SDL_WM_ToggleFullscreen() function, but it sounds like it only works on Linux. Losing the rendering context? This means rerunning all Open GL initialization code (setting up lights, loading textures, everything.) If I am correct, you also need to tell it to do cleanup functions before doing these reinitalizations (ie calling the glDeleteTextures function); otherwise you'll have resource leaks. Is this correct? Thanks in advance.
Advertisement
Yes, this is a known issue. Luckily, I found a custom build of SDL that doesn't destroy the context.

You can get it here:
http://akb825.com/downloads/SDL-1.2.11.zip

The forum post here:
http://www.idevgames.com/forum/archive/index.php/t-12824.html
Thanks - that's some useful information.
I guess my main concern with using that build of SDL is how thoroughly it's been tested - it sounds like a number of people have used it by now, but I suspect the official build of SDL has gone through more testing by now.

If I decide to go the route with using standard SDL version 1.2 (meaning redoing Open GL initialization each time I call SDL_SetVideoMode() and losing my rendering context) - Do I also need to manually cleanup the old stuff that was lost with the old rendering context - ie. do I need to call glDeleteTextures on the old texture data before reloading it?
It's been my experience that you do not. (I'm fairly certain I do anyway). In testing, when I didn't do it, the driver properly released the video memory used by the textures when the context was destroyed. But I could just have a friendly driver.

Just remember to clean it up before resizing. It does you no good to clean up a brand new context.
Thanks for the suggestions.

How can I tell if the driver released the video memory for me?

You said that, if I clean it up, I should do it before resizing. By resizing you mean calling SDL_SetVideoMode, correct?
Quote:Original post by scarypajamasYes, this is a known issue. Luckily, I found a custom build of SDL that doesn't destroy the context.


Wow, that just saved me many hours of pain, I was just about to ditch SDL because of the context problem! I do like SDL for everything else it's offering so I'd rather not.

Can anyone confirm that this version builds for Linux as well?

This topic is closed to new replies.

Advertisement