why won't the mouse move??
#include <allegro.h>
int main(){
allegro_init();
install_keyboard();
install_mouse();
set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0);
acquire_screen();
show_mouse(screen);
while ( !key[KEY_ESC] )
{
textout_ex( screen, font, "New Game", 0, 0, makecol( 0, 155, 0), makecol( 0, 0, 0) );
textout_ex( screen, font, "Load Game", 0, 10, makecol( 0, 155, 0),makecol(0, 0, 0) );
textout_ex( screen, font, "Options", 0, 20, makecol( 0, 155, 0), makecol(0,0,0) );
textout_ex( screen, font, "Quit", 0, 30, makecol(0, 155, 0), makecol(0, 0, 0) );
}
release_screen();
return 0;
}
END_OF_MAIN();
Throw out acquire_screen() and it will work.
thanks, i thought i need aquare screen so i can draw to the screen
also, the mouse goes under the text, i need it to overlap the text
Use a double buffer.
| 1 | #include <allegro.h> |
| 2 | |
| 3 | int main(){ |
| 4 | BITMAP *bmp; |
| 5 | allegro_init(); |
| 6 | install_keyboard(); |
| 7 | install_mouse(); |
| 8 | set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0); |
| 9 | |
| 10 | bmp = create_bitmap(640, 480); |
| 11 | while ( !key[KEY_ESC] ) { |
| 12 | clear_bitmap(bmp); |
| 13 | |
| 14 | textout_ex( bmp, font, "New Game", 0, 0, makecol( 0, 155, 0), makecol( 0, 0, 0) ); |
| 15 | textout_ex( bmp, font, "Load Game", 0, 10, makecol( 0, 155, 0),makecol(0, 0, 0) ); |
| 16 | textout_ex( bmp, font, "Options", 0, 20, makecol( 0, 155, 0), makecol(0,0,0) ); |
| 17 | textout_ex( bmp, font, "Quit", 0, 30, makecol(0, 155, 0), makecol(0, 0, 0) ); |
| 18 | |
| 19 | show_mouse(bmp); |
| 20 | blit(bmp, screen, 0, 0, 0, 0, 640, 480); |
| 21 | } |
| 22 | |
| 23 | show_mouse(NULL); |
| 24 | destroy_bitmap(bmp); |
| 25 | allegro_exit(); |
| 26 | return 0; |
| 27 | } |
| 28 | END_OF_MAIN() |
Try this code:
| 1 | #include <allegro.h> |
| 2 | |
| 3 | |
| 4 | int main(){ |
| 5 | |
| 6 | allegro_init(); |
| 7 | set_color_depth(desktop_color_depth()); |
| 8 | set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0); |
| 9 | install_keyboard(); |
| 10 | install_mouse(); |
| 11 | |
| 12 | BITMAP *canvas = create_bitmap(SCREEN_W, SCREEN_H); |
| 13 | |
| 14 | while ( !key[KEY_ESC] ) |
| 15 | { |
| 16 | clear_to_color(canvas, 0); |
| 17 | textout_ex( canvas, font, "New Game", 0, 0, makecol( 0, 155, 0), makecol( 0, 0, 0) ); |
| 18 | textout_ex( canvas, font, "Load Game", 0, 10, makecol( 0, 155, 0),makecol(0, 0, 0) ); |
| 19 | textout_ex( canvas, font, "Options", 0, 20, makecol( 0, 155, 0), makecol(0,0,0) ); |
| 20 | textout_ex( canvas, font, "Quit", 0, 30, makecol(0, 155, 0), makecol(0, 0, 0) ); |
| 21 | show_mouse(canvas); |
| 22 | blit(canvas, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); |
| 23 | } |
| 24 | show_mouse(0); |
| 25 | destroy_bitmap(canvas); |
| 26 | return 0; |
| 27 | } |
| 28 | END_OF_MAIN() |
EDIT: Göddämnít Rey, you type too fast.
And Money, begin adding checks. Your program may crash and you will never find out why.
new game doesn't get highlightsed
#include <allegro.h>
int main(){
BITMAP *bmp;
allegro_init();
install_keyboard();
install_mouse();
set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0);
bmp = create_bitmap(640, 480);
while ( !key[KEY_ESC] ) {
clear_bitmap(bmp);
textout_ex( bmp, font, "New Game", 0, 0, makecol( 0, 155, 0), makecol( 0, 0, 0) );
textout_ex( bmp, font, "Load Game", 0, 10, makecol( 0, 155, 0),makecol(0, 0, 0) );
textout_ex( bmp, font, "Options", 0, 20, makecol( 0, 155, 0), makecol(0,0,0) );
textout_ex( bmp, font, "Quit", 0, 30, makecol(0, 155, 0), makecol(0, 0, 0) );
show_mouse(bmp);
blit(bmp, screen, 0, 0, 0, 0, 640, 480);
if ( mouse_x >= 0 && mouse_x <= 50 && mouse_y >= 0 and mouse_y <= 20 )
{
textout_ex( bmp, font, "New Game", 0, 0, makecol( 0, 255, 0), makecol( 0, 0, 0) );
}
}
show_mouse(NULL);
destroy_bitmap(bmp);
allegro_exit();
return 0;
}
END_OF_MAIN()
Think a little bit about what your code does.
Hehehe
miran is right, you need to understand what you are writing. Note that you blit the bitmap on the screen and then highlight it. You should highlight it before blitting the bitmap on the screen.
Go one line at a time, understanding what each does.
ok, got it thanks
what does blitting a bitmap mean?
Blit is basically copying. You copy every pixel of a memory bitmap onto the screen so that you can see it. Until you blit the bitmap, you won't see anything you have drawn on that determined bitmap.
oh, ok, thNks
Blit stands for Block Image Transfer. In simple terms it means copying a bitmap somewhere. The blit() function copies (blits) one bitmap on top of another. In your code you should draw all your graphics to the canvas buffer and then copy (blit) it to the visible screen. What you actually did was draw some of the gfx to the canvas, copy it to the screen, then draw some more. Which is wrong.
EDIT: Yes, I type slower. Or maybe I just type more?
Also, don't forget to call install_timer() before you call install_mouse(). Allegro needs this if you want to display the pointer.
AE.
You don't need to call install_timer() first because the manual states that the install_mouse() function calls it if not installed. I do suggest the following order though:
allegro_init();
install_timer();
install_keyboard();
install_mouse();
set_color_depth(BPP);
set_gfx_mode(CARD,Width,Height,XWidth,XHeight);
set_color_conversion(COLORCONV_TOTAL);
I install timer before keyboard even, because the keyboard was an interrupt driven device...I don't beleive it matters with allegro, but I've stuck with this all the same.
Don: I believe that this can get you into trouble on some windows platforms, since the w32 port needs a window (created by set_gfx_mode()) to process the keyboard and mouse messages. I could be wrong though.
The proper order should be something like this:
allegro_init(); set_color_depth(BPP); set_gfx_mode(CARD,Width,Height,XWidth,XHeight); set_color_conversion(COLORCONV_TOTAL); install_keyboard(); install_mouse();
I believe that this can get you into trouble on some windows platforms, since the w32 port needs a window (created by set_gfx_mode()) to process the keyboard and mouse messages. I could be wrong though.
Allegro already creates a window before you call set_gfx_mode(). It's somewhere outside the desktop area of the viewport though, so you never get to see it.
That said, I think the Windows port delays the `real' initialisation of the keyboard and mouse code until after set_gfx_mode() is called. But calling the initialisation routines before then should be fine (I do it all the time and have never seen a problem myself).
It is fine to initialize them before the graphics mode is set, but you cannot use them until after.
The docs are quite clear on this, especially the example.