so the mouse pointer will not appear, i dont know how to get it to show up inside the window. the program works just fine, i just want the mouse to appear (if possible could i get a crosshair mouse?) IDE:Code::Blocks Compiler: GNU GPP
1 | #include <allegro.h> |
2 | using namespace std; |
3 | |
4 | int x[2] = {-1,-1}; |
5 | int y[2] = {-1,-1}; |
6 | int count=1; |
7 | int blue = makecol(0,0,255); |
8 | |
9 | void reset(){ |
10 | x[0] = -1; |
11 | x[1] = -1; |
12 | y[0] = -1; |
13 | y[1] = -1; |
14 | } |
15 | |
16 | void solidDraw(){ |
17 | if(count == 1){ |
18 | x[0]=mouse_x; |
19 | y[0]=mouse_y; |
20 | count++; |
21 | //break; |
22 | } |
23 | else if(count == 2){ |
24 | x[1]=mouse_x; |
25 | y[1]=mouse_y; |
26 | count--; |
27 | //break; |
28 | } |
29 | if(x[0]!=-1 && x[1]!=-1 && y[0]!=-1 && y[1]!=-1){ |
30 | line(screen,x[0],y[0],x[1],y[1],blue); |
31 | } |
32 | } |
33 | |
34 | void dotDraw(){ |
35 | putpixel(screen,mouse_x,mouse_y, blue); |
36 | } |
37 | |
38 | int main(){ |
39 | allegro_init(); |
40 | install_keyboard(); |
41 | install_timer(); |
42 | install_mouse(); |
43 | show_mouse(screen); |
44 | |
45 | |
46 | |
47 | set_color_depth(32); |
48 | set_gfx_mode(GFX_AUTODETECT_WINDOWED,800,640,0,0); |
49 | clear_to_color(screen,makecol(255,255,255)); |
50 | |
51 | do{ |
52 | if(mouse_b & 1){solidDraw();} |
53 | }while(!key[KEY_ESC]); |
54 | |
55 | allegro_exit(); |
56 | } |
57 | END_OF_MAIN(); |
You have to call show_mouse() after you set the video mode, not before. This is because at the moment you currently call show_mouse() the screen pointer is NULL.
--- Kris Asick (Gemini)
--- http://www.pixelships.com
[edit]
What he said.
Besides, you must hide the mouse pointer before doing any drawing. Use scare_mouse and unscare_mouse() to achieve this:
install_mouse(); set_color_depth(32); set_gfx_mode(GFX_AUTODETECT_WINDOWED,800,640,0,0); clear_to_color(screen,makecol(255,255,255)); show_mouse(screen); do{ scare_mouse(); if(mouse_b & 1){solidDraw();} unscare_mouse(); }while(!key[KEY_ESC]); allegro_exit();
thx guys