Update the screen issue

HI,

well i’ve ported somecode form directdraw7 to sdl.

and it’s working fine, but i have a problem: the screen doesn’t update :\

here is my main loop

void
WinApp::MainLoop() {

SDL_Event event;

bool Quit = false;
//bool Active = false;
while(!Quit) {

	if(SDL_PollEvent(&event)) {

		if ( event.key.keysym.sym == SDLK_ESCAPE ) {

			Quit = true;
		}

		switch(event.type) {

			//case SDL_APPACTIVE:
			// {
			//Active = (event.active.gain == 0) ?false:true;
			//break;
			//}
			case SDL_QUIT:
				{
					Quit = true;
				}
			default:break;
		}

	}else {

		//if(Active == true) {
		//if(1) {
		if(SDL_GetAppState() & SDL_APPACTIVE){
			// draw everything
			this->draw();

			/* ..And calculate the fps */
			calcFrameRate();
			/* now flip the back buffer to the front.. */
			int er = SDL_Flip(_MainScreen);
		}
	}
}

}

// init
SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER)==0)

_MainScreen = SDL_SetVideoMode(w,h,bpp,flags);

where flags = SDL_HWSURFACE |SDL_DOUBLEBUF //| SDL_FULLSCREEN
i run windowed mode when i want to debug.

SDL_Flip returns 0 //success
i tried SDL_UpdateRects but it doesn’t solve the problem

i tried to isolate the problem, and i can tell you the the code from
directdraw doesn’t cause the problem since it’s just some maths classes.
any ideas, help ?!

thanx in advance

ps : i use SDL 1.2.7_________________________________________________________________
MSN Search, le moteur de recherche qui pense comme vous !
http://search.msn.fr

HI,

well i’ve ported somecode form directdraw7 to sdl.

and it’s working fine, but i have a problem: the screen doesn’t
update :\

Then, how do you know that it’s working fine? :wink:

here is my main loop

void
WinApp::MainLoop() {

SDL_Event event;

bool Quit = false;
//bool Active = false;
while(!Quit) {

(Suggestion: I’d make this “while(SDL_PollEvent(&event)”. Saves one
level of indentation by avoiding the “else” case, and more
importantly; you know that the outer loop essentially runs once per
frame, and nothing else.)

  if(SDL_PollEvent(&event)) {
  	if ( event.key.keysym.sym == SDLK_ESCAPE ) {

  		Quit = true;
  	}

  	switch(event.type) {

  		//case SDL_APPACTIVE:
  		// {
  		//Active = (event.active.gain == 0) ?false:true;
  		//break;
  		//}
  		case SDL_QUIT:
  			{
  				Quit = true;
  			}
  		default:break;
  	}

  }else {

  	//if(Active == true) {
  	//if(1) {
  	if(SDL_GetAppState() & SDL_APPACTIVE){
  		// draw everything
  		this->draw();

  		/* ..And calculate the fps */
  		calcFrameRate();
  		/* now flip the back buffer to the front.. */
  		int er = SDL_Flip(_MainScreen);
  	}

To avoid hogging the CPU (100% load) when the app isn’t active, add
something like:

		else
			SDL_Delay(100);

here, or (better) do something that turns that SDL_PollEvent() at the
top into as SDL_WaitEvent(), so you don’t have to spin around that
loop at insane speed just to read events.

(Now, some people would suggest that you should also insert an
SDL_Delay() after SDL_Flip(). I say “yes, but make it a
user option”. It will effectively restrict your frame rate to 100 Hz
on most operating systems, which will, in some cases, result in less
smooth animation than you may get otherwise.)

  }

}

}

// init
SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER)==0)

_MainScreen = SDL_SetVideoMode(w,h,bpp,flags);

where flags = SDL_HWSURFACE |SDL_DOUBLEBUF //| SDL_FULLSCREEN
i run windowed mode when i want to debug.

SDL_DOUBLEBUF implies SDL_HWSURFACE. You will not get a double
buffered h/w display surface with a s/w shadow surface by saying
SDL_DOUBLEBUF | SDL_SWSURFACE. (SDL_SWSURFACE == 0 BTW…)

However, SDL_FULLSCREEN is often required to get a h/w surface at all,
and pretty much always required for a double buffered h/w surface.
(Windowed modes generally do not support page flipping.)

SDL_Flip returns 0 //success
i tried SDL_UpdateRects but it doesn’t solve the problem

Nope, if you need SDL_UpdateRects(), SDL_Flip() will actuall call it
for you… (For the full screen, though. If performance is critical
and you aren’t animating the whole screen, use only
SDL_UpdateRects() unless you have a h/w display surface.)

i tried to isolate the problem, and i can tell you the the code
from directdraw doesn’t cause the problem since it’s just some
maths classes.

Oh, you really wish coding was that simple, don’t you? ;-D

Anyway, if it works correctly with DDraw, it’s at least much less
likely to be causing the trouble. :slight_smile:

any ideas, help ?!

Very simple, at least in theory: Try homing in on the problem by
locating the general area of the problem, and then refining that area
until you’ve found the offending line of code.

For example, is your code actually drawing anything? Try replacing
"this->draw();" with something very simple, like drawing a filled
rectangle in a random color using SDL_FillRect(). If that works, the
problem is in draw(). If not, the problem is somewhere in your main
loop. Next, you just hack something to find out which half of draw()

  • or the mail loop - the problem is in. And so on…

//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 03 May 2004 08.00, CrazyLegs EasyTo wrote:

greetings
thanks for replying!>From: David Olofson

Reply-To: sdl at libsdl.org
To: sdl at libsdl.org
Subject: Re: [SDL] Update the screen issue
Date: Mon, 3 May 2004 09:28:19 +0200

On Monday 03 May 2004 08.00, CrazyLegs EasyTo wrote:

HI,

well i’ve ported somecode form directdraw7 to sdl.

and it’s working fine, but i have a problem: the screen doesn’t
update :\

Then, how do you know that it’s working fine? :wink:


well everything is drawing well, but the screen doesn’t update,
(the content of the previous frames remains there)

here is my main loop

void
WinApp::MainLoop() {

SDL_Event event;

bool Quit = false;
//bool Active = false;
while(!Quit) {

(Suggestion: I’d make this “while(SDL_PollEvent(&event)”. Saves one
level of indentation by avoiding the “else” case, and more
importantly; you know that the outer loop essentially runs once per
frame, and nothing else.)


hmm, can you please gimme a simple exemple?! use my pseudo code if it’s
possible.


  if(SDL_PollEvent(&event)) {
  	if ( event.key.keysym.sym == SDLK_ESCAPE ) {

  		Quit = true;
  	}

  	switch(event.type) {

  		//case SDL_APPACTIVE:
  		// {
  		//Active = (event.active.gain == 0) ?false:true;
  		//break;
  		//}
  		case SDL_QUIT:
  			{
  				Quit = true;
  			}
  		default:break;
  	}

  }else {

  	//if(Active == true) {
  	//if(1) {
  	if(SDL_GetAppState() & SDL_APPACTIVE){
  		// draw everything
  		this->draw();

  		/* ..And calculate the fps */
  		calcFrameRate();
  		/* now flip the back buffer to the front.. */
  		int er = SDL_Flip(_MainScreen);
  	}

To avoid hogging the CPU (100% load) when the app isn’t active, add
something like:

  	else
  		SDL_Delay(100);

here, or (better) do something that turns that SDL_PollEvent() at the
top into as SDL_WaitEvent(), so you don’t have to spin around that
loop at insane speed just to read events.


Can you ellaborate(simple exemple would be appreciated)?!

(Now, some people would suggest that you should also insert an
SDL_Delay() after SDL_Flip(). I say “yes, but make it a
user option”. It will effectively restrict your frame rate to 100 Hz
on most operating systems, which will, in some cases, result in less
smooth animation than you may get otherwise.)


well i can lock the frame rate to some value and stick out!
but i’m using SDL to write(port) a 3D software engine.

  }
}

}

// init
SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER)==0)

_MainScreen = SDL_SetVideoMode(w,h,bpp,flags);

where flags = SDL_HWSURFACE |SDL_DOUBLEBUF //| SDL_FULLSCREEN
i run windowed mode when i want to debug.

SDL_DOUBLEBUF implies SDL_HWSURFACE. You will not get a double
buffered h/w display surface with a s/w shadow surface by saying
SDL_DOUBLEBUF | SDL_SWSURFACE. (SDL_SWSURFACE == 0 BTW…)


i know!

However, SDL_FULLSCREEN is often required to get a h/w surface at all,
and pretty much always required for a double buffered h/w surface.
(Windowed modes generally do not support page flipping.)

SDL_Flip returns 0 //success
i tried SDL_UpdateRects but it doesn’t solve the problem

Nope, if you need SDL_UpdateRects(), SDL_Flip() will actuall call it
for you… (For the full screen, though. If performance is critical
and you aren’t animating the whole screen, use only
SDL_UpdateRects() unless you have a h/w display surface.)


yea, i figured this out, hardware acceleration is only fullscreen.

i tried to isolate the problem, and i can tell you the the code
from directdraw doesn’t cause the problem since it’s just some
maths classes.

Oh, you really wish coding was that simple, don’t you? ;-D


Don’t you, huh?! :wink:

Anyway, if it works correctly with DDraw, it’s at least much less
likely to be causing the trouble. :slight_smile:

any ideas, help ?!

Very simple, at least in theory: Try homing in on the problem by
locating the general area of the problem, and then refining that area
until you’ve found the offending line of code.

For example, is your code actually drawing anything? Try replacing
"this->draw();" with something very simple, like drawing a filled
rectangle in a random color using SDL_FillRect(). If that works, the
problem is in draw(). If not, the problem is somewhere in your main
loop. Next, you just hack something to find out which half of draw()

  • or the mail loop - the problem is in. And so on…

i removed all the code from the draw method
i just print a pixel with a random postion and color,
and the problem still there : the screen is filled with dots from the
previous frames instead of only one dot.

thanx for your answer

//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


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


MSN Search, le moteur de recherche qui pense comme vous !
http://search.msn.fr/

[…]

Then, how do you know that it’s working fine? :wink:


well everything is drawing well, but the screen doesn’t update,
(the content of the previous frames remains there)

Ah… I see. Unless you completely cover the screen with new graphics
every frame, you have to clear the screen one way or another.
SDL_Flip() either copies your shadow buffer to the display surface,
or swaps the visible page with the one you just rendered into. These
cases are different, but they have one thing in common: Old stuff is
left around until you draw over it.

[…]

(Suggestion: I’d make this “while(SDL_PollEvent(&event)”. Saves
one level of indentation by avoiding the “else” case, and more
importantly; you know that the outer loop essentially runs once
per frame, and nothing else.)


hmm, can you please gimme a simple exemple?! use my pseudo code if
it’s possible.

    while(!Quit) {
            while(SDL_PollEvent(&event)) {
                    if ( event.key.keysym.sym == SDLK_ESCAPE ) {
                            Quit = true;
                    }
                    switch(event.type) {
                            case SDL_QUIT:
                                    Quit = true;
                                    break;
                            default:
                                    break;
                    }
            }
            if(SDL_GetAppState() & SDL_APPACTIVE){
                    // draw everything
                    this->draw();

                    /* ..And calculate the fps */
                    calcFrameRate();
                    /* now flip the back buffer to the front.. */
                    int er = SDL_Flip(_MainScreen);
            }
    }

Just noticed another thing: The if(event.key.keysym…) statement may
react at random on various events, since the event.key part is
invalid unless the event really is a keyboard event. Always check the
event before touching any other part of the event union.

[…]

To avoid hogging the CPU (100% load) when the app isn’t active,
add something like:

  else
  	SDL_Delay(100);

here, or (better) do something that turns that SDL_PollEvent() at
the top into as SDL_WaitEvent(), so you don’t have to spin around
that loop at insane speed just to read events.


Can you ellaborate(simple exemple would be appreciated)?!

What happens in your version is that if the application isn’t active,
it’ll spin through the main loop, polling events as fast as the CPU
allows. That is, while your application is in the background, not
really doing anything, it consumes all CPU power it can get by,
potentially making the whole system slow and unresponsive for no
reason.

On a multiuser OS, or on a battery powered machine, this is obviously
considered a criminal offense. :slight_smile:

So, either

* just go to sleep for a moment (SDL_Delay(100) -
  one tenth of a second), to nicely hand over the
  CPU to the OS and any processes that might actually
  have real work to do,

or

* if possible (that is, if you're just waiting for SDL
  events, as in this case), do it the proper way and
  use SDL_WaitEvent(). As opposed to SDL_PollEvent(),
  SDL_WaitEvent() will block until something actually
  happens. So, if your app is inactive and there's no
  even for it in say, ten seconds, it won't use a
  single CPU cycle during those ten seconds.

(Now, some people would suggest that you should also insert an
SDL_Delay() after SDL_Flip(). I say “yes, but make it
a user option”. It will effectively restrict your frame rate to
100 Hz on most operating systems, which will, in some cases,
result in less smooth animation than you may get otherwise.)


well i can lock the frame rate to some value and stick out!

Actually, no you can’t, really. You can make the engine render at any
frame rate you like as long as it doesn’t try to display anything.
However, SDL_Flip() (on a proper target with retrace sync) will lock
the frame rate to the monitor refresh rate.

Also, since SDL_Delay() and the SDL timers generally have a
granularity of 10 ms, you can’t use those to accurately control the
frame rate on targets without retrace sync. As long as you want a
frame rate below 100 Hz, you can “throttle” the game using a mix of
SDL_Delay() calls and busy-waiting on SDL_GetTicks().

but i’m using SDL to write(port) a 3D software engine.

That’s not really relevant, provided the game is designed to deal with
whatever frame rate it gets. (Old 2D games are generally not
designed to deal with that, so you get some extra work if you want to
port one of those.)

[…]

i tried to isolate the problem, and i can tell you the the code
from directdraw doesn’t cause the problem since it’s just some
maths classes.

Oh, you really wish coding was that simple, don’t you? ;-D


Don’t you, huh?! :wink:

Naah… That would be pretty boring in the long run. :smiley:

[…]

i removed all the code from the draw method
i just print a pixel with a random postion and color,
and the problem still there : the screen is filled with dots from
the previous frames instead of only one dot.

Yes, as expected… (See above.)

Is the game supposed to overwrite the whole screen? (I’d guess so, if
it’s a 3D engine…) If so, I’d guess some part of the graphics went
missing in action. If you really repaint the whole screen every
frame, you can’t go wrong; SDL_Flip() should Just Work™.

//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 03 May 2004 10.10, CrazyLegs EasyTo wrote:

ello again, and thank you so much>From: David Olofson

Reply-To: sdl at libsdl.org
To: sdl at libsdl.org
Subject: Re: [SDL] Update the screen issue
Date: Mon, 3 May 2004 11:42:19 +0200

On Monday 03 May 2004 10.10, CrazyLegs EasyTo wrote:
[…]

Then, how do you know that it’s working fine? :wink:


well everything is drawing well, but the screen doesn’t update,
(the content of the previous frames remains there)

Ah… I see. Unless you completely cover the screen with new graphics
every frame, you have to clear the screen one way or another.
SDL_Flip() either copies your shadow buffer to the display surface,
or swaps the visible page with the one you just rendered into. These
cases are different, but they have one thing in common: Old stuff is
left around until you draw over it.

back-buffering ,and page flipping

[…]

(Suggestion: I’d make this “while(SDL_PollEvent(&event)”. Saves
one level of indentation by avoiding the “else” case, and more
importantly; you know that the outer loop essentially runs once
per frame, and nothing else.)


hmm, can you please gimme a simple exemple?! use my pseudo code if
it’s possible.

    while(!Quit) {
            while(SDL_PollEvent(&event)) {
                    if ( event.key.keysym.sym == SDLK_ESCAPE ) {
                            Quit = true;
                    }
                    switch(event.type) {
                            case SDL_QUIT:
                                    Quit = true;
                                    break;
                            default:
                                    break;
                    }
            }
            if(SDL_GetAppState() & SDL_APPACTIVE){
                    // draw everything
                    this->draw();

                    /* ..And calculate the fps */
                    calcFrameRate();
                    /* now flip the back buffer to the front.. */
                    int er = SDL_Flip(_MainScreen);
            }
    }

Just noticed another thing: The if(event.key.keysym…) statement may
react at random on various events, since the event.key part is
invalid unless the event really is a keyboard event. Always check the
event before touching any other part of the event union.

yea i noticed it too, thanx anyway

[…]

To avoid hogging the CPU (100% load) when the app isn’t active,
add something like:

  else
  	SDL_Delay(100);

here, or (better) do something that turns that SDL_PollEvent() at
the top into as SDL_WaitEvent(), so you don’t have to spin around
that loop at insane speed just to read events.


Can you ellaborate(simple exemple would be appreciated)?!

What happens in your version is that if the application isn’t active,
it’ll spin through the main loop, polling events as fast as the CPU
allows. That is, while your application is in the background, not
really doing anything, it consumes all CPU power it can get by,
potentially making the whole system slow and unresponsive for no
reason.

On a multiuser OS, or on a battery powered machine, this is obviously
considered a criminal offense. :slight_smile:

So, either

  • just go to sleep for a moment (SDL_Delay(100) -
    one tenth of a second), to nicely hand over the
    CPU to the OS and any processes that might actually
    have real work to do,

or

  • if possible (that is, if you’re just waiting for SDL
    events, as in this case), do it the proper way and
    use SDL_WaitEvent(). As opposed to SDL_PollEvent(),
    SDL_WaitEvent() will block until something actually
    happens. So, if your app is inactive and there’s no
    even for it in say, ten seconds, it won’t use a
    single CPU cycle during those ten seconds.

the 2nd in fact is more interesting, how can i do it(my pseudo code plz),
i’ve never used SDL_WaitEvent() before

(Now, some people would suggest that you should also insert an
SDL_Delay() after SDL_Flip(). I say “yes, but make it
a user option”. It will effectively restrict your frame rate to
100 Hz on most operating systems, which will, in some cases,
result in less smooth animation than you may get otherwise.)


well i can lock the frame rate to some value and stick out!

Actually, no you can’t, really. You can make the engine render at any
frame rate you like as long as it doesn’t try to display anything.
However, SDL_Flip() (on a proper target with retrace sync) will lock
the frame rate to the monitor refresh rate.

Also, since SDL_Delay() and the SDL timers generally have a
granularity of 10 ms, you can’t use those to accurately control the
frame rate on targets without retrace sync. As long as you want a
frame rate below 100 Hz, you can “throttle” the game using a mix of
SDL_Delay() calls and busy-waiting on SDL_GetTicks().

but i’m using SDL to write(port) a 3D software engine.

That’s not really relevant, provided the game is designed to deal with
whatever frame rate it gets. (Old 2D games are generally not
designed to deal with that, so you get some extra work if you want to
port one of those.)

[…]

i tried to isolate the problem, and i can tell you the the code
from directdraw doesn’t cause the problem since it’s just some
maths classes.

Oh, you really wish coding was that simple, don’t you? ;-D


Don’t you, huh?! :wink:

Naah… That would be pretty boring in the long run. :smiley:
i agree =D, but when you’re debugging it’s just the rescue.

[…]

i removed all the code from the draw method
i just print a pixel with a random postion and color,
and the problem still there : the screen is filled with dots from
the previous frames instead of only one dot.

Yes, as expected… (See above.)

Is the game supposed to overwrite the whole screen? (I’d guess so, if
it’s a 3D engine…) If so, I’d guess some part of the graphics went
missing in action. If you really repaint the whole screen every
frame, you can’t go wrong; SDL_Flip() should Just Work™.

yes it should overwrite the whole screen(it’s a 3d engine)
that’s weird SDL_Flip get called but it doesn’t act as expected!
would you please accept my code( i removed all the 3d engine code and keept
it resonably small)
if so plz give me your email, icq,aim or whatever

thanx in advance!

//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


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


Hotmail : un compte GRATUIT qui vous suit partout et tout le temps !
http://g.msn.fr/FR1000/9493

ello again, and thank you so much>From: David Olofson

Reply-To: sdl at libsdl.org
To: sdl at libsdl.org
Subject: Re: [SDL] Update the screen issue
Date: Mon, 3 May 2004 11:42:19 +0200

On Monday 03 May 2004 10.10, CrazyLegs EasyTo wrote:
[…]

Then, how do you know that it’s working fine? :wink:


well everything is drawing well, but the screen doesn’t update,
(the content of the previous frames remains there)

Ah… I see. Unless you completely cover the screen with new graphics
every frame, you have to clear the screen one way or another.
SDL_Flip() either copies your shadow buffer to the display surface,
or swaps the visible page with the one you just rendered into. These
cases are different, but they have one thing in common: Old stuff is
left around until you draw over it.

back-buffering ,and page flipping

[…]

(Suggestion: I’d make this “while(SDL_PollEvent(&event)”. Saves
one level of indentation by avoiding the “else” case, and more
importantly; you know that the outer loop essentially runs once
per frame, and nothing else.)


hmm, can you please gimme a simple exemple?! use my pseudo code if
it’s possible.

    while(!Quit) {
            while(SDL_PollEvent(&event)) {
                    if ( event.key.keysym.sym == SDLK_ESCAPE ) {
                            Quit = true;
                    }
                    switch(event.type) {
                            case SDL_QUIT:
                                    Quit = true;
                                    break;
                            default:
                                    break;
                    }
            }
            if(SDL_GetAppState() & SDL_APPACTIVE){
                    // draw everything
                    this->draw();

                    /* ..And calculate the fps */
                    calcFrameRate();
                    /* now flip the back buffer to the front.. */
                    int er = SDL_Flip(_MainScreen);
            }
    }

Just noticed another thing: The if(event.key.keysym…) statement may
react at random on various events, since the event.key part is
invalid unless the event really is a keyboard event. Always check the
event before touching any other part of the event union.

yea i noticed it too, thanx anyway

[…]

To avoid hogging the CPU (100% load) when the app isn’t active,
add something like:

  else
  	SDL_Delay(100);

here, or (better) do something that turns that SDL_PollEvent() at
the top into as SDL_WaitEvent(), so you don’t have to spin around
that loop at insane speed just to read events.


Can you ellaborate(simple exemple would be appreciated)?!

What happens in your version is that if the application isn’t active,
it’ll spin through the main loop, polling events as fast as the CPU
allows. That is, while your application is in the background, not
really doing anything, it consumes all CPU power it can get by,
potentially making the whole system slow and unresponsive for no
reason.

On a multiuser OS, or on a battery powered machine, this is obviously
considered a criminal offense. :slight_smile:

So, either

  • just go to sleep for a moment (SDL_Delay(100) -
    one tenth of a second), to nicely hand over the
    CPU to the OS and any processes that might actually
    have real work to do,

or

  • if possible (that is, if you’re just waiting for SDL
    events, as in this case), do it the proper way and
    use SDL_WaitEvent(). As opposed to SDL_PollEvent(),
    SDL_WaitEvent() will block until something actually
    happens. So, if your app is inactive and there’s no
    even for it in say, ten seconds, it won’t use a
    single CPU cycle during those ten seconds.

the 2nd in fact is more interesting, how can i do it(my pseudo code plz),
i’ve never used SDL_WaitEvent() before

(Now, some people would suggest that you should also insert an
SDL_Delay() after SDL_Flip(). I say “yes, but make it
a user option”. It will effectively restrict your frame rate to
100 Hz on most operating systems, which will, in some cases,
result in less smooth animation than you may get otherwise.)


well i can lock the frame rate to some value and stick out!

Actually, no you can’t, really. You can make the engine render at any
frame rate you like as long as it doesn’t try to display anything.
However, SDL_Flip() (on a proper target with retrace sync) will lock
the frame rate to the monitor refresh rate.

Also, since SDL_Delay() and the SDL timers generally have a
granularity of 10 ms, you can’t use those to accurately control the
frame rate on targets without retrace sync. As long as you want a
frame rate below 100 Hz, you can “throttle” the game using a mix of
SDL_Delay() calls and busy-waiting on SDL_GetTicks().

but i’m using SDL to write(port) a 3D software engine.

That’s not really relevant, provided the game is designed to deal with
whatever frame rate it gets. (Old 2D games are generally not
designed to deal with that, so you get some extra work if you want to
port one of those.)

[…]

i tried to isolate the problem, and i can tell you the the code
from directdraw doesn’t cause the problem since it’s just some
maths classes.

Oh, you really wish coding was that simple, don’t you? ;-D


Don’t you, huh?! :wink:

Naah… That would be pretty boring in the long run. :smiley:
i agree =D, but when you’re debugging it’s just the rescue.

[…]

i removed all the code from the draw method
i just print a pixel with a random postion and color,
and the problem still there : the screen is filled with dots from
the previous frames instead of only one dot.

Yes, as expected… (See above.)

Is the game supposed to overwrite the whole screen? (I’d guess so, if
it’s a 3D engine…) If so, I’d guess some part of the graphics went
missing in action. If you really repaint the whole screen every
frame, you can’t go wrong; SDL_Flip() should Just Work™.

yes it should overwrite the whole screen(it’s a 3d engine)
that’s weird SDL_Flip get called but it doesn’t act as expected!
would you please accept my code( i removed all the 3d engine code and keept
it resonably small)
if so plz give me your email, icq,aim or whatever

thanx in advance!

//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


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


Dialoguez en direct et gratuitement avec vos amis sur
http://g.msn.fr/FR1001/866 MSN Messenger !

Hi! Looks like your mail was put on hold for a while there… Sorry
’bout that. :slight_smile:

[…]

  • if possible (that is, if you’re just waiting for SDL
    events, as in this case), do it the proper way and
    use SDL_WaitEvent(). As opposed to SDL_PollEvent(),
    SDL_WaitEvent() will block until something actually
    happens. So, if your app is inactive and there’s no
    even for it in say, ten seconds, it won’t use a
    single CPU cycle during those ten seconds.

the 2nd in fact is more interesting, how can i do it(my pseudo code
plz), i’ve never used SDL_WaitEvent() before

SDL_WaitEvent() works like SDL_PollEvent(), except that it doesn’t
return until there really is an event. That is, if there are no
events, the thread gets stuck until there are.

So, unless you have a separate thread for input, or a timer or
something that sends events, SDL_WaitEvent() isn’t very useful. Your
average game has to keep running whether there are incoming events or
not.

[…]

Is the game supposed to overwrite the whole screen? (I’d guess so,
if it’s a 3D engine…) If so, I’d guess some part of the
graphics went missing in action. If you really repaint the whole
screen every frame, you can’t go wrong; SDL_Flip() should Just
Work™.

yes it should overwrite the whole screen(it’s a 3d engine)
that’s weird SDL_Flip get called but it doesn’t act as expected!

Just a thougt: Is the 3D engine rendering directly into the display
surface, via the ‘pixels’ field? If so, make sure you’re locking the
display surface and rereading the pointer every frame.

would you please accept my code( i removed all the 3d engine code
and keept it resonably small)
if so plz give me your email, icq,aim or whatever

Well, you can mail anything smaller than 10 MB directly to
@David_Olofson, though I don’t have much time for making things
compile and stuff. (I’m on Linux with gcc, autotools etc. No Win32
dev tools at hand, except for Delphi and some old C++ Builder.)

//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 03 May 2004 19.19, CrazyLegs EasyTo wrote: