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 | |
4 | int 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 | } |
29 | END_OF_MAIN(); |
]]>
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.
set_gfx_mode(GFX_AUTODETECT_WINDOWED, 648, 480, 0, 0);
Odd resolution. Try 640x480, may be a little safer (definetly for full screen though.)
You shouldn't be using textprintf anymore.
Why not? What should be used instead?
]]>The cursor changes, but no text is appearing anywhere- just a blank screen. Plese help
Use makecol() to acquire a proper text color.
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, ...);
]]>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