allegro mouse distortion question

I am a complete Allegro newbie and I am trying to start making a simple Solitaire card game just to have some fun with Allegro. Anyway, I am having some troubles with the mouse cursor in Allegro. I have a simple program that just displays a screen with a black background and a green box. If I move the mouse cursor over the box the box gets erased by the mouse cursor, and turns black (which is the color of the area behind the box).

I was thinking that the problem was that I wasn't hiding the mouse cursor properly, but I think I am doing it correctly. Here is my code:

1#include <pc.h>
2#include <allegro.h>
3using namespace std;
5int main()
7 allegro_init();
8 set_color_depth(16);
9 set_gfx_mode (GFX_AUTODETECT, 640, 480, 0, 0);
10 install_timer();
11 install_mouse();
12 select_mouse_cursor(MOUSE_CURSOR_ARROW);
13 enable_hardware_cursor();
15 show_mouse (screen);
17 BITMAP* bmp = create_bitmap(640, 480);
18 clear_to_color (bmp, makecol16(0,0,0));
21 rectfill(bmp, 150, 400, 230, 450, makecol16(0,255,0));
22 show_mouse(0);
23 blit(bmp, screen, 0, 0, 0, 0, 640, 480);
24 show_mouse(screen);
26 sleep(5);

I am using the sleep function just to have the graphics run for a few seconds so I can test the mouse out. It's not necessary at all.

Kitty Cat

The mouse will be hidden automatically if it needs to be. Once you call show_mouse(screen); you can't call show_mouse again without losing the hardware cursor.


When I try it without the show_mouse(0) it makes it worse, and the mouse messes up even more.

Richard Phipps

Change the last part of your code to this:

show_mouse (screen);

BITMAP* bmp = create_bitmap(640, 480);
clear_to_color (bmp, makecol16(0,0,0));

rectfill(bmp, 150, 400, 230, 450, makecol16(0,255,0));

blit(bmp, screen, 0, 0, 0, 0, 640, 480);


#include <pc.h>

What compiler are you using?


I am using DJGPP.

Matthew Leverton

DJGPP doesn't work right under Windows XP.


I fixed the problem. I didn't know about the individual graphics drivers you could load up, only the GFX_AUTODETECT. I did some searching and found out about the selection of video drivers for each platform. I tried loading up the GFX_VESA1 driver and now the mouse corruption problem went away.

Matthew Leverton

You worked around the problem for your installation of XP on your hardware, which is far from fixing it. If you plan to let other people running Windows XP use your project, then you need to switch to a Windows compiler.

DOS applications can be coaxed to run on Windows XP, but usually not very well. They won't work at all on 64-bit versions.


I use DJGPP because my university computer science classes/professors use DJGPP actually.

Christopher Bludau

You should use Mingw.
It´s a windows compiler.

djgpp = gcc for dos
Mingw = gcc for windows

IIRC. So it won´t be much of a change, but your games will work correct under windows


my university computer science classes/professors use DJGPP

You sure that they're really professors, and not just some random guy with a fake beard?


Yeah, we haven't needed anything else really besides DJGPP. For instance, if you are doing data structures like trees, linked lists, basic AI stuff like searching through mazes, sorting, hash functions, etc, you don't need fancy graphics or capabilities.

Anyway, I took the time tonight to get MINGW installed, as I had some problems when I tried to get allegro working with it in the past. Well, I got Allegro successfully working with MINGW now so I will continue my solitaire game development using MINGW instead of djgpp.


I have a Windows related question. If I want to run a Windows based Allegro program on another computer, what do I need to do? Is the Allegro library statically linked into the program or do I need to include a DLL if I want to run the program on another PC?

Christopher Bludau

Depends on the way you compiled allegro.
I guess you compiled it the way you have to include the dll.
Which is the way to go, IMO.

If you make one change to your exefile, people only have to download the small exe file, because they already have the dll.

Otherwise your exe will be bigger and the people will redownload the dll (in the exe) everytime they download the exe.

Thread #586801. Printed from