Window resize problem when using OpenGL with SDL

Hi all,

I am trying some things out with OpenGL running in an SDL window, and am having
problems with video resize events whenever I resize the SDL main window.

What happens is that when the window is resized, it seems that the OpenGL
viewport does not get updated, so that (for example) glClear only clears the
original window “area”; if I make the window larger, for example, the new area
stays untouched. If I make the window smaller, my output gets clipped.

This happens even though I am listening for and reacting to SDL_VIDEORESIZE
events, and then calling glViewport() with the new window size.

I have tested this with a minimal program using SDL and another using GLUT
(freeglut). The GLUT program functions correctly. Also, trying it out under
cygwin (of all things) also works correctly, so I am led to believe this is a
new bug(feature?) in SDL?

I have found an ugly workaround: in the window resize handler, instead of
calling glViewport() I call SDL_SetVideoMode(). This works correctly but I am
not sure of what else happens in the background? Is this safe? A proper fix
would be better IMHO.

Some more details:
SDL version: 1.2.13-1ubuntu1
OpenGL version: (mesa) 7.0.3~rc2-1ubuntu3
GLUT version: (freeglut3) 2.4.0-6

Old SDL version under Cygwin: 1.2.11

If you have any light to shed on this, I’d be grateful!

Cheers,
Chris

Hi Chris,

I resize something like this:

float aspect = (float)width / (float)height;
glViewport(0, 0, (GLsizei) width, (GLsizei) height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(your_fovy, aspect, your_zNear, your_zFar);
glMatrixMode(GL_MODELVIEW);

Oliver

Chris wrote:> Hi all,

I am trying some things out with OpenGL running in an SDL window, and am having
problems with video resize events whenever I resize the SDL main window.

What happens is that when the window is resized, it seems that the OpenGL
viewport does not get updated, so that (for example) glClear only clears the
original window “area”; if I make the window larger, for example, the new area
stays untouched. If I make the window smaller, my output gets clipped.

This happens even though I am listening for and reacting to SDL_VIDEORESIZE
events, and then calling glViewport() with the new window size.

I have tested this with a minimal program using SDL and another using GLUT
(freeglut). The GLUT program functions correctly. Also, trying it out under
cygwin (of all things) also works correctly, so I am led to believe this is a
new bug(feature?) in SDL?

I have found an ugly workaround: in the window resize handler, instead of
calling glViewport() I call SDL_SetVideoMode(). This works correctly but I am
not sure of what else happens in the background? Is this safe? A proper fix
would be better IMHO.

Some more details:
SDL version: 1.2.13-1ubuntu1
OpenGL version: (mesa) 7.0.3~rc2-1ubuntu3
GLUT version: (freeglut3) 2.4.0-6

Old SDL version under Cygwin: 1.2.11

If you have any light to shed on this, I’d be grateful!

Cheers,
Chris


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Sorry, I forgot to mention that in my SDL_VIDEORESIZE event handler I
do call SDL_SetVideoMode() and I don’t think that there’s a way around
that as the API docs suggest:

http://www.libsdl.org/cgi/docwiki.cgi/SDL_ResizeEvent (last sentence)
http://www.libsdl.org/cgi/docwiki.cgi/SDL_SetVideoMode (SDL_RESIZABLE)
http://www.libsdl.org/cgi/docwiki.cgi/Resizable_Windows (example)

Also, if your app is supposed to run on crappy windows then you have to
make sure you not only run your resize code (see my snippet below).
Windows “kills” the OpenGL context so you even have to reinitialize it
(glEnable features, create your glCallLists, etc.)!

Oliver

Chris Venter wrote:> Hi Oliver,

On Wed, Nov 26, 2008 at 8:45 PM, Oliver Bock <@Oliver_Bock mailto:Oliver_Bock> wrote:

Hi Chris,

I resize something like this:

float aspect = (float)width / (float)height;
glViewport(0, 0, (GLsizei) width, (GLsizei) height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(your_fovy, aspect, your_zNear, your_zFar);
glMatrixMode(GL_MODELVIEW);

Yes, that is similar to what I’m doing.
Except that if I don’t do an SDL_SetVideoMode() before the glViewport()
call,
the strange behaviour takes place.

I have attached a piece of source code which should demonstrate what I mean.
I would appreciate it if you could compile and run it, and see whether
you get the
same thing.

There are instructions in the source code comments with my observations.

Cheers,
Chris

Oliver


Chris wrote:

    Hi all,

    I am trying some things out with OpenGL running in an SDL
    window, and am having
    problems with video resize events whenever I resize the SDL main
    window.

    What happens is that when the window is resized, it seems that
    the OpenGL
    viewport does not get updated, so that (for example) glClear
    only clears the
    original window "area"; if I make the window larger, for
    example, the new area
    stays untouched. If I make the window smaller, my output gets
    clipped.

    This happens even though I am listening for and reacting to
    SDL_VIDEORESIZE
    events, and then calling glViewport() with the new window size.

    I have tested this with a minimal program using SDL and another
    using GLUT
    (freeglut). The GLUT program functions correctly. Also, trying
    it out under
    cygwin (of all things) also works correctly, so I am led to
    believe this is a
    new bug(feature?) in SDL?

    I have found an ugly workaround: in the window resize handler,
    instead of
    calling glViewport() I call SDL_SetVideoMode(). This works
    correctly but I am
    not sure of what else happens in the background? Is this safe? A
    proper fix
    would be better IMHO.

    Some more details:
    SDL version: 1.2.13-1ubuntu1
    OpenGL version: (mesa) 7.0.3~rc2-1ubuntu3
    GLUT version: (freeglut3) 2.4.0-6

    Old SDL version under Cygwin: 1.2.11

    If you have any light to shed on this, I'd be grateful!

    Cheers,
    Chris


    _______________________________________________
    SDL mailing list
    SDL at lists.libsdl.org <mailto:SDL at lists.libsdl.org>
    http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

You might want to take a look at SDL 1.3, gl contexts no longer get killed.
Of course, there are some problems with 1.3, window management is less than
adequate at the moment, and events for the mouse don’t specify what window
it’s in yet, but hopefully, that will be fixed in the coming months.

If you’re upgrading an app from 1.2 to 1.3, doesn’t the guarantee
which window your mouse events will pertain to? (Put another way:
Isn’t multiple SDL display windows a 1.3 feature?)On Wed, Nov 26, 2008 at 6:13 AM, Jasper van Eck <jasper.vaneck at gmail.com> wrote:

there are some problems with 1.3 …
… events for the mouse don’t specify what window it’s in …


http://codebad.com/

It is, but at the moment, it isn’t quite at the point where it works
entirely.
As I said, mouse input events etc don’t have their windowID field filled, so
it’s rather hard to find out what window it happens in.
In addition to that, the “mouse enter” and “mouse leave” events aren’t
working either.

I was only suggesting that these unfinished features are all absent in
SDL 1.2, so porting an app from 1.2 to 1.3 isn’t a task which will
find trouble with those unfinished features.On Wed, Nov 26, 2008 at 6:20 AM, Jasper van Eck <jasper.vaneck at gmail.com> wrote:

It is, but at the moment, it isn’t quite at the point where it works
entirely.
As I said, mouse input events etc don’t have their windowID field filled, so
it’s rather hard to find out what window it happens in.
In addition to that, the “mouse enter” and “mouse leave” events aren’t
working either.


http://codebad.com/

Ah, communications error, still, if you want opengl video resizing in the
near future instead of now, starting the port to 1.3 might be a wise thing
to do, plus, it’ll help finding bugs.

I’d like to try to upgrade to SDL 1.3, but I’m waiting on some stability issues.
The mouse events issue isn’t a big problem for me at the moment, but there
is one thing that will be a deal-breaker: I need the ability to open multiple
SDL display surfaces inside the same Windows form, using the handles
of the panel controls that define the surface boundaries.

You could do that in SDL 1.2 for a single surface, but it was a bit of a hack
and didn’t work all that reliably, and the way it worked sort of precluded
using it for more than one window, and they said it was going to be
revamped in 1.3. Is this working yet? If not, is it being worked on? Does
anyone know how far along it is?________________________________
From: donny.viszneki@gmail.com (Donny Viszneki)
To: A list for developers using the SDL library. (includes SDL-announce)
Sent: Wednesday, November 26, 2008 3:23:28 AM
Subject: Re: [SDL] Window resize problem when using OpenGL with SDL

On Wed, Nov 26, 2008 at 6:20 AM, Jasper van Eck <jasper.vaneck at gmail.com> wrote:

It is, but at the moment, it isn’t quite at the point where it works
entirely.
As I said, mouse input events etc don’t have their windowID field filled, so
it’s rather hard to find out what window it happens in.
In addition to that, the “mouse enter” and “mouse leave” events aren’t
working either.

I was only suggesting that these unfinished features are all absent in
SDL 1.2, so porting an app from 1.2 to 1.3 isn’t a task which will
find trouble with those unfinished features.


http://codebad.com/


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org