PDA

View Full Version : I need help with Allegro


naruto1327
07-24-2006, 01:51 AM
#include <allegro.h>
void increment_speed_counter();
volatile long speed_counter = 0;
int main(int argc, char *argv[])
{
allegro_init();
install_keyboard();
install_timer();
LOCK_VARIABLE(speed_counter);
LOCK_FUNCTION(increment_speed_counter);
install_int_ex(increment_speed_counter, BPS_TO_TIMER(60));
set_color_depth(16);
set_gfx_mode(GFX_AUTODETECT, 640,480,0,0);
BITMAP *my_pic;
my_pic = load_bitmap("image.bmp", NULL);
BITMAP *buffer;
buffer = create_bitmap(640,480);
int my_pic_x = 0;
int my_pic_y = 0;
while(!key[KEY_ESC])
{
while(speed_counter > 0)
{
if(key[KEY_RIGHT])
{
my_pic_x++;
}
else if(key[KEY_LEFT])
{
my_pic_x--;
}
else if(key[KEY_UP])
{
my_pic_y--;
}
else if(key[KEY_DOWN])
{
my_pic_y++;
}
speed_counter--;
}
draw_sprite(buffer, my_pic, my_pic_x, my_pic_y);
blit(buffer, screen, 0,0,0,0,640,480);
clear_bitmap(buffer);
}
destroy_bitmap(my_pic);
destroy_bitmap(buffer);
return 0;
}
END_OF_MAIN();
void increment_speed_counter()
{
speed_counter++;
}
END_OF_FUNCTION(increment_speed_counter);


This is the main.cpp file.
The file "image.bmp" DOES exist, but nothing shows up. Just blackness...

Whats wrong?

TwitcH
07-24-2006, 09:40 AM
Do you have the image.bmp in the same folder as the source code?

If you do, then maybe giving allegro a more specific path to use may help:


my_pic = load_bitmap("c:\image.bmp", NULL);

Just my guess, never actually worked with allegro before and dont know alot of C++ , but I know enough to read through a C++ program and tell what it does and to me the source looks fine.

naruto1327
07-26-2006, 12:00 AM
Yesh, they're both in the same folder:
D:\C++\main.cpp
D:\C++\image.bmp

Program works fine, but the image just doesn't appear.

Maybe it's something wrong with the image?

hamik
07-27-2006, 07:28 PM
#include <allegro.h>
void increment_speed_counter();
volatile long speed_counter = 0;
int main(int argc, char *argv[])
{
allegro_init();
install_keyboard();
install_timer();
LOCK_VARIABLE(speed_counter);
LOCK_FUNCTION(increment_speed_counter);
install_int_ex(increment_speed_counter, BPS_TO_TIMER(60));
set_color_depth(16);
set_gfx_mode(GFX_AUTODETECT, 640,480,0,0);
BITMAP *my_pic;
my_pic = load_bitmap("image.bmp", NULL);
BITMAP *buffer;
buffer = create_bitmap(640,480);
int my_pic_x = 0;
int my_pic_y = 0;
while(!key[KEY_ESC])
{
while(speed_counter > 0)
{
if(key[KEY_RIGHT])
{
my_pic_x++;
}
else if(key[KEY_LEFT])
{
my_pic_x--;
}
else if(key[KEY_UP])
{
my_pic_y--;
}
else if(key[KEY_DOWN])
{
my_pic_y++;
}
speed_counter--;
}
draw_sprite(buffer, my_pic, my_pic_x, my_pic_y);
blit(buffer, screen, 0,0,0,0,640,480);
clear_bitmap(buffer);
}
destroy_bitmap(my_pic);
destroy_bitmap(buffer);
return 0;
}
END_OF_MAIN();
void increment_speed_counter()
{
speed_counter++;
}
END_OF_FUNCTION(increment_speed_counter);


This is the main.cpp file.
The file "image.bmp" DOES exist, but nothing shows up. Just blackness...

Whats wrong?
I'am not quite sure about allegro since I haven't used it in a while, but I think the drawing and all should be done before searching for the input. Basically blitting before Pressing keys =).

naruto1327
07-30-2006, 08:44 PM
Actually this is an example program from one of the tutorial sites.

I'll try doing that.