Hi
I have never had any problems with drawing in any of my games. Then on the
otherhand, most of them have been 3D OpenGL driven… But I remeber doing
some early games in 2D long back. But now when I sat down at work to greate
a simple 2D game to test a system we are developing I get SDL saying (when
using the draw_bmp function from the libsdl site) “BlitSurface error:
Surfaces must not be locked during blit”
Now, the thing is… I don’t lock ANY surface ANYWHERE… So whats wrong?
A glance at the code:
(mpSurface is a SDL_Surface in test_game. The system will then take that and
blit it to a surface called screen later on…)
I set the videomode to the following:
screen = SDL_SetVideoMode(800, 600, 32,
SDL_HWSURFACE|SDL_ANYFORMAT|SDL_DOUBLEBUF);
void TestGame::PlayRound()
{
int computer_hand = 0;
computer_hand = (rand()%3);
int human_hand = GetPlayerHand();
//cout << "Du har: ";
switch( human_hand )
{
case 0 : DisplayBmp(“stone.bmp”, 100, 100); break;
case 1 : DisplayBmp(“sic.bmp”, 100, 100); break;
case 2 : DisplayBmp(“bag.bmp”, 100, 100); break;
}
//cout << "Datorn har: ";
switch( computer_hand )
{
case 0 : DisplayBmp(“stone.bmp”, 200, 100); break;
case 1 : DisplayBmp(“sic.bmp”, 200, 100); break;
case 2 : DisplayBmp(“bag.bmp”, 200, 100); break;
}
if ( human_hand == computer_hand )
{
cout << “Draw…” << endl << endl;
}
else if ( human_hand == 0 && computer_hand != 2 )
{
cout << “You win!” << endl << endl;
}
else if ( human_hand == 1 && computer_hand != 0 )
{
cout << “You win!” << endl << endl;
}
else if ( human_hand == 2 && computer_hand != 1 )
{
cout << “You win!” << endl << endl;
}
else
{
cout << Computer wins!" << endl << endl;
}
}
void TestGame::DisplayBmp(char *pFileName, int posX, int posY)
{
SDL_Surface *image;
/* Load the BMP file into a surface */
image = SDL_LoadBMP(pFileName);
if (image == NULL)
{
fprintf(stderr, "Couldn't load %s: %s\n", pFileName,
SDL_GetError());
return;
}
/*
* Palettized screen modes will have a default palette (a standard
* 8*8*4 colour cube), but if the image is palettized as well we can
* use that palette for a nicer colour matching
*/
if (image->format->palette && mpSurface->format->palette)
{
SDL_SetColors(mpSurface, image->format->palette->colors, 0,
image->format->palette->ncolors);
}
/* Blit onto the screen surface */
if(SDL_BlitSurface(image, NULL, mpSurface, NULL) < 0)
fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
SDL_UpdateRect(mpSurface, 0, 0, image->w, image->h);
/* Free the allocated BMP surface */
SDL_FreeSurface(image);
}
Best regards
Daniel_________________________________________________________________
MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*.
http://join.msn.com/?page=features/virus