Old 07-24-2006, 02:51 AM   #1 (permalink)
Dante’s Inferno
 
naruto1327's Avatar
 
Join Date: May 2006
Location: OLD PROFILE. NEW: NOODLEPOWA
Posts: 608
Reputation: 10
Send a message via AIM to naruto1327 Send a message via MSN to naruto1327 Send a message via Yahoo to naruto1327
Default I need help with Allegro

Code:
#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?

Last edited by naruto1327; 07-24-2006 at 02:53 AM.
naruto1327 is offline  
Old 07-24-2006, 10:40 AM   #2 (permalink)
Banned
 
TwitcH's Avatar
 
Join Date: May 2006
Posts: 2,053
Reputation: 14
Default

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:

Code:
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.
TwitcH is offline  
Old 07-26-2006, 01:00 AM   #3 (permalink)
Dante’s Inferno
 
naruto1327's Avatar
 
Join Date: May 2006
Location: OLD PROFILE. NEW: NOODLEPOWA
Posts: 608
Reputation: 10
Send a message via AIM to naruto1327 Send a message via MSN to naruto1327 Send a message via Yahoo to naruto1327
Default

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?
naruto1327 is offline  
Old 07-27-2006, 08:28 PM   #4 (permalink)
Bongo Crazy Kong
 
Join Date: Jul 2006
Posts: 233
Reputation: 10
Default

Quote:
Originally Posted by naruto1327
Code:
#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 =).
hamik is offline  
Old 07-30-2006, 09:44 PM   #5 (permalink)
Dante’s Inferno
 
naruto1327's Avatar
 
Join Date: May 2006
Location: OLD PROFILE. NEW: NOODLEPOWA
Posts: 608
Reputation: 10
Send a message via AIM to naruto1327 Send a message via MSN to naruto1327 Send a message via Yahoo to naruto1327
Default

Actually this is an example program from one of the tutorial sites.

I'll try doing that.
naruto1327 is offline  
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 01:02 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.6.0
OnRPG, Copyright ©2003-2011, Game Entertainment Enterprises