Question relating to SDL_flip and splits

Hi, I have a question relating to my use of SDL.

Below is the code. it seems to compile fine. However, it doesn’t
function as it is intended and I don’t know why. Hopefully somebody can
shed some light on the matter. My question is:

Even though (i think) I’m using SDL_DOUBLEBUF with SDL_flip, i still get
splits in my screen. It appears not to be updating on the screen
refresh. Now, I am using a Laptop with a TFT screen. Is this going to
affect things?

Many Thanks

Henry Gomersall

/test.c/

#include “SDL/SDL.h”
#include <stdio.h>
#include <sfftw.h>

#define DISPLAY_RES_X 320
#define DISPLAY_RES_Y 240

int main() {
/* set various SDL variables */
SDL_Surface *screen;
SDL_Color colour[1];
SDL_Event keyboard_check;
SDL_PixelFormat *colour_format;

/* Initilise SDL */

printf(" SDL.\n");

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

if(SDL_VideoModeOK(DISPLAY_RES_X, DISPLAY_RES_Y, 32, SDL_FULLSCREEN |
SDL_HWSURFACE | SDL_DOUBLEBUF) != 32)
fprintf(stderr, “video mode not possible on this hardware\n”);

/* requesting a 32 bit hardware surface with a hardware palette */

screen = SDL_SetVideoMode(DISPLAY_RES_X, DISPLAY_RES_Y, 32,
SDL_FULLSCREEN | SDL_HWSURFACE | SDL_DOUBLEBUF);
if ( screen == NULL ) {
fprintf(stderr, “Couldn’t set %ix%ix8 video mode: %s\n”,
DISPLAY_RES_X, DISPLAY_RES_Y, SDL_GetError());
exit(1);
}

colour[0].r = 255;
colour[0].g = 0;
colour[0].b = 0;

colour_format=screen->format;

for(;;){

while(SDL_PollEvent(&keyboard_check)){
  switch(keyboard_check.type) {
  case SDL_KEYDOWN:
exit(0);
  }
}

colour[0].r = (int)(rand() % 255);
SDL_FillRect(screen, 0, SDL_MapRGB(colour_format, colour[0].r, 0,

0));

// Update the screen
SDL_Flip(screen);

}

printf(“SDL initialized.\n”);

printf(“Quiting SDL.\n”);

/* Shutdown all subsystems */
SDL_Quit();

printf(“Quiting…\n”);

exit(0);
}

-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20021126/a34acde1/attachment.pgp

It works the same here, and I am on a very standard desktop. I have no
idea what’s going on. I even tried to put in the frame limiter:

void WaitFrame(void)
{
static Uint32 next_tick = 0;
Uint32 this_tick;

// Wait for the next frame 
this_tick = SDL_GetTicks(); 
if ( this_tick < next_tick ) {
	SDL_Delay(next_tick-this_tick);
}
next_tick = this_tick + (1000/FRAMES_PER_SEC);

}

set at 50 frames per second and I’m still seeing the same thing, this
implies to me that it must have something to do with SDL_FillRect
drawing directly to the screen instead of the buffer. Have you tried
creating a surface, filling it with the red then blitting it to the
screen?

RobertOn Tue, 2002-11-26 at 04:42, Henry Gomersall wrote:

Hi, I have a question relating to my use of SDL.

Below is the code. it seems to compile fine. However, it doesn’t
function as it is intended and I don’t know why. Hopefully somebody can
shed some light on the matter. My question is:

Even though (i think) I’m using SDL_DOUBLEBUF with SDL_flip, i still get
splits in my screen. It appears not to be updating on the screen
refresh. Now, I am using a Laptop with a TFT screen. Is this going to
affect things?

Many Thanks

Henry Gomersall

/test.c/

#include “SDL/SDL.h”
#include <stdio.h>
#include <sfftw.h>

#define DISPLAY_RES_X 320
#define DISPLAY_RES_Y 240

int main() {
/* set various SDL variables */
SDL_Surface *screen;
SDL_Color colour[1];
SDL_Event keyboard_check;
SDL_PixelFormat *colour_format;

/* Initilise SDL */

printf(" SDL.\n");

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

if(SDL_VideoModeOK(DISPLAY_RES_X, DISPLAY_RES_Y, 32, SDL_FULLSCREEN |
SDL_HWSURFACE | SDL_DOUBLEBUF) != 32)
fprintf(stderr, “video mode not possible on this hardware\n”);

/* requesting a 32 bit hardware surface with a hardware palette */

screen = SDL_SetVideoMode(DISPLAY_RES_X, DISPLAY_RES_Y, 32,
SDL_FULLSCREEN | SDL_HWSURFACE | SDL_DOUBLEBUF);
if ( screen == NULL ) {
fprintf(stderr, “Couldn’t set %ix%ix8 video mode: %s\n”,
DISPLAY_RES_X, DISPLAY_RES_Y, SDL_GetError());
exit(1);
}

colour[0].r = 255;
colour[0].g = 0;
colour[0].b = 0;

colour_format=screen->format;

for(;;){

while(SDL_PollEvent(&keyboard_check)){
  switch(keyboard_check.type) {
  case SDL_KEYDOWN:

exit(0);
}
}

colour[0].r = (int)(rand() % 255);
SDL_FillRect(screen, 0, SDL_MapRGB(colour_format, colour[0].r, 0,

0));

// Update the screen
SDL_Flip(screen);

}

printf(“SDL initialized.\n”);

printf(“Quiting SDL.\n”);

/* Shutdown all subsystems */
SDL_Quit();

printf(“Quiting…\n”);

exit(0);
}

It works the same here, and I am on a very standard desktop. I have no
idea what’s going on. I even tried to put in the frame limiter:

void WaitFrame(void)
{
static Uint32 next_tick = 0;
Uint32 this_tick;

// Wait for the next frame
this_tick = SDL_GetTicks();
if ( this_tick < next_tick ) {
SDL_Delay(next_tick-this_tick);
}
next_tick = this_tick + (1000/FRAMES_PER_SEC);
}

set at 50 frames per second and I’m still seeing the same thing, this
implies to me that it must have something to do with SDL_FillRect
drawing directly to the screen instead of the buffer.

Yeah, I thought this, but the screen doesn’t update until I do an
SDL_flip. Without the SDL_flip, I just get a blank screen. Does anyone
have a clue what is going on?

Have you tried
creating a surface, filling it with the red then blitting it to the
screen?

No, I guess i’ll try this next.

Robert

Cheers

Henry
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20021126/b6650dcb/attachment.pgpOn Tue, 2002-11-26 at 11:23, Robert Diel wrote:

// Wait for the next frame
this_tick = SDL_GetTicks();
if ( this_tick < next_tick ) {
SDL_Delay(next_tick-this_tick);
}
next_tick = this_tick + (1000/FRAMES_PER_SEC);
}

FYI: This isn’t a very good way of waiting for the next frame,
because SDL_Delay() has a 10ms resolution on most systems. If
next_tick is only 1 ms more than this_tick, you’ll waste 9 ms. A
better solution is a combination of SDL_Delay() and a busy loop.

set at 50 frames per second and I’m still seeing the same thing,
this

implies to me that it must have something to do with SDL_FillRect
drawing directly to the screen instead of the buffer.

Yeah, I thought this, but the screen doesn’t update until I do an
SDL_flip. Without the SDL_flip, I just get a blank screen. Does
anyone have a clue what is going on?

My best guess: Your screen is 320x240 - I don’t know if SDL supports
this low a resolution. It may be emulating it, which may be causing
these nasty artifacts. Try opening a 640x480 screen and see what
that does.–
Matthijs Hollemans
www.allyoursoftware.com

My best guess: Your screen is 320x240 - I don’t know if SDL supports
this low a resolution. It may be emulating it, which may be causing
these nasty artifacts. Try opening a 640x480 screen and see what
that does.

That helps a lot. But it only seems to work for 640x480. What
resolutions does SDL support? my default screen resolution is 1400x1050.
I don’t expect this to be supported, but all the other standard
resolutions (800x600, 1024x768, 1152x864 and 1280x1024) don’t improve
matters. Also, 640x480 does occasionally tear.

cheers

hen
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20021126/96cde360/attachment.pgp

What resolutions SDL supports, depend very much on the system and/or
driver… Windows 95/98/me/2000(?) support most feasible resolutions via
DirectX, i.e. if your hardware supports it, Windows supports it. Windows XP,
however, demands an absolute minimum of 800*600 resolution(which is just plain
stupid imho). Other graphical systems may have different limitations.

Henry Gomersall wrote:> > My best guess: Your screen is 320x240 - I don’t know if SDL supports

this low a resolution. It may be emulating it, which may be causing
these nasty artifacts. Try opening a 640x480 screen and see what
that does.

That helps a lot. But it only seems to work for 640x480. What
resolutions does SDL support? my default screen resolution is 1400x1050.
I don’t expect this to be supported, but all the other standard
resolutions (800x600, 1024x768, 1152x864 and 1280x1024) don’t improve
matters. Also, 640x480 does occasionally tear.

cheers

hen


                   Name: signature.asc

signature.asc Type: application/pgp-signature
Description: This is a digitally signed message part