Jump to content
  • Advertisement
Sign in to follow this  
Aeroman

Trouble with SDL bmp's...

This topic is 2149 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, I'm not really new to game development in general- mostly the programming behind it. Anyway I'm having trouble loading more than 1 image and using getmousestate-but mostly just displaying multiple images. Here I'll post my code:
[source lang="cpp"]#ifdef __cplusplus
#include <cstdlib>
#else
#include <stdlib.h>
#endif
#ifdef __APPLE__
#include <SDL/SDL.h>
#else
#include <SDL.h>
#endif

int main ( int argc, char** argv )
{

if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
printf( "Unable to init SDL: %s\n", SDL_GetError() );
return 1;
}


atexit(SDL_Quit);


SDL_Surface* screen = SDL_SetVideoMode(1300, 630, 16,
SDL_HWSURFACE|SDL_DOUBLEBUF);
if ( !screen )
{
printf("Unable to set 640x480 video: %s\n", SDL_GetError());
return 1;
}
SDL_WM_SetCaption("Z Soft", NULL);

// load an image
SDL_Surface* bmp = SDL_LoadBMP("TaskBar.bmp");
if (!bmp)
{
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}


SDL_Rect dstrect;
dstrect.x = (screen->w - bmp->w) / 2;
dstrect.y = (screen->h - bmp->h) / 14;
//This does what?

SDL_Surface*PBP = SDL_LoadBMP("PageButtonPressed.bmp");
if (!PBP)
{
printf("Unable to perform that action. This situation sucks for you...%s\n", SDL_GetError());
return 1;
}
SDL_Rect dstrectPBP;
dstrectPBP.x = (screen->w - PBP->w) / 2;
dstrectPBP.y = (screen->h - PBP->h) / 2;
// program main loop
bool done = false;
while (!done)
{
// message processing loop
SDL_Event event;
while (SDL_PollEvent(&event))
{
// check for messages
switch (event.type)
{
// exit if the window is closed
case SDL_QUIT:
done = true;
break;

// check for keypresses
case SDL_KEYDOWN:
{
// exit if ESCAPE is pressed
if (event.key.keysym.sym == SDLK_ESCAPE)
done = true;
break;
if (event.key.keysym.sym == SDLK_UP)
SDL_Surface*PBP = SDL_LoadBMP("PageButtonPressed.bmp");
if (!PBP)
{
printf("Unable to perform that action. This situation sucks for you...%s\n", SDL_GetError());
return 1;
}
SDL_Rect dstrectPBP;
dstrectPBP.x = (screen->w - PBP->w) / 2;
dstrectPBP.y = (screen->h - PBP->h) / 2;
break;
}
} // end switch
} // end of message processing



// clear screen
SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));

// draw bitmap
SDL_BlitSurface(bmp, 0, screen, &dstrect);

// DRAWING ENDS HERE


SDL_Flip(screen);
} // end main loop

// free loaded bitmap
SDL_FreeSurface(bmp);


printf("Finally you closed it!\n");
return 0;
}
[/source]
So can anyone help to pinpoint the problem?

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!