Jump to content
  • Advertisement
Sign in to follow this  
SKATIN_HARD

displaying bitmap with sdl

This topic is 4666 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

I made a little hacked up window function to display a bitmap in sdl. The source is:
[sourcecpp]

int InitImages()  
      {
                     if (SDL_Init(SDL_INIT_VIDEO) != 0) {
	printf("Unable to initialize SDL: %s\n", SDL_GetError());
	return 1;
}
        SDL_Surface *screen;

screen = SDL_SetVideoMode(640, 480, 32,SDL_HWSURFACE|SDL_DOUBLEBUF);
if (screen == NULL) {
	printf("Unable to set video mode: %s\n", SDL_GetError());
	return 1;
}         
             // image stuff
                SDL_Surface *image;
               
        SDL_WM_SetCaption( "Starting", "Starting");
        SDL_ShowCursor(SDL_DISABLE);    
        image = SDL_LoadBMP("image/background.bmp");   
        
SDL_Rect src, dest;

src.x = 0;
src.y = 0;
src.w = image->w;
src.h = image->h;
dest.x = 100;
dest.y = 100;
dest.w = image->w;
dest.h = image->h;

SDL_BlitSurface(image, &src, screen, &dest);
        
} 
Now this code compiles and runs. I see the starting window then it goes to my game but the bitmap doesn't get displayed on the screen. Does anybody have a clue why? Thanks again.

Share this post


Link to post
Share on other sites
Advertisement
Always when you load bitmaps with sdl, check if they are ok.


SDL_Surface* image;
image = SDL_LoadBMP("background.bmp");

if(image == NULL) {
// image failed to load
cout << "unable to open file: background.bmp" << endl;
}



Cheers and good luck! [smile]

Share this post


Link to post
Share on other sites
you have to call SDL_Flip( screen );

so SDL will update the screen.

you may also need to add in a delayin there if your game would instantly overwrite the image

Share this post


Link to post
Share on other sites
I added in the SDL_Flip(); and the screen still comes up blank. The SDL window appears and it says Starting like it should but the bitmap does not get displayed. Dunno why.

Share this post


Link to post
Share on other sites
Quote:
Original post by SKATIN_HARD
I added in the SDL_Flip(); and the screen still comes up blank. The SDL window appears and it says Starting like it should but the bitmap does not get displayed. Dunno why.


post your code then. it should work...

Share this post


Link to post
Share on other sites
Ok. I have these 2 functions at the top:

int InitImages();
int SDL_Flip(SDL_Surface *screen);

Then the source for them:

[sourcecpp]

int InitImages()
{
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf("Unable to initialize SDL: %s\n", SDL_GetError());
return 1;
}
SDL_Surface *screen;

screen = SDL_SetVideoMode(640, 480, 32,SDL_HWSURFACE|SDL_DOUBLEBUF);
if (screen == NULL) {
printf("Unable to set video mode: %s\n", SDL_GetError());
return 1;
}
SDL_Surface *back;
SDL_Surface *image;
int xpos=0,ypos=0;


SDL_WM_SetCaption( "Starting Clone Pong", "Starting Clone Pong");
SDL_ShowCursor(SDL_DISABLE);
image = SDL_LoadBMP("image/background.bmp");

SDL_Rect src, dest;

src.x = 0;
src.y = 0;
src.w = image->w;
src.h = image->h;
dest.x = 100;
dest.y = 100;
dest.w = image->w;
dest.h = image->h;
SDL_BlitSurface(image, &src, screen, &dest);

}


Then below in main I have

[sourcecpp]
InitImages();
int SDL_Flip(SDL_Surface *screen);

wait(1);


I want the first sdl window to come up showing the bitmap....then have a pause then go to the main game window. Ideas and comments welcome. Thanks so much guys.

Share this post


Link to post
Share on other sites
Ok,
I may be looking at this wrong, but this is what I got. You want the bitmap "image" to show up? Is that right?


Try this for your SDL_Flip.




SDL_Flip(screen);



Again,
I may have just looked at your code wrong. I will look at it again though.



Chad.


EDIT: After looking at your code more, it seems like that is what you need. Just forget the int, and put
SDL_Flip(screen);

Share this post


Link to post
Share on other sites
Ok I switched that and my code compiled. But it didn't show the bitmap. I just got a blank sdl window with the right caption that said starting but no bitmap was displayed.

Share this post


Link to post
Share on other sites
I will kindly refer you to look at this thread for a great bunch of references/tutorials on SDL to help you understand what you are after and how you should go about it. [wink] Cone3D's tutorials are outdated, but they have a great beginning one that shows how to go about this, so look there.

Share this post


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

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!