SDL_SetVideoMode resets my textures

I’m programming for OpenGL using SDL.

My problem is that whenever I call SDL_SetVideoMode,
all the OpenGL textures that I loaded to that time get reset into black.

These are textures that I load into the gfx-card memory.

Anyone has an idea why this happens or how can I solve it?

Thanks in advance,
Erez Sh.

Check this thread which was easily found using google:
http://twomix.devolution.com/pipermail/sdl/2004-March/060480.html

— “Erez Sh.” wrote:> I’m programming for OpenGL using SDL.

My problem is that whenever I call SDL_SetVideoMode,
all the OpenGL textures that I loaded to that time
get reset into black.

These are textures that I load into the gfx-card
memory.

Anyone has an idea why this happens or how can I
solve it?

Thanks in advance,
Erez Sh.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail

I’m programming for OpenGL using SDL.

My problem is that whenever I call SDL_SetVideoMode,
all the OpenGL textures that I loaded to that time get reset into black.

It happens because you are using Windows and Windows wipes out all your
GL context when you change the video mode. This has nothing to do with
SDL, it is just the way MS decided to implement GL on Windows.

If I were you, I would complain to MS, and then rewrite your code to
reload your textures after you change the video mode.

	Bob PendletonOn Sat, 2004-08-21 at 15:56, Erez Sh. wrote:

These are textures that I load into the gfx-card memory.

Anyone has an idea why this happens or how can I solve it?

Thanks in advance,
Erez Sh.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

±-------------------------------------+

SDL is a portability layer on top of, among other things, OpenGL on Windows,
so it really is SDL’s job to specify that the OpenGL context is lost when
certain SDL calls are made. The peculiarities of the underlying APIs that
SDL can’t hide become peculiarities of SDL’s API, so this has everything
to do with SDL.On Sun, Aug 29, 2004 at 06:37:52PM -0500, Bob Pendleton wrote:

On Sat, 2004-08-21 at 15:56, Erez Sh. wrote:

I’m programming for OpenGL using SDL.

My problem is that whenever I call SDL_SetVideoMode,
all the OpenGL textures that I loaded to that time get reset into black.

It happens because you are using Windows and Windows wipes out all your
GL context when you change the video mode. This has nothing to do with
SDL, it is just the way MS decided to implement GL on Windows.


Glenn Maynard

I’m programming for OpenGL using SDL.

My problem is that whenever I call SDL_SetVideoMode,
all the OpenGL textures that I loaded to that time get reset into
black.

It happens because you are using Windows and Windows wipes out all
your
GL context when you change the video mode. This has nothing to do with
SDL, it is just the way MS decided to implement GL on Windows.

SDL is a portability layer on top of, among other things, OpenGL on
Windows,
so it really is SDL’s job to specify that the OpenGL context is lost
when
certain SDL calls are made. The peculiarities of the underlying APIs
that
SDL can’t hide become peculiarities of SDL’s API, so this has
everything
to do with SDL.

SDL’s role in an OpenGL application doesn’t have much to do with
OpenGL. If you were to make any sort of statement about what technology
SDL is wrapping or replacing in an OpenGL application, you might say
GLUT.On Aug 29, 2004, at 9:23 PM, Glenn Maynard wrote:

On Sun, Aug 29, 2004 at 06:37:52PM -0500, Bob Pendleton wrote:

On Sat, 2004-08-21 at 15:56, Erez Sh. wrote:


Glenn Maynard


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

It would indeed be very handy if SDL could keep track of that, and
post an event if textures are lost. But how to implement it? I don’t
think it’s as simple as a set of platform #defines, because it may
well be driver dependent on most or all platforms. I can see how
Windows can force an OpenGL driver to release all VRAM at any point
(sort of, if the driver is “nice”, that is), but that’s not how it
works on all platforms.

//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,… |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Monday 30 August 2004 03.23, Glenn Maynard wrote:

On Sun, Aug 29, 2004 at 06:37:52PM -0500, Bob Pendleton wrote:

On Sat, 2004-08-21 at 15:56, Erez Sh. wrote:

I’m programming for OpenGL using SDL.

My problem is that whenever I call SDL_SetVideoMode,
all the OpenGL textures that I loaded to that time get reset
into black.

It happens because you are using Windows and Windows wipes out
all your GL context when you change the video mode. This has
nothing to do with SDL, it is just the way MS decided to
implement GL on Windows.

SDL is a portability layer on top of, among other things, OpenGL on
Windows, so it really is SDL’s job to specify that the OpenGL
context is lost when certain SDL calls are made. The peculiarities
of the underlying APIs that SDL can’t hide become peculiarities of
SDL’s API, so this has everything to do with SDL.

In that case it is either a documentation bug which you can fix at
http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fSetVideoMode or it is a bug
in SDL which you are free to fix. I rather like Dave’s suggestion of
sending an event when you lose the GL context. That solution shouldn’t
be to hard to implement and document.

		Bob PendletonOn Sun, 2004-08-29 at 20:23, Glenn Maynard wrote:

On Sun, Aug 29, 2004 at 06:37:52PM -0500, Bob Pendleton wrote:

On Sat, 2004-08-21 at 15:56, Erez Sh. wrote:

I’m programming for OpenGL using SDL.

My problem is that whenever I call SDL_SetVideoMode,
all the OpenGL textures that I loaded to that time get reset into black.

It happens because you are using Windows and Windows wipes out all your
GL context when you change the video mode. This has nothing to do with
SDL, it is just the way MS decided to implement GL on Windows.

SDL is a portability layer on top of, among other things, OpenGL on Windows,
so it really is SDL’s job to specify that the OpenGL context is lost when
certain SDL calls are made. The peculiarities of the underlying APIs that
SDL can’t hide become peculiarities of SDL’s API, so this has everything
to do with SDL.


±-------------------------------------+

Some additional notes regarding this case, if you don’t want to reload
your textures unless it really is necessary.

If you want to switch between fullscreen and windowed mode, you will of
course need to call SDL_SetVideoMode. But you can check with
SDL_VideoDriverName if you’re using the x11 driver, and in such cases skip
the initialization.

If you receive a SDL_VIDEORESIZE event, you have to call SDL_SetVideoMode
according to the docs, I think. But at least at the moment, you don’t
really need that call on Windows (the same goes for OS X), just remember
to update your GL viewport. Using the x11 driver, you have to call
SDL_SetVideoMode, but you don’t need to reload the textures and
reinitialize the GL context again.

Of course, this makes your code ugly, and this kind of OS dependant checks
should be avoided. But if you really want your app to do as little
unneccessary texture reloading as possible, using the current version of
SDL, this is how it works as far as I’ve seen.

An event which tells whether the GL context was lost would of course be
the best solution.

// Martin

Sure. I implemented that at one point, myself. Unfortunately, it got
commented out at some point a long time ago, and I don’t have time presently
to reenable it, de-bit-rot it and make it presentable. It also avoided
resetting the context in Windows when possible; for example, a SetVideoMode
call that simply resizes a window doesn’t need to (but the SDL code path
for this gets hairy).

(The reason I’ve never done this–it’s been disabled for over a year–is
the number of obscure driver issues I see in Windows, forcing a “get it
right, even if it takes longer in silly places” attitude–when things
are working, I’m afraid to touch anything.)On Mon, Aug 30, 2004 at 09:57:03AM -0500, Bob Pendleton wrote:

In that case it is either a documentation bug which you can fix at
http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fSetVideoMode or it is a bug
in SDL which you are free to fix. I rather like Dave’s suggestion of
sending an event when you lose the GL context. That solution shouldn’t
be to hard to implement and document.


Glenn Maynard

I thank everyone who’s answered me.

Damien A - I did several searches, including google. I may not be as qualified
as you in searching stuff. I’m quite curious what is the search ceriteria you
used.

Glenn Maynard - I would very much appreciate if you could post/email me your
solution. Also if I can find the time (and strength :), I will help you
document it so we can contribute it to SDL (in case you’re willing).

As for my opinion on things - I think it should be mentioned in the docs.
SDL does claim to use as a wrapper for OpenGL, and cannot ignore that one of
its functions interrupt the use of OpenGL, no matter what’s the cause…

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Donny Viszneki wrote:
| SDL’s role in an OpenGL application doesn’t have much to do with OpenGL.
| If you were to make any sort of statement about what technology SDL is
| wrapping or replacing in an OpenGL application, you might say GLUT.

Or not, seeing as SDL has absolutely nothing to do with GLUT (directly
or indirectly).
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFBOQq7ms1059AAPcwRAoI4AKCh3o9gvwpfFGPJ8NN9Kuri7w9a1wCcCrpB
HSpaaVHeiB+PSZ/IfBWvS2s=
=bPB/
-----END PGP SIGNATURE-----

Yes, you’re right. SDL instead plays the roll of multiplatform
GLX/AGL/WinGL (and so on) interface (while using those apis directly
internally) and providing a multiplatform input system. (And a
multiplatform audio api, but many people are choosing openal instead
now adays.)On Sat, 04 Sep 2004 01:22:19 +0100, Matt Wilson wrote:

Or not, seeing as SDL has absolutely nothing to do with GLUT (directly
or indirectly).


Patrick “Diablo-D3” McFarland || @Patrick_McFarland
"Computer games don’t affect kids; I mean if Pac-Man affected us as kids, we’d
all be running around in darkened rooms, munching magic pills and listening to
repetitive electronic music." – Kristian Wilson, Nintendo, Inc, 1989