Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » MSVC8 Bitmaps

Credits go to CGamesPlay for helping out!
This thread is locked; no one can reply to it. rss feed Print
MSVC8 Bitmaps
xinco1
Member #8,061
December 2006

Ok, I'm currently moving from Dev-c++ to MS Visual C++ 2005 express edition. I've got it set up, with the microsoft platform SDK, and then followed this to install allegro:
http://wiki.allegro.cc/VisualCExpress2005
Anyway, I've got allegro sorted ok but when I declare a bitmap pointer using:

BITMAP *a = load_bitmap( "a.bmp", NULL);

This gives the error "This application has requested the runtime to terminate it in an unusual way."
Please help...

CGamesPlay
Member #2,559
July 2002
avatar

You need to check your return values:

BITMAP *a = load_bitmap( "a.bmp", NULL);
if(!a)
{
    set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
    allegro_message("Bitmap failed to load!");
    exit(1);
}

Once you do that, put a.bmp into the Debug or Release folder of your project directory.

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

xinco1
Member #8,061
December 2006

Ok, this is weird but it says
"syntax error : 'if'
syntax error : missing ';' before '{'
'{' : missing function header (old-style formal list?)"
Thats only shown on the code you just posted.

CGamesPlay
Member #2,559
July 2002
avatar

Oh, of course. You can't load a bitmap on the global scope, you have to do it inside of a function. The reason is because allegro_init hasn't been called yet on the global scope, nor has set_color_depth or set_gfx_mode. So:

1BITMAP* a = NULL;
2 
3int main(int argc, char* argv[])
4{
5 allegro_init();
6 set_color_depth(32);
7 set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
8 
9 a = load_bitmap( "a.bmp", NULL);
10 if(!a)
11 {
12 set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
13 allegro_message("Bitmap failed to load!");
14 return 1;
15 }
16
17 destroy_bitmap(a);
18 return 0;
19}

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Paul whoknows
Member #5,081
September 2004
avatar

Quote:

Ok, I'm currently moving from Dev-c++ to MS Visual C++ 2005 express edition.

Why?

____

"The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner.

CGamesPlay
Member #2,559
July 2002
avatar

Because Dev-C++ is a bad IDE, MSVS has a great debugger, and it's free?

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

xinco1
Member #8,061
December 2006

Quote:

Oh, of course. You can't load a bitmap on the global scope, you have to do it inside of a function. The reason is because allegro_init hasn't been called yet on the global scope, nor has set_color_depth or set_gfx_mode. So:
BITMAP* a = NULL;

int main(int argc, char* argv[])
{
allegro_init();
set_color_depth(32);
set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);

a = load_bitmap( "a.bmp", NULL);
if(!a)
{
set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
allegro_message("Bitmap failed to load!");
return 1;
}

destroy_bitmap(a);
return 0;
}

I can't belive I missed that. Thanks! BTW: MSVS IS free but requires registration. It's more stable, easier to use(for example on really long peices of code, voids can be minimized) and the debugger really is supreme.

BAF
Member #2,981
December 2002
avatar

It requires registration? I never had to register for my copies...

Go to: