SDL + OpenGL and video events

Started by
8 comments, last by Tachikoma 17 years, 11 months ago
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?
Latest project: Sideways Racing on the iPad
Advertisement
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.
[size="2"]I like the Walrus best.
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).
Latest project: Sideways Racing on the iPad
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?
[size="2"]I like the Walrus best.
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 ).
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.
[size="2"]I like the Walrus best.
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.
Yes. You're right. :)
[size="2"]I like the Walrus best.
From my experience, SDL does not keep the context intact during resolution changes on either Mac or Windows.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

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. :)
Latest project: Sideways Racing on the iPad

This topic is closed to new replies.

Advertisement