Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Mouse problem

This thread is locked; no one can reply to it. rss feed Print
Mouse problem
horizon981
Member #7,594
August 2006

This small program was meant to change the cursor as well as display its position and button status. The cursor changes, but no text is appearing anywhere- just a blank screen. Plese help

1#include <allegro.h>
2#include <string.h>
3 
4int main(void)
5{
6 allegro_init();
7 set_color_depth(24);
8 set_gfx_mode(GFX_AUTODETECT_WINDOWED, 648, 480, 0, 0);
9 install_mouse();
10 install_keyboard();
11 BITMAP *cursor = load_bitmap("cursor.bmp", 0);
12 set_mouse_sprite(cursor);
13 show_mouse(screen);
14
15 while(!key[KEY_ESC])
16 {
17 textprintf(screen,font,10,10,6,"Mouse :(%d,%d,%d)",mouse_x,mouse_y,mouse_z);
18 if(mouse_b & 1)
19 textprintf(screen,font,20,20,6,"Left Button pressed.");
20 if(mouse_b & 2)
21 textprintf(screen,font,20,20,6,"Right Button pressed.");
22 if(mouse_b & 3)
23 textprintf(screen,font,20,20,6,"Centre Button pressed.");
24 }
25
26 allegro_exit();
27 return 0;
28}
29END_OF_MAIN();

Kauhiz
Member #4,798
July 2004

Tried it, it works just fine for me. There's a bunch of stuff wrong with your code though.
First, what version of allegro are you using. You shouldn't be using textprintf anymore. Also, END_OF_MAIN(); is wrong. Drop the ; it's just END_OF_MAIN(). Next you should check the bitmap you're using, and AFAIK 24 is not a good color depth to use, but I might be wrong. Also, you're not destroying the bitmap once you're done. You needn't include string.h either.

---
It's Ridge Racer! RIIIIIDGE RAAAAACER!

Ceagon Xylas
Member #5,495
February 2005
avatar

set_gfx_mode(GFX_AUTODETECT_WINDOWED, 648, 480, 0, 0);
Odd resolution. Try 640x480, may be a little safer (definetly for full screen though.)

Quote:

You shouldn't be using textprintf anymore.

Why not? What should be used instead?

gnolam
Member #2,030
March 2002
avatar

horizon981 said:

The cursor changes, but no text is appearing anywhere- just a blank screen. Plese help

Use makecol() to acquire a proper text color.

Ceagon Xylas said:

Why not? What should be used instead?

void textprintf_ex(BITMAP *bmp, const FONT *f, int x, int y, int color, int bg, const char *fmt, ...);

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

Kauhiz
Member #4,798
July 2004

Seems I misread your question a bit. I thought the mouse wasn't showing up either. Well, the answer is what gnolam said, the text is drawn, but for me it was a dark blue font, so you're not seeing it because of the black background. Trytextprintf_ex(screen, font, 10, 10, makecol(255, 255, 255), -1, "Mouse :(%d,%d,%d)",mouse_x,mouse_y,mouse_z);

edit:
A bit off topic, but textprintf is a link to the manual in the code box, but textprintf_ex isn't. Fix it ML :P

---
It's Ridge Racer! RIIIIIDGE RAAAAACER!

Go to: