Trying to display a bitmap

Hi guys,

I’m a newbie and I’m trying to Display a bitmap…

basically, my program calls an InitGame function from Main and then
enters a while loop (infinite right now…)

In the InitGame function, it sets up the display and opens the window
and then calls the ShowBMP function which was taken directly from the
samples on the SDL site…

Here is my InitGame code:

int InitGame(void)
{
if((SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO)) < 0)
{
fprintf(stderr, “SDL error: %s\n”, SDL_GetError());
return 0;
}

screen = SDL_SetVideoMode(640, 480, 16, SDL_HWSURFACE);

if(screen == NULL)
{
fprintf(stderr, “Video error: %s\n”, SDL_GetError());
exit(1);
}

SDL_WM_SetCaption(title_string, NULL);

ShowBMP("…/Images/station1.bmp", screen, 1, 1);
}

As I mentioned, ShowBMP is the sample code…
http://www.libsdl.org/intro/usingvideo.html

The problem is simple that all I get is a black box for a window… no
bitmap…

Any ideas what I missed? I am a fairly good OpenGL programmer via Xlib
but just getting started with SDL. (and I have years of C/C++
experience that seems to be useless now…)

Daniel

In article <3AD90B71.CED50506 at cfl.rr.com>, planetes at cfl.rr.com says…

I’m a newbie and I’m trying to Display a bitmap…
In the InitGame function, it sets up the display and opens the window
and then calls the ShowBMP function which was taken directly from the
samples on the SDL site…
As I mentioned, ShowBMP is the sample code…
http://www.libsdl.org/intro/usingvideo.html

ok. 

The problem is simple that all I get is a black box for a window… no
bitmap… Any ideas what I missed?

I am guessing that SDL_LoadBMP is failing in ShowBMP:

/* Load the BMP file into a surface */
image = SDL_LoadBMP(file);


Also be warned that ShowBMP doesn't free the BMP it loads. ShowBMP 

is for demonstration and not very well written at all.–
-dv

Thanks for the response :slight_smile:

Yes, I know it doesn’t do cleanup very well (at all)… I am the type of
programmer who learns best by hacking at sample code and tinkering with it…
It’s a one step at a time thing…

I did discover something:

some BMP’s display, others won’t… What’s interesting about your SDL_LoadBMP
idea is that if I wrap it in an if (and do an exit or something inside the
if) it never errors out, so it’s acting like the function is working…

Daniel

Daniel wrote:> In article <3AD90B71.CED50506 at cfl.rr.com>, @Daniel_Davis says…

I’m a newbie and I’m trying to Display a bitmap…
In the InitGame function, it sets up the display and opens the window
and then calls the ShowBMP function which was taken directly from the
samples on the SDL site…
As I mentioned, ShowBMP is the sample code…
http://www.libsdl.org/intro/usingvideo.html

    ok.

The problem is simple that all I get is a black box for a window… no
bitmap… Any ideas what I missed?

    I am guessing that SDL_LoadBMP is failing in ShowBMP:

    /* Load the BMP file into a surface */
    image = SDL_LoadBMP(file);

    Also be warned that ShowBMP doesn't free the BMP it loads. ShowBMP

is for demonstration and not very well written at all.


-dv

some BMP’s display, others won’t… What’s interesting about your
SDL_LoadBMP idea is that if I wrap it in an if (and do an exit or
something inside the if) it never errors out, so it’s acting like the
function is working

try checking the return value of SDL_BlitSurface.

If the blit is successful, it returns 0, otherwise it returns -1.

If either of the surfaces were in video memory, and the blit
returns -2, the video memory was lost, so it should be reloaded
with artwork and re-blitted.-- 

-dv

Hi guys,

I’m a newbie and I’m trying to Display a bitmap…

In the InitGame function, it sets up the display and opens the window
and then calls the ShowBMP function which was taken directly from the
samples on the SDL site…

Personally (and this is just me) if I were you I’d try using the actual
functions used inside ShowBMP instead of ShowBMP itself. It’s pretty straight
forward stuff, and shouldn’t give too much problem.

Here is my InitGame code:

screen = SDL_SetVideoMode(640, 480, 16, SDL_HWSURFACE);

Are you certian you are at 16 bpp? If not, you may wish to try a bpp setting of
`0’ (to take the current bpp).

Also, are you certain you want to use SDL_HWSURFACE here?

Check the function reference for SDL_SetVideoMode(…) here:
http://sdldoc.csn.ul.ie/sdlsetvideomode.php

The problem is simple that all I get is a black box for a window… no
bitmap…

some BMP’s display, others won’t… What’s interesting about your
SDL_LoadBMPidea is that if I wrap it in an if (and do an exit or something
inside the if) it never errors out, so it’s acting like the function is
working…

I could be totally misinterpreting this (if I am, someone please tell me) but
it seems like that SDL_HWSURFACE flag may or may not be giving you the color
palette you want for these.

Also, you might want to check to verify that the bitmaps you are loading aren’t
bigger than your display area. (I.e., verify this isn’t a clipping problem).

Other than that, I’m just grasping at straws…On Sat, 14 Apr 2001, you wrote:


Sam “Criswell” Hart <@Sam_Hart> AIM, Yahoo!:
Homepage: < http://www.geekcomix.com/snh/ >
PGP Info: < http://www.geekcomix.com/snh/contact/ >
Advogato: < http://advogato.org/person/criswell/ >