SDL OpenGL woes

Started by
7 comments, last by Fingers_ 20 years, 8 months ago
Hello, I have an interesting little problem with SDL and OpenGL under WinXP. When I switch from fullscreen to windowed mode, I''m unable to re-initialize OpenGL. Also, after I''ve used the fullscreen mode I can''t start the program in a windowed mode until I reboot. This seems to prevent me from running various SDL/GL example programs as well. The exact error I get from SDL is "unable to make GL context current". This only happens when switching from fullscreen to windowed mode, but not the other way around, which makes me think that my switching method (basically shutdown app, restart with fullscreen bit flipped) is probably not in error. I googled a bit and found a few old messageboard posts of people having a similar problem, but couldn''t find a workaround. It appears that in fullscreen mode SDL doesn''t properly destroy the OpenGL context when it shuts down. Has anybody else had this problem, and is there a known solution?
Advertisement
from the SDL sdk help:

SDL_WM_ToggleFullScreenNameSDL_WM_ToggleFullScreen -- Toggles fullscreen modeSynopsis#include "SDL.h"int SDL_WM_ToggleFullScreen(SDL_Surface *surface);DescriptionToggles the application between windowed and fullscreen mode, if supported. (X11 is the only target currently supported, BeOS support is experimental).Return ValueReturns 0 on failure or 1 on success.


check the description part. Is this what you were looking for?

Because I was gonna implement a toggle-fullscreen thing into my little game made with SDL and OGL, but when I read that description I never bothered trying. Are you using that method or something else?

"No lies of sugar can sweeten the sournes of reality"

}+TITANIUM+{ A.K.A. DXnewbie[onMIRC]
[ ThumbView: Adds thumbnail support for DDS, PCX, TGA and 16 other imagetypes for Windows XP Explorer. ] [ Chocolate peanuts: Brazilian recipe for home made chocolate covered peanuts. Pure coding pleasure. ]
I am afraid it is not that simple, if you use OpenGl, rather than a normal SDL surface.
I have the same problem in my game.
That''s what I do:
Kill SDL, destroy the OpenGL context, then restart SDL, and create another OpenGl context.
On my Win 98 SE this works, but sometimes the system crashes, etc. On other OSes (Linux, XP) people don''t have this problem.


Height Map Editor | Eternal Lands | Fast User Directory
Raduprv: Isn''t SDL supposed to create/destroy the OpenGL context for you when you init/deinitialize the video subsystem? I couldn''t even find a way to destroy the context manually when deinitializing SDL. How are you doing it?

I''m not even hoping to toggle window/fullscreen while running, but it ought to be possible to (a) run the app in fullscreen (b) quit, and (c) run the app in a window. But for some reason it isn''t working.

I can run it either fullscreen or in a window as many times as I want, but if I try to run in a window right after running fullscreen I get the error. But I can still run it fullscreen.. It''s quite bizarre. Telling the user to reboot to switch screen modes in a game would be awkward to say the least
Umm, sorry, I was a little wrong.
This is how I do it:
Destroy ALL the OpenGl textures (VERY IMPORTANT);
SDL_QuitSubSystem(SDL_INIT_VIDEO);
Restart SDL, Restart OpenGL, reload all your textures, states, etc.
If you want to see how it works, try my MMORPG (the Eternal Lands link in my sig).


Height Map Editor | Eternal Lands | Fast User Directory
Hi!

Wow that seems like a hassle don''t it? Glad I didn''t even try! *hehe*

I made it possible to run in a) fullscreen or b) windowed. My method was to always run in windowed mode unless it''s told to run in fullscreen. How did I do that? With a commandline. "main.exe -fullscreen". I parse for commands in the main file and send in the commands to my engine. If I find the -fullscreen command I have a little if( fullscreen ) videoFlags |= SDL_FULLSCREEN;

Works kinda nice. Don''t understand why yours doesn''t work :/

"No lies of sugar can sweeten the sournes of reality"

}+TITANIUM+{ A.K.A. DXnewbie[onMIRC]
[ ThumbView: Adds thumbnail support for DDS, PCX, TGA and 16 other imagetypes for Windows XP Explorer. ] [ Chocolate peanuts: Brazilian recipe for home made chocolate covered peanuts. Pure coding pleasure. ]
all my resources do have an aquire and a release function. as long as you don''t aquire a texture, it does not load its data into opengl.. once you call release, it deletes itself..


now, the whole fullscreen/windowed switch is just

foreachobject { object->release() }
SDL_QuitSubSystem(SDL_INIT_VIDEO)
// set up opengl format
SDL_InitSubSystem(SDL_INIT_VIDEO)
toggleFullScreen(flags)
SDL_SetVideoMode(......,flags)
foreachobject { object->aquire() }

this all nice wrapped in my class..


not much of a hassle actually, if all your objects are derived from that "manageable" class, and support proper aquire/release functions.

note that i got, depending on system and drivers, some hard blue screen crashes when switching too often

"take a look around" - limp bizkit
www.google.com
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia

My Page davepermen.net | My Music on Bandcamp and on Soundcloud

I''m pretty sure I''m destroying all the textures before I shut down the video. I have an "asset manager" that does it automagically on deinit...

I''ll have to try your game to see if the same problem occurs (e.g. if it''s a driver problem).
Seems like it was indeed a driver problem... I got the latest catalyst drivers for my card and now it works fine. Thanks for all the suggestions though

This topic is closed to new replies.

Advertisement