Troubles with double buffering still

I’m having trouble getting double buffering working still. The program
executes and the drawling loop keeps repeating, but nothing is drawn to
the screen. I’m posting below the functions that load the bitmaps,
initialize display, and the animation loop. Hope it isn’t too much, I
just don’t know what I’m doing wrong.

void hover::loadImages(void)// loads images
{
/* cone = load_pcx(“cone.pcx”,pal);
background = load_pcx(“road.pcx”,pal);
playerCar[0] = load_pcx(“hovercar1.pcx”,pal); Old functions
playerCar[1] = load_pcx(“blank.pcx”,pal2); from allegro
library
enemyCar[0] = load_pcx(“modifiedstock.pcx”,pal);
set_palette(pal);
image = create_bitmap(640,480);
playerCar[3] = create_bitmap(400,400);
/
/
Load a BMP image into a surface */
background = SDL_LoadBMP(“road.bmp”);
if ( background == NULL ) {
ComplainAndExit();
}

    /* Load a BMP image into a surface */
    playerCar[0] = SDL_LoadBMP("road.bmp");
    if ( playerCar[0] == NULL ) {
            ComplainAndExit();
    }

    /* Load a BMP image into a surface */
    AICar[0] = SDL_LoadBMP("road.bmp");
    if ( AICar[0] == NULL ) {
            ComplainAndExit();
    }

}

void hover::initVideoDisplay(void) / initializes video display
{
/* Set the video mode (640x480 at native depth) /
screen = SDL_AllocSurface(0,640, 480, 8, 0, 0, 0, 0);
if ( screen == NULL ) {
ComplainAndExit();
}
images = SDL_SetVideoMode(640, 480, 0, SDL_HWSURFACE|SDL_FULLSCREEN);
/
Set the video colormap /
if ( background->format->palette != NULL ) {
SDL_SetColors(screen,
background->format->palette->colors, 0,
background->format->palette->ncolors);
}
/
Draw bands of color on the raw surface /
if ( SDL_MUSTLOCK(screen) ) {
if ( SDL_LockSurface(screen) < 0 )
ComplainAndExit();
}
buffer=(Uint8 )screen->pixels;
for ( i=0; ih; ++i ) {
memset(buffer,(i
255)/screen->h,
screen->w
screen->format->BytesPerPixel);
buffer += screen->pitch;
}
if ( SDL_MUSTLOCK(screen) ) {
SDL_UnlockSurface(screen);
}

}

void hover::anim(void) // animation Loop
{
int GameOver;
cerr << “in anim Loop” << endl;

/* Convert the image to the video format (maps colors) */
cerr << “Die here? 1” << endl;
surface[sectorDisplay + 10] =
SDL_DisplayFormat(surface[sectorDisplay]);
cerr << “Die here? 2” << endl;
obstacles[sectorDisplay + 10] =
SDL_DisplayFormat(obstacles[sectorDisplay]);
cerr << “Die here? 3” << endl;
barrier[sectorDisplay + 10] =
SDL_DisplayFormat(barrier[sectorDisplay]);
cerr << “Die here? 4” << endl;
playerCar[1] = SDL_DisplayFormat(playerCar[0]);
cerr << “Die here? 5” << endl;
AICar[1] = SDL_DisplayFormat(AICar[0]);
cerr << “alive” << endl;
// Code to blit the background to the screen

// Blits Surface of terrain
surfrect.x = 0;
surfrect.y = 0;
surfrect.w = surface[sectorDisplay + 10]->w;
surfrect.h = surface[sectorDisplay + 10]->h;
cerr << “dead 0” << endl;
if ( SDL_BlitSurface(surface[sectorDisplay + 10], NULL, screen,
&surfrect) < 0 )
{
freeVidMem();
ComplainAndExit();
}
cerr << “dead .5” << endl;
SDL_FreeSurface(surface[sectorDisplay + 10]);
SDL_UpdateRects(screen, 1, &surfrect);

cerr << “dead one” << endl;

// Blits the barrier(s)
barrect.x = barrierX[sectorDisplay];
barrect.y = barrierY[sectorDisplay];
barrect.w = barrier[sectorDisplay + 10]->w;
barrect.h = barrier[sectorDisplay + 10]->h;
if ( SDL_BlitSurface(barrier[sectorDisplay + 10], NULL, screen,
&barrect) < 0 )
{
freeVidMem();
ComplainAndExit();
}

SDL_FreeSurface(barrier[sectorDisplay + 10]);
SDL_UpdateRects(screen, 1, &barrect);

// Blits obstacle(s) to the screen
obsrect.x = obstacleX[sectorDisplay];
obsrect.y = obstacleY[sectorDisplay];
obsrect.w = obstacles[sectorDisplay + 10]->w;
obsrect.h = obstacles[sectorDisplay + 10]->h;
if ( SDL_BlitSurface(obstacles[sectorDisplay + 10], NULL, screen,
&obsrect) < 0 )
{
freeVidMem();
ComplainAndExit();
}
SDL_FreeSurface(obstacles[sectorDisplay + 10]);
SDL_UpdateRects(screen, 1, &obsrect);

// Code to blit the Player Car(s) to the screen

plyrect.x = playerX;
plyrect.y = playerY;
plyrect.w = playerCar[1]->w;
plyrect.h = playerCar[1]->h;
if ( SDL_BlitSurface(playerCar[1], NULL, screen, &plyrect) < 0 )
{
ComplainAndExit();
}

// Update the screen 

SDL_FreeSurface(playerCar[1]);
SDL_UpdateRects(screen, 1, &plyrect);

// Code to blit the AI Car(s) to the screen.

AIrect.x = AIX;
AIrect.y = AIY;
AIrect.w = AICar[1]->w;
AIrect.h = AICar[1]->h;
if ( SDL_BlitSurface(AICar[1], NULL, screen, &AIrect) < 0 )
{
ComplainAndExit();
}

// Update the screen 

SDL_FreeSurface(AICar[1]);
SDL_UpdateRects(screen, 1, &AIrect);

cerr << “at image display” << endl;
img.x = 0;
img.y = 0;
img.w = screen->w;
img.h = screen->h;
cerr << “blitting!” << endl;
if ( SDL_BlitSurface(screen, NULL, images, &img) < 0 )
{
ComplainAndExit();
}
cerr << “not dead” << endl;

// SDL_FreeSurface(screen);
cerr << “still not dead” << endl;

SDL_UpdateRects(images,1,&img);
anim();
//exit(0);
}

Man I feel dumb not being able to figure this out :frowning:

Mike.

Sam Lantinga wrote:

void hover::initVideoDisplay(void) / initializes video display
{
/* Set the video mode (640x480 at native depth) /
screen = SDL_AllocSurface(0,640, 480, 8, 0, 0, 0, 0);
if ( screen == NULL ) {
ComplainAndExit();
}
images = SDL_SetVideoMode(640, 480, 0, SDL_HWSURFACE|SDL_FULLSCREEN);
/
Set the video colormap */
if ( background->format->palette != NULL ) {
SDL_SetColors(screen,
background->format->palette->colors, 0,
background->format->palette->ncolors);
}

Try:
screen = SDL_SetVideoMode() …
… blit into screen …
SDL_UpdateRects(screen, …)

    -Sam Lantinga                           (slouken at devolution.com)

Lead Programmer, Loki Entertainment Software

Author of Simple DirectMedia Layer -
http://www.devolution.com/~slouken/SDL/

Doesn’t that just make it so that it redaws everytime something is
blitted to it, instead of waiting for everything to blit then redraw the
screen?

Sam Lantinga wrote:

Try:
screen = SDL_SetVideoMode() …
… blit into screen …
SDL_UpdateRects(screen, …)

Doesn’t that just make it so that it redaws everytime something is
blitted to it, instead of waiting for everything to blit then redraw the
screen?

Rather:
screen = SDL_SetVideoMode() …
… wait for everything to blit
SDL_UpdateRects(screen, …) (redraw the screen)

Better? :slight_smile:
-Sam Lantinga (slouken at devolution.com)

Lead Programmer, Loki Entertainment Software

Author of Simple DirectMedia Layer -
http://www.devolution.com/~slouken/SDL/

Ok, i’ll try that, but one last ?. should I use the same SDL_Rect for
blitting each image on to screen?

Sam Lantinga wrote:

Ok, i’ll try that, but one last ?. should I use the same SDL_Rect for
blitting each image on to screen?

What do you mean, exactly?
Have you looked at the example code at all?

    -Sam Lantinga                           (slouken at devolution.com)

Lead Programmer, Loki Entertainment Software

Author of Simple DirectMedia Layer -
http://www.devolution.com/~slouken/SDL/

Thanks for the help. I finally figured it out, all is working smoothly,
except for a couple of other bugs in my code, oh well will work on those
later.

Mike.

void hover::initVideoDisplay(void) / initializes video display
{
/* Set the video mode (640x480 at native depth) /
screen = SDL_AllocSurface(0,640, 480, 8, 0, 0, 0, 0);
if ( screen == NULL ) {
ComplainAndExit();
}
images = SDL_SetVideoMode(640, 480, 0, SDL_HWSURFACE|SDL_FULLSCREEN);
/
Set the video colormap */
if ( background->format->palette != NULL ) {
SDL_SetColors(screen,
background->format->palette->colors, 0,
background->format->palette->ncolors);
}

Try:
screen = SDL_SetVideoMode() …
… blit into screen …
SDL_UpdateRects(screen, …)

-Sam Lantinga				(slouken at devolution.com)

Lead Programmer, Loki Entertainment Software–
Author of Simple DirectMedia Layer -
http://www.devolution.com/~slouken/SDL/

Try:
screen = SDL_SetVideoMode() …
… blit into screen …
SDL_UpdateRects(screen, …)

Doesn’t that just make it so that it redaws everytime something is
blitted to it, instead of waiting for everything to blit then redraw the
screen?

Rather:
screen = SDL_SetVideoMode() …
… wait for everything to blit
SDL_UpdateRects(screen, …) (redraw the screen)

Better? :slight_smile:
-Sam Lantinga (slouken at devolution.com)

Lead Programmer, Loki Entertainment Software–
Author of Simple DirectMedia Layer -
http://www.devolution.com/~slouken/SDL/