Bug? DoubleBuf+Windows+Windowed

It appears that doublebuff does not work on windows when in windowed mode.
The following code has been tested on Windows and Linux.
On Linux it works as expected, but in Windows it draws to the physical
screen even though no call has been made to update it.
It however works fine when in fullscreen.

Any ideas?

Thanks in advance,

Si.

#include <stdlib.h>
#include “SDL.h”

int main(int argc, char *argv[])
{
SDL_Surface *screen;

/* Initialize SDL */
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr, “Couldn’t initialize SDL: %s\n”,SDL_GetError());
exit(1);
}
atexit(SDL_Quit);

/* Set video mode */
if ( (screen=SDL_SetVideoMode(640, 480, 16, SDL_SWSURFACE|SDL_DOUBLEBUF))
== NULL ) {
fprintf(stderr, “Couldn’t set 640x480x%d video mode: %s\n”, 16,
SDL_GetError());
exit(2);
}

SDL_Rect dstrect;

dstrect.x = 10;
dstrect.y = 10;
dstrect.w = 100;
dstrect.h = 100;
SDL_FillRect(screen, &dstrect, SDL_MapRGB(screen->format, 0xff, 0x0, 0x0));

SDL_Event event;
int done = 0;

/* Quit on input /
while (!done) {
/
Check for events */
while ( SDL_PollEvent(&event) ) {
switch (event.type) {
case SDL_KEYDOWN:
case SDL_QUIT:
done = 1;
break;
default:
break;
}
}
}
return 0;
}

It appears that doublebuff does not work on windows when in windowed mode.
The following code has been tested on Windows and Linux.
On Linux it works as expected, but in Windows it draws to the physical
screen even though no call has been made to update it.

This has been reported before. I’ll look into it if I can.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

Sorry if you know about this already.
I have found out that its only when you call SDL_PollEvent that it triggers
the screen to be updated.
Im not very handy with a debugger, otherwise I would try and track it down.

Si.

At 11:09 10/01/02 -0800, you wrote:>> It appears that doublebuff does not work on windows when in windowed mode.

The following code has been tested on Windows and Linux.
On Linux it works as expected, but in Windows it draws to the physical
screen even though no call has been made to update it.

This has been reported before. I’ll look into it if I can.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment


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

At 17.37 10/01/02 +0000, you wrote:

It appears that doublebuff does not work on windows when in windowed mode.
The following code has been tested on Windows and Linux.
On Linux it works as expected, but in Windows it draws to the physical
screen even though no call has been made to update it.
It however works fine when in fullscreen.
if ( (screen=SDL_SetVideoMode(640, 480, 16, SDL_SWSURFACE|SDL_DOUBLEBUF))

It’s not very useful to use a sw surface with double buffering, it has no
sense at all double buffering in windowed mode. Double buffering is very
useful with HWSURFACEs in that way you can draw to the hidden buffer and
then swap it to the visible one without having to blit the new surface to
the screen. SWSURFACE means that you have to blit with UpdateRect(s) your
changes since your surface is really in the main memory of your computer,
so if you have to blit it to the visible buffer you have not to have also a
double buffer to hide your drawing operations. A double buffer with a SW
surface may be useful in a very fast scrolling game but only if the target
machine supports VBlank synchronization for the flip operation (a way to
delay surface flipping to the next time the physical CRT redraw operation
is arrived to the not visible area of the display), but in these cases it’s
almost the same thing to have double buffering on an HW screen, you’ll gain
a full screen blit each frame, maybe that if you are using alpha keying for
transparences the SWSURFACE may have sense since alpha keying needs to read
the background surface and reading from video memory is usually slow, so I
suggest you the following videomodes:

without alpha:
SDL_HWSURFACE|SDL_DOUBLEBUF: if fullscreen
SDL_SWSURFACE: if windowed

in the mainloop you can place something like:
if(fullscreen) SDL_Flip(); else SDL_UpdateRect(screen,0,0,0,0);

with alpha:
SDL_SWSURFACE: always

You may try SDL_DOUBLEBUF in the fullscreen case if you see video update
visual effects that you don’t like.

Please correct me if I’m wrong :slight_smile:

Bye,
Gabry (gabrielegreco at tin.it)