[Win32] Problem with blits in Fullscreen mode?

To check that i had SDL properly installed and
everything, i made the little silly program below(it
display a background picture and draws a smaller
picture where the mouse is clicked, if a key is
pressed it takes a screenshot and restores the
background). It works fine windowed, but when i added
the SDL_FULLSCREEN flag i ran into trouble, weird
things happened when i click the mouse. I tested it on
2 other machines(one Win2000/ATI rage the other
WinXP/Geforce2) and the exact same thing happened.
More exactly, when i click the mouse, ONLY my little
boom.bmp image is shown, the next time i click, the
background comes back, but there are little black
boxes missing from it, and when i keep clicking the
boom.bmp sprites move around in a very strange way…
Can anyone help me fix this, i would like to know if
its because im using it wrong(likely) or because of
something else beyond my control. I tried using a
software surface and removing the double buffer flag,
that helps a little, but the there is still a
transparent whole in the “boom.bmp” that was last
drawn, until i draw another one by clicking the mouse.

Here is the very simple code:

#include "SDL.h"
int main( int argc, char* argv[] )
{
SDL_Init ( SDL_INIT_VIDEO ) ;

atexit ( SDL_Quit ) ;

SDL_Surface* pSurface = SDL_SetVideoMode ( 800 , 600

, 0, SDL_HWSURFACE | SDL_FULLSCREEN | SDL_DOUBLEBUF )
;
SDL_Surface* imageTile = SDL_LoadBMP(“boom.bmp”);
SDL_Surface* background =
SDL_LoadBMP(“background.bmp”);
SDL_WM_SetCaption(“Stupid SDL test program”, NULL);
SDL_SetColorKey(imageTile, SDL_SRCCOLORKEY,
SDL_MapRGB(imageTile->format, 255, 0, 128));

 SDL_Event event;
 SDL_BlitSurface(background, NULL, pSurface, NULL);
 SDL_Flip(pSurface);
 for ( ; ; )	
 {
	if ( SDL_PollEvent ( &event ) )	
	{
	  if ( event.type == SDL_QUIT ) break ;
	  if ( event.type == SDL_KEYDOWN ) {
		SDL_SaveBMP(pSurface, "screenshot.bmp");
		SDL_BlitSurface(background, NULL, pSurface, NULL); 
		SDL_Flip(pSurface);
		}
	if ( event.type == SDL_MOUSEBUTTONDOWN) {
		SDL_Rect target;
		target.x = event.button.x - 10;
		target.y = event.button.y - 10;
		SDL_BlitSurface(imageTile, NULL, pSurface,

&target);
SDL_Flip(pSurface);
}
}
}

  return ( 0 ) ;

}__________________________________________________
Do You Yahoo!?
Everything you’ll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

— Peter T skrev: > To
check that i had SDL properly installed and

everything, i made the little silly program below(it
display a background picture and draws a smaller
picture where the mouse is clicked, if a key is
pressed it takes a screenshot and restores the
background). It works fine windowed, but when i
added
the SDL_FULLSCREEN flag i ran into trouble

try to change the flag SDL_HWSURFACE to SDL_SWSURFACE
and it will probably work.

I’m not sure why it doesn’t work with SDL_HWSURFACE
though._____________________________________________________
Do You Yahoo!?
se.yahoo.com

Hi.

When running in fullscreen mode, the surface is double buffered.

You need to ensure that your images are on both the back and front buffers.

To do this, call each of your blit / flips twice.

Steve> ----- Original Message -----

From: Peter T [mailto:petertiedk@yahoo.co.uk]
Sent: 12 December 2001 10:33
To: sdl at libsdl.org
Subject: [SDL] [Win32] Problem with blits in Fullscreen mode?

To check that i had SDL properly installed and
everything, i made the little silly program below(it
display a background picture and draws a smaller
picture where the mouse is clicked, if a key is
pressed it takes a screenshot and restores the
background). It works fine windowed, but when i added
the SDL_FULLSCREEN flag i ran into trouble, weird
things happened when i click the mouse. I tested it on
2 other machines(one Win2000/ATI rage the other
WinXP/Geforce2) and the exact same thing happened.
More exactly, when i click the mouse, ONLY my little
boom.bmp image is shown, the next time i click, the
background comes back, but there are little black
boxes missing from it, and when i keep clicking the
boom.bmp sprites move around in a very strange way…
Can anyone help me fix this, i would like to know if
its because im using it wrong(likely) or because of
something else beyond my control. I tried using a
software surface and removing the double buffer flag,
that helps a little, but the there is still a
transparent whole in the “boom.bmp” that was last
drawn, until i draw another one by clicking the mouse.

Here is the very simple code:

#include "SDL.h"
int main( int argc, char* argv[] )
{
SDL_Init ( SDL_INIT_VIDEO ) ;

atexit ( SDL_Quit ) ;

SDL_Surface* pSurface = SDL_SetVideoMode ( 800 , 600
, 0, SDL_HWSURFACE | SDL_FULLSCREEN | SDL_DOUBLEBUF )
;
SDL_Surface* imageTile = SDL_LoadBMP(“boom.bmp”);
SDL_Surface* background =
SDL_LoadBMP(“background.bmp”);
SDL_WM_SetCaption(“Stupid SDL test program”, NULL);
SDL_SetColorKey(imageTile, SDL_SRCCOLORKEY,
SDL_MapRGB(imageTile->format, 255, 0, 128));

SDL_Event event;
SDL_BlitSurface(background, NULL, pSurface, NULL);
SDL_Flip(pSurface);
for ( ; ; )
{
if ( SDL_PollEvent ( &event ) )
{
if ( event.type == SDL_QUIT ) break ;
if ( event.type == SDL_KEYDOWN ) {
SDL_SaveBMP(pSurface, “screenshot.bmp”);
SDL_BlitSurface(background, NULL, pSurface, NULL);
SDL_Flip(pSurface);
}
if ( event.type == SDL_MOUSEBUTTONDOWN) {
SDL_Rect target;
target.x = event.button.x - 10;
target.y = event.button.y - 10;
SDL_BlitSurface(imageTile, NULL, pSurface,
&target);
SDL_Flip(pSurface);
}
}
}

return ( 0 ) ;

}


Do You Yahoo!?
Everything you’ll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com


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


This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com


try to change the flag SDL_HWSURFACE to
SDL_SWSURFACE
and it will probably work.

I’m not sure why it doesn’t work with SDL_HWSURFACE
though.

I also tried with SDL_SWSURFACE, it helps a little but
the small pictures drawn by the mouse still have
problems. The last one i draw becomes transparent in
the middle(seems like its the mouses bounding
rectangle), until i draw another one. If i just click
and dont move the mouse its okay, but the instant i
move the mouse, the picture becomes transparent in the middle.__________________________________________________
Do You Yahoo!?
Everything you’ll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

— Steve Lupton wrote: > Hi.

When running in fullscreen mode, the surface is
double buffered.

You need to ensure that your images are on both the
back and front buffers.

To do this, call each of your blit / flips twice.

Steve

Thanks, that helped a little, but now the screen
flickers(looks like it goes black for a very small
instant) when i click the mouse. Besides, i just
noticed something, i cant actually see the mouse
cursor, in both SW and HW(but if i remove the
doublebuffer flag i can see the mouse, but then the
mouse leaves transparent rectangles in the last
picture drawn until i draw another one!?):frowning:
Anyway, im not quite sure WHY it helps calling
blit/flip twice, i mean i use the double buffer flag
when windowed too, but that doesnt give me any
problems. Why do i need to blit twice to the
backbuffer(pSurface)? What exactly happens to the
backbuffer when i flip?(sorry if this is a really
stupid question :)__________________________________________________
Do You Yahoo!?
Everything you’ll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

Hi

When you flip, the new backbuffer is in a completely unknown state.

It may have what was previously on the front buffer but this is by no
means guaranteed.

As you cannot trust the contents of the backbuffer after flipping, you must
always rewrite the entire back buffer before flipping again.

There is a pretty good reason why you see different results in
fullscreen/windowed modes.

In fullscreen mode when you call the flip, all that actually happens is the
videocard is given a pointer to a different area in memory - no data is
actually copied. In this case, after the first flip, the backbuffer is empty
(or possibly full of rubbish) again. If you flipped again, you would see
your original screen as this is also still in the same location.

In windowed mode when you call the flip, the contents of the backbuffer is
blitted onto your screen. In this case, the backbuffer is probably always in
the same memory location and will therefore contain the already blitted
contents still within it.

Steve> ----- Original Message -----

From: Peter T [mailto:petertiedk@yahoo.co.uk]
Sent: 12 December 2001 12:21
To: sdl at libsdl.org
Subject: RE: [SDL] [Win32] Problem with blits in Fullscreen mode?

— Steve Lupton wrote: > Hi.

When running in fullscreen mode, the surface is
double buffered.

You need to ensure that your images are on both the
back and front buffers.

To do this, call each of your blit / flips twice.

Steve

Thanks, that helped a little, but now the screen
flickers(looks like it goes black for a very small
instant) when i click the mouse. Besides, i just
noticed something, i cant actually see the mouse
cursor, in both SW and HW(but if i remove the
doublebuffer flag i can see the mouse, but then the
mouse leaves transparent rectangles in the last
picture drawn until i draw another one!?):frowning:
Anyway, im not quite sure WHY it helps calling
blit/flip twice, i mean i use the double buffer flag
when windowed too, but that doesnt give me any
problems. Why do i need to blit twice to the
backbuffer(pSurface)? What exactly happens to the
backbuffer when i flip?(sorry if this is a really
stupid question :slight_smile:


Do You Yahoo!?
Everything you’ll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com


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


This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com


Is this behaviour consistent between Win32 and X platforms?On Wed, Dec 12, 2001 at 02:20:04PM -0000, Steve Lupton wrote:

In fullscreen mode when you call the flip, all that actually happens is the
videocard is given a pointer to a different area in memory - no data is
actually copied. In this case, after the first flip, the backbuffer is empty
(or possibly full of rubbish) again. If you flipped again, you would see
your original screen as this is also still in the same location.

In windowed mode when you call the flip, the contents of the backbuffer is
blitted onto your screen. In this case, the backbuffer is probably always in
the same memory location and will therefore contain the already blitted
contents still within it.


Thomas “Mondoshawan” Tate
phoenix at psy.ed.asu.edu
http://tank.dyndns.org
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20011212/818e3d53/attachment.pgp

When you flip, the new backbuffer is in a completely
unknown state.

Thanks, i see the problem with the old code now.

Im still having some problems though:

  1. If i use HW or SW surface in fullscreen with
    doublebuffering set, i cant see the mouse cursor!

  2. If i dont use the doublebuffer flag, i can see the
    mouse but it leaves a transparent hole in my blitted
    picture(when i move the cursor) so i can see the
    background picture.(this is mysterious to me, i could
    perhaps understand that the mouse could cause an
    artifact, but it seems strange that it doesnt just
    cause blackness or some garbage.)

Again, thank you for taking the time to explain.__________________________________________________
Do You Yahoo!?
Everything you’ll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

I’m not 100% sure.

As I understand it, the fullscreen mode in X is performed using blits rather
than page flipping on the videocard. This would make it consistent with
windowed mode on Win32 as opposed to fullscreen mode.

The windowed modes are, however, definitely consistent.

Steve> ----- Original Message -----

From: Thomas Mondoshawan Tate [mailto:phoenix@psy.ed.asu.edu]
Sent: 12 December 2001 15:25
To: sdl at libsdl.org
Subject: Re: [SDL] [Win32] Problem with blits in Fullscreen mode?

On Wed, Dec 12, 2001 at 02:20:04PM -0000, Steve Lupton wrote:

In fullscreen mode when you call the flip, all that actually happens is
the
videocard is given a pointer to a different area in memory - no data is
actually copied. In this case, after the first flip, the backbuffer is
empty
(or possibly full of rubbish) again. If you flipped again, you would see
your original screen as this is also still in the same location.

In windowed mode when you call the flip, the contents of the backbuffer is
blitted onto your screen. In this case, the backbuffer is probably always
in
the same memory location and will therefore contain the already blitted
contents still within it.

Is this behaviour consistent between Win32 and X platforms?


Thomas “Mondoshawan” Tate
phoenix at psy.ed.asu.edu
http://tank.dyndns.org


This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com


That would explain why Linux-SDL ports of Win32 games run slower, then.
Thanks for the heads up. =o)On Wed, Dec 12, 2001 at 03:55:45PM -0000, Steve Lupton wrote:

I’m not 100% sure.

As I understand it, the fullscreen mode in X is performed using blits rather
than page flipping on the videocard. This would make it consistent with
windowed mode on Win32 as opposed to fullscreen mode.

The windowed modes are, however, definitely consistent.

Steve


Thomas “Mondoshawan” Tate
phoenix at psy.ed.asu.edu
http://tank.dyndns.org
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20011212/7101dfd5/attachment.pgp

The newest nvidia drivers do perform page flipping (at least under OpenGL) when
running at certain resolutions (I believe 640x480, 800x600, and another res…)

-EvilTypeGuyOn Wed, Dec 12, 2001 at 09:05:08AM -0700, Thomas Mondoshawan Tate wrote:

On Wed, Dec 12, 2001 at 03:55:45PM -0000, Steve Lupton wrote:

I’m not 100% sure.

As I understand it, the fullscreen mode in X is performed using blits rather
than page flipping on the videocard. This would make it consistent with
windowed mode on Win32 as opposed to fullscreen mode.

The windowed modes are, however, definitely consistent.

Steve

That would explain why Linux-SDL ports of Win32 games run slower, then.
Thanks for the heads up. =o)

“Peter T” wrote in message
news:mailman.1008153244.9982.sdl at libsdl.org

#include "SDL.h"
int main( int argc, char* argv[] )
{
SDL_Init ( SDL_INIT_VIDEO ) ;

atexit ( SDL_Quit ) ;

SDL_Surface* pSurface = SDL_SetVideoMode ( 800 , 600
, 0, SDL_HWSURFACE | SDL_FULLSCREEN | SDL_DOUBLEBUF )
;
SDL_Surface* imageTile = SDL_LoadBMP(“boom.bmp”);
SDL_Surface* background =
SDL_LoadBMP(“background.bmp”);
SDL_WM_SetCaption(“Stupid SDL test program”, NULL);
SDL_SetColorKey(imageTile, SDL_SRCCOLORKEY,
SDL_MapRGB(imageTile->format, 255, 0, 128));

SDL_Event event;
SDL_BlitSurface(background, NULL, pSurface, NULL);
SDL_Flip(pSurface);
for ( ; ; )
{
if ( SDL_PollEvent ( &event ) )
{
if ( event.type == SDL_QUIT ) break ;
if ( event.type == SDL_KEYDOWN ) {
SDL_SaveBMP(pSurface, “screenshot.bmp”);
SDL_BlitSurface(background, NULL, pSurface, NULL);
SDL_Flip(pSurface);

This leaves the contents of your main surface in an undefined state.

}
if ( event.type == SDL_MOUSEBUTTONDOWN) {
SDL_Rect target;
target.x = event.button.x - 10;
target.y = event.button.y - 10;
SDL_BlitSurface(imageTile, NULL, pSurface,
&target);

You need to draw over the entire screen surface or there will be unspecified
visual artifacts.> SDL_Flip(pSurface);

}
}
}

return ( 0 ) ;
}


Rainer Deyke (root at rainerdeyke.com)
Shareware computer games - http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor

i remember looking through the SDL docs one day, and i came across an
explanation for your mouse problem. i looked for it today, but cannot for
the life of me find it. it said something about the mouse cursor not being
usable in full screen mode, and that if you want one, you’d have to
implement it yourself. its in the docs somewhere.>From: Peter T

Reply-To: sdl at libsdl.org
To: sdl at libsdl.org
Subject: RE: [SDL] [Win32] Problem with blits in Fullscreen mode?
Date: Wed, 12 Dec 2001 15:45:07 +0000 (GMT)

When you flip, the new backbuffer is in a completely
unknown state.

Thanks, i see the problem with the old code now.

Im still having some problems though:

  1. If i use HW or SW surface in fullscreen with
    doublebuffering set, i cant see the mouse cursor!

  2. If i dont use the doublebuffer flag, i can see the
    mouse but it leaves a transparent hole in my blitted
    picture(when i move the cursor) so i can see the
    background picture.(this is mysterious to me, i could
    perhaps understand that the mouse could cause an
    artifact, but it seems strange that it doesnt just
    cause blackness or some garbage.)

Again, thank you for taking the time to explain.


Do You Yahoo!?
Everything you’ll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com


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


Chat with friends online, try MSN Messenger: http://messenger.msn.com

This leaves the contents of your main surface in an
undefined state.

Thanks, i gathered as much from Steve Luptons
response.

But even after fixing(ie, i repainted the whole
background, and one of the little explosion pictures i
had, kind of changed the “purpose” of the program, but
that is irrelevant here :wink: that i do have some
problems, as i wrote in response to steve:

"1. If i use HW or SW surface in fullscreen with
doublebuffering set, i cant see the mouse cursor!

  1. If i dont use the doublebuffer flag, i can see the
    mouse but it leaves a transparent hole in my blitted
    picture(when i move the cursor) so i can see the
    background picture.(this is mysterious to me, i could
    perhaps understand that the mouse could cause an
    artifact, but it seems strange that it doesnt just
    cause blackness or some garbage.)"__________________________________________________
    Do You Yahoo!?
    Everything you’ll ever need on one web page
    from News and Sport to Email and Music Charts
    http://uk.my.yahoo.com

Thanks for the response, i suppose implementing a
mousepointer isnt that bad, im more worried about the
problems in SW mode where it DOES show, but leaves
artifacts. Is there a way to hide the mousecursor and
draw your own in this case?

— Ernest Pazera wrote: >> i remember looking through the SDL docs one day, and

i came across an
explanation for your mouse problem. i looked for it
today, but cannot for
the life of me find it. it said something about the
mouse cursor not being
usable in full screen mode, and that if you want
one, you’d have to
implement it yourself. its in the docs somewhere.


Do You Yahoo!?
Everything you’ll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

SDL_ShowCursor ( SDL_DISABLE ) ;>From: Peter T

Reply-To: sdl at libsdl.org
To: sdl at libsdl.org
Subject: RE: [SDL] [Win32] Problem with blits in Fullscreen mode?
Date: Wed, 12 Dec 2001 18:25:43 +0000 (GMT)

Thanks for the response, i suppose implementing a
mousepointer isnt that bad, im more worried about the
problems in SW mode where it DOES show, but leaves
artifacts. Is there a way to hide the mousecursor and
draw your own in this case?

— Ernest Pazera <@Ernest_Pazera> wrote: >

i remember looking through the SDL docs one day, and
i came across an
explanation for your mouse problem. i looked for it
today, but cannot for
the life of me find it. it said something about the
mouse cursor not being
usable in full screen mode, and that if you want
one, you’d have to
implement it yourself. its in the docs somewhere.


Do You Yahoo!?
Everything you’ll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com


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


Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.