#include <allegro.h>
int distance( int x1, int y1, int x2, int y2 )
{
int sx = ABS( x2 - x1 ), sy = ABS( y2 - y1 );
return fixtoi( fhypot( itofix( sx ), itofix( sy ) ) );
}
int main()
{
int x, y, r, g, b;
BITMAP *bitmap, *behind, *buffer;
bool done = FALSE;
allegro_init();
install_keyboard();
install_timer();
install_mouse();
set_color_depth(16);
if(set_gfx_mode(GFX_AUTODETECT, 1024, 768, 0, 0) < 0)
{
set_color_depth(15);
if(set_gfx_mode(GFX_AUTODETECT, 1024, 768, 0, 0) < 0)
{
allegro_message("Unable to initialize graphics module\n %s\n", allegro_error);
return -1;
}
}
set_mouse_range(0, 0, SCREEN_W - 31, SCREEN_H - 31 );
buffer=create_bitmap( SCREEN_W, SCREEN_H );
bitmap=create_bitmap( 32, 32 );
behind=create_bitmap( 32, 32 );
clear_to_color( bitmap,makecol( 255, 0, 255 ) );
//fix up the buffer
for ( int i = 0; i < SCREEN_W; i++ )
{
for ( int j = 0; j < SCREEN_H; j++ )
{
if ( i > = 320 )
{
r = distance( 629, 469, i, j );
}
else
{
r = distance( 10, 10, i, j );
}
if ( i > = 320 )
{
g = distance( 629, 10, i, j );
}
else
{
g = distance( 10, 469, i, j );
}
b = distance( 320, 240, i, j );
if ( r > 255 ) r = 255;
if ( g > 255 ) g = 255;
if ( b > 255 ) b = 255;
putpixel( buffer, i, j, makecol( 255 - r, 255 - g, 255 - b ) );
}
}
circlefill(bitmap, 15, 15, 15, makecol(255,255,255));
circlefill(bitmap, 15, 15, 15, makecol(255,0,255));
while(!done)
{
acquire_screen();
x = mouse_x, y = mouse_y;
blit(buffer, behind, x, y, 0, 0, 32, 32);
draw_sprite(buffer, bitmap, x, y);
blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
blit(behind, buffer, 0, 0, x, y, 32, 32);
release_screen();
if(key[KEY_ESC] || (mouse_b & 1))
done = TRUE;
}
destroy_bitmap(bitmap);
destroy_bitmap(behind);
destroy_bitmap(buffer);
return 0;
}
END_OF_MAIN();
Various Allegro Issues
Hi, I was just following the examples and tutorials at AGDN.
The first two tuts went fine (hello world, and mouse). Well, I got to the third one: Bitmaps. I went through the tutorial and learned all the various stuff; then I went to compile and I got an enormous amount of errors, most being parser errors and `so-and-so' previously deifined here and `so-and-so' was not declared in this scope and ISO C++ forbids `realse_screen' with no type... Ugh.. it goes on and on, most being similar errors. I even tried copying and pasting the source from the tutorial and I got the exact same errors.
Here's the code:
For some reason, the code has two instances of "> =". Remove the space and it compiles fine. [smile]
Jesus saves ... the rest of you take 2d4 fire damage.
July 20, 2004 10:57 PM
dont feel stupid.
we all come across these problems every now and then
we all come across these problems every now and then
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement