Window resize with OpenGL, need to redraw twice

Hello,

For some reasons I have to redraw twice the window on osx after a window resize event, otherwise the window shows garbage. This is on osx 10.8.5 with a retina display. A minimal repro case is given below, can anyone confirm ? Is it a retina display only issue ?

Btw, is it possible to get resize events while the window is being resized ?

Best,

Daniel

---- minc.c ----
/*
Compile with:
gcc -o minc minc.c sdl2-config --cflags --libs -framework OpenGL
*/

#include <unistd.h>
#include <assert.h>
#include <stdio.h>
#include <OpenGL/gl3.h>
#include “SDL.h”

void draw (SDL_Window *w)
{
glClearColor (1.0, 0.0, 0.0, 1.0);
glClear (GL_COLOR_BUFFER_BIT);
SDL_GL_SwapWindow (w);
}

void reshape (SDL_Window *w, int width, int height)
{
glViewport (0, 0, width, height);
}

int main(int argc, char** argv)
{
assert (SDL_Init(SDL_INIT_VIDEO) == 0);

SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

SDL_Window *w =
SDL_CreateWindow (“SDL OpenGL ©”,
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
640, 480,
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
assert (w);

SDL_GLContext *c = SDL_GL_CreateContext(w);
assert ©;

draw (w);
while (1)
{
SDL_Event e;
assert (SDL_WaitEvent (&e));
switch (e.type) {
case SDL_KEYUP: if (e.key.keysym.sym == SDLK_ESCAPE) exit(0); break;
case SDL_WINDOWEVENT:
if (e.window.event == SDL_WINDOWEVENT_RESIZED)
{
reshape (w, e.window.data1, e.window.data2);
draw (w);
/* draw (w) */
}
break;
default: break;
}
}

SDL_GL_DeleteContext ©;
SDL_DestroyWindow (w);
SDL_Quit ();
return 0;
}--------------------

Hello,

For some reasons I have to redraw twice the window on osx after a window resize event, otherwise the window shows garbage. This is on osx 10.8.5 with a retina display. A minimal repro case is given below, can anyone confirm ? Is it a retina display only issue ?

No, it occurs just as you say on my Macbook Air mid 2011 model, too. If it makes ya feel any better, the same thing happens on my game. -_-

This isn’t the only garbage artifact related issue to plague SDL2, either:

  1. https://bugzilla.libsdl.org/show_bug.cgi?id=2018#c0
  2. https://github.com/i8degrees/ttcards/issues/9

Not sure what to make of it. It appears outwardly to me as some sort of memory corruption going on, vaguely similar to what happens when the buffer overflows (undefined behavior, AKA garbage). This is pure speculation on my part, though!

I think I will be able to fix my case (see #2, AKA full screen toggle) by filling in the window with solid black during game play, and then during the pause state (where it gets bad), simply use a render texture for the window fill, or so. In other words, I simply must keep rendering something onto the window, leaving no portion of it unfilled.

No idea what a possible solution in your case is. I can confirm that your issue also occurs on my old Windows 7 dev box. (FYI, my full-screen toggle bug does not occur on Windows OS).

Best of luck. Cheers!

Jeffrey Carpenter
<@Jeffrey_Carpenter>

Btw, is it possible to get resize events while the window is being resized ?

Best,

Daniel

---- minc.c ----
/*
Compile with:
gcc -o minc minc.c sdl2-config --cflags --libs -framework OpenGL
*/

#include <unistd.h>
#include <assert.h>
#include <stdio.h>
#include <OpenGL/gl3.h>
#include “SDL.h”

void draw (SDL_Window *w)
{
glClearColor (1.0, 0.0, 0.0, 1.0);
glClear (GL_COLOR_BUFFER_BIT);
SDL_GL_SwapWindow (w);
}

void reshape (SDL_Window *w, int width, int height)
{
glViewport (0, 0, width, height);
}

int main(int argc, char** argv)
{
assert (SDL_Init(SDL_INIT_VIDEO) == 0);

SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

SDL_Window *w =
SDL_CreateWindow (“SDL OpenGL ©”,
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
640, 480,
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
assert (w);

SDL_GLContext *c = SDL_GL_CreateContext(w);
assert ©;

draw (w);
while (1)
{
SDL_Event e;
assert (SDL_WaitEvent (&e));
switch (e.type) {
case SDL_KEYUP: if (e.key.keysym.sym == SDLK_ESCAPE) exit(0); break;
case SDL_WINDOWEVENT:
if (e.window.event == SDL_WINDOWEVENT_RESIZED)
{
reshape (w, e.window.data1, e.window.data2);
draw (w);
/* draw (w) */
}
break;
default: break;
}
}

SDL_GL_DeleteContext ©;
SDL_DestroyWindow (w);
SDL_Quit ();
return 0;
}



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

Jeffrey Carpenter
<@Jeffrey_Carpenter>On 2014/01/ 03, at 5:56, Daniel B?nzli <daniel.buenzli at erratique.ch> wrote:

It is normal for OpenGL to require a couple SDL_GL_SwapWindow calls before it appears, depending on how the driver does buffering (some will buffer 3+ frames).

On a compositing window manager (which most OS’s use by default at this point) you can’t even directly view a single-buffered OpenGL window if you ask for one, requiring at least a glFlush()
(according to Windows Vista documentation) before anything is pushed to the screen.On 01/06/2014 01:40 PM, Jeffrey Carpenter wrote:

On 2014/01/ 03, at 5:56, Daniel B?nzli <daniel.buenzli at erratique.ch> wrote:

Hello,

For some reasons I have to redraw twice the window on osx after a window resize event, otherwise the window shows garbage. This is on osx 10.8.5 with a retina display. A minimal repro case is given below, can anyone confirm ? Is it a retina display only issue ?

No, it occurs just as you say on my Macbook Air mid 2011 model, too. If it makes ya feel any better, the same thing happens on my game. -_-

This isn’t the only garbage artifact related issue to plague SDL2, either:

  1. https://bugzilla.libsdl.org/show_bug.cgi?id=2018#c0
  2. https://github.com/i8degrees/ttcards/issues/9

Not sure what to make of it. It appears outwardly to me as some sort of memory corruption going on, vaguely similar to what happens when the buffer overflows (undefined behavior, AKA garbage). This is pure speculation on my part, though!

I think I will be able to fix my case (see #2, AKA full screen toggle) by filling in the window with solid black during game play, and then during the pause state (where it gets bad), simply use a render texture for the window fill, or so. In other words, I simply must keep rendering something onto the window, leaving no portion of it unfilled.

No idea what a possible solution in your case is. I can confirm that your issue also occurs on my old Windows 7 dev box. (FYI, my full-screen toggle bug does not occur on Windows OS).

Best of luck. Cheers!

Jeffrey Carpenter

Btw, is it possible to get resize events while the window is being resized ?

Best,

Daniel

---- minc.c ----
/*
Compile with:
gcc -o minc minc.c sdl2-config --cflags --libs -framework OpenGL
*/

#include <unistd.h>
#include <assert.h>
#include <stdio.h>
#include <OpenGL/gl3.h>
#include “SDL.h”

void draw (SDL_Window *w)
{
glClearColor (1.0, 0.0, 0.0, 1.0);
glClear (GL_COLOR_BUFFER_BIT);
SDL_GL_SwapWindow (w);
}

void reshape (SDL_Window *w, int width, int height)
{
glViewport (0, 0, width, height);
}

int main(int argc, char** argv)
{
assert (SDL_Init(SDL_INIT_VIDEO) == 0);

SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

SDL_Window *w =
SDL_CreateWindow (“SDL OpenGL ©”,
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
640, 480,
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
assert (w);

SDL_GLContext *c = SDL_GL_CreateContext(w);
assert ©;

draw (w);
while (1)
{
SDL_Event e;
assert (SDL_WaitEvent (&e));
switch (e.type) {
case SDL_KEYUP: if (e.key.keysym.sym == SDLK_ESCAPE) exit(0); break;
case SDL_WINDOWEVENT:
if (e.window.event == SDL_WINDOWEVENT_RESIZED)
{
reshape (w, e.window.data1, e.window.data2);
draw (w);
/* draw (w) */
}
break;
default: break;
}
}

SDL_GL_DeleteContext ©;
SDL_DestroyWindow (w);
SDL_Quit ();
return 0;
}



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

Jeffrey Carpenter


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


LordHavoc
Author of DarkPlaces Quake1 engine - http://icculus.org/twilight/darkplaces
Co-designer of Nexuiz - http://alientrap.org/nexuiz
"War does not prove who is right, it proves who is left." - Unknown
"Any sufficiently advanced technology is indistinguishable from a rigged demo." - James Klass
"A game is a series of interesting choices." - Sid Meier

It is normal for OpenGL to require a couple SDL_GL_SwapWindow calls before it appears, depending on how the driver does buffering (some will buffer 3+ frames).

On a compositing window manager (which most OS’s use by default at this point) you can’t even directly view a single-buffered OpenGL window if you ask for one, requiring at least a glFlush()
(according to Windows Vista documentation) before anything is pushed to the screen.

Makes good sense. Thanks for the info!

I am not all that familiar with OpenGL (yet!), but have been quickly picking up pace since SDL2 went stable :slight_smile:

Cheers

Hello,

For some reasons I have to redraw twice the window on osx after a window resize event, otherwise the window shows garbage. This is on osx 10.8.5 with a retina display. A minimal repro case is given below, can anyone confirm ? Is it a retina display only issue ?

No, it occurs just as you say on my Macbook Air mid 2011 model, too. If it makes ya feel any better, the same thing happens on my game. -_-

This isn’t the only garbage artifact related issue to plague SDL2, either:

  1. https://bugzilla.libsdl.org/show_bug.cgi?id=2018#c0
  2. https://github.com/i8degrees/ttcards/issues/9

Not sure what to make of it. It appears outwardly to me as some sort of memory corruption going on, vaguely similar to what happens when the buffer overflows (undefined behavior, AKA garbage). This is pure speculation on my part, though!

I think I will be able to fix my case (see #2, AKA full screen toggle) by filling in the window with solid black during game play, and then during the pause state (where it gets bad), simply use a render texture for the window fill, or so. In other words, I simply must keep rendering something onto the window, leaving no portion of it unfilled.

No idea what a possible solution in your case is. I can confirm that your issue also occurs on my old Windows 7 dev box. (FYI, my full-screen toggle bug does not occur on Windows OS).

Best of luck. Cheers!

Jeffrey Carpenter
<@Jeffrey_Carpenter>

Btw, is it possible to get resize events while the window is being resized ?

Best,

Daniel

---- minc.c ----
/*
Compile with:
gcc -o minc minc.c sdl2-config --cflags --libs -framework OpenGL
*/

#include <unistd.h>
#include <assert.h>
#include <stdio.h>
#include <OpenGL/gl3.h>
#include “SDL.h”

void draw (SDL_Window *w)
{
glClearColor (1.0, 0.0, 0.0, 1.0);
glClear (GL_COLOR_BUFFER_BIT);
SDL_GL_SwapWindow (w);
}

void reshape (SDL_Window *w, int width, int height)
{
glViewport (0, 0, width, height);
}

int main(int argc, char** argv)
{
assert (SDL_Init(SDL_INIT_VIDEO) == 0);

SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

SDL_Window *w =
SDL_CreateWindow (“SDL OpenGL ©”,
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
640, 480,
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
assert (w);

SDL_GLContext *c = SDL_GL_CreateContext(w);
assert ©;

draw (w);
while (1)
{
SDL_Event e;
assert (SDL_WaitEvent (&e));
switch (e.type) {
case SDL_KEYUP: if (e.key.keysym.sym == SDLK_ESCAPE) exit(0); break;
case SDL_WINDOWEVENT:
if (e.window.event == SDL_WINDOWEVENT_RESIZED)
{
reshape (w, e.window.data1, e.window.data2);
draw (w);
/* draw (w) */
}
break;
default: break;
}
}

SDL_GL_DeleteContext ©;
SDL_DestroyWindow (w);
SDL_Quit ();
return 0;
}



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

Jeffrey Carpenter
<@Jeffrey_Carpenter>


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


LordHavoc
Author of DarkPlaces Quake1 engine - http://icculus.org/twilight/darkplaces
Co-designer of Nexuiz - http://alientrap.org/nexuiz
"War does not prove who is right, it proves who is left." - Unknown
"Any sufficiently advanced technology is indistinguishable from a rigged demo." - James Klass
"A game is a series of interesting choices." - Sid Meier


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

Jeffrey Carpenter
<@Jeffrey_Carpenter>On 2014/01/ 06, at 15:46, Forest Hale wrote:

On 01/06/2014 01:40 PM, Jeffrey Carpenter wrote:

On 2014/01/ 03, at 5:56, Daniel B?nzli <daniel.buenzli at erratique.ch> wrote:

Le lundi, 6 janvier 2014 ? 22:46, Forest Hale a ?crit :

It is normal for OpenGL to require a couple SDL_GL_SwapWindow calls before it appears, depending on how the driver does buffering (some will buffer 3+ frames).

That doesn’t make sense to me (at least on osx), I think we have a bug here. I tried to have a look at the implementation of SDL_GL_SwapWindow [1] but there’s nothing obviously wrong that jumps to my eyes.

Daniel

[1] https://hg.libsdl.org/SDL/file/b744b3f8754b/src/video/cocoa/SDL_cocoaopengl.m#l375

It sounds like memory is being reallocated (which it would do because the size has changed) and because you haven’t updated that buffer with anything it just displays whatever was there last. Just a guess.

Is it also possible that the screen is updated before your program has a chance to draw anything onto that buffer?

It’s a completely different issue raised in this post (by myself), but I saw similar garbage by just not clearing the buffer, drawing a few pixels and displaying it. http://stackoverflow.com/questions/19935727/sdl2-how-to-render-with-one-buffer-instead-of-two

Maybe it’s worth investigating in what order things are triggered?

I nailed something down, see here for an explanation:

https://bugzilla.libsdl.org/show_bug.cgi?id=2339#c1

Daniel

I’d rather not get Rick Rolled or worse, catch the next generation virus.
Would someone please post what this guy is talking about so I don’t need to
take the risk?On Feb 25, 2014 2:10 PM, “Daniel B?nzli” <daniel.buenzli at erratique.ch> wrote:

I nailed something down, see here for an explanation:

https://bugzilla.libsdl.org/show_bug.cgi?id=2339#c1

Daniel


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

I don?t think the official SDL issue tracker is going to rickroll you.On Feb 25, 2014, at 4:53 PM, R Manard wrote:

I’d rather not get Rick Rolled or worse, catch the next generation virus. Would someone please post what this guy is talking about so I don’t need to take the risk?

On Feb 25, 2014 2:10 PM, “Daniel B?nzli” <daniel.buenzli at erratique.ch> wrote:
I nailed something down, see here for an explanation:

https://bugzilla.libsdl.org/show_bug.cgi?id=2339#c1

Daniel


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


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

I clicked the link that said it was a Microsoft website and it wrecked my
hard drive. Had to buy a new hard drive lost everything. That’s why I’m
mailing list or form is a good thing, but clicking links that you see in an
email list or form is pretty riskyOn Feb 25, 2014 2:55 PM, “Alex Szpakowski” wrote:

I don’t think the official SDL issue tracker is going to rickroll you.

On Feb 25, 2014, at 4:53 PM, R Manard <@R_Manard> wrote:

I’d rather not get Rick Rolled or worse, catch the next generation virus.
Would someone please post what this guy is talking about so I don’t need to
take the risk?
On Feb 25, 2014 2:10 PM, “Daniel B?nzli” <daniel.buenzli at erratique.ch> wrote:

I nailed something down, see here for an explanation:

https://bugzilla.libsdl.org/show_bug.cgi?id=2339#c1

Daniel


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


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


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