This program I put together from the wiki gives accurate ev.mouse.dx, but the mouse runs into the edge of the screen and doesn't move past it. If I warped the mouse to the centre of the screen every frame, that might give me what I want, but doing so makes the ev.mouse.dx give me the mouse movement since the start of the program, so I've commented out the warp code. Is there a solution? Here's the code so it should be easy to test. You might have to change the font name or install a font.
Have a look at ex_warp_mouse. ex_warp_mouse works here (in Linux). If it doesn't work on another platform that's a bug which needs to be fixed.
after copying common.c into my compiler include directory, ex_warp_mouse.c compiles but crashes when I run it.
The program I wrote should be working. Does it work for other people? It compiles and runs for me, but the mouse warping doesn't work.
It works for me in Linux (after removing the font loading).
What I'm trying to achieve is a program that warps the mouse cursor to the centre of the screen every time the mouse moves, and prints to the screen how far the mouse has moved since the last redraw. so with the al_set_mouse_xy code enabled on the example program I wrote it works ok? Thanks. you might have to install a font and change the font name to that font to get the program to work, or find some other way of displaying the mouse mickeys.
I'm starting to think there's a mouse driver bug in my system, I'm using allegro 5.0.4 devpak with Orwell's dev-cpp 5.0.0.4 on windows 7 professional.
The help is much appreciated.
Maybe instead of checking the dx and dy parameters you can check the x and y parameters and calculate the change from where you warp the mouse?
The if the behaviour is inconsistent between operating systems (I'm not really sure what you are expecting and what you are getting, and what Elias is getting) then I guess it is still a bug that needs to be reported.
The problem with that is the mouse cursor still hits the edge of the screen, and what I need is unlimited mouse movement. Warping the cursor to the centre of the screen every frame - or every time the mouse changes position - will let me have unlimited mouse movement like in a first person shooter.
In an FPS, you can keep rotating left or right as much as you want, but I can't make that happen without getting the mouse to warp the the screen centre, while still getting accurate mouse mickeys from ev.mouse.dx
I'm running the program in fullscreen of course, and once I get the mouse code working well, I can, for the game menu, draw a custom cursor with primitives that keeps on the screen while the (hidden) real cursor is constantly being warped to the centre of the screen.
I've attached what I've done so far on the Allegro 5 program code as well as the Allegro 4.2 code and executable that I'm trying to port to fullscreen Allegro 5.
Warping the cursor to the centre of the screen every frame - or every time the mouse changes position - will let me have unlimited mouse movement like in a first person shooter.
Exactly.
In pseudo-code:
1) dx <- mouse.x - center_x
2) dy <- mouse.y - center_y
3) warp_mouse(center_x, center_y)
The problem is that warping the mouse to the centre of the screen on each mouse event somehow makes ev.mouse.dx give a number from -960 to 959 based on where the mouse is. The screen I'm using is 1920 pixels wide.
I think it's the mouse warp code that's the problem - it doesn't actually make the mouse cursor move, maybe it's because I'm using Windows 7 Pro, and Dev-c++ with the allegro 5.0.4 devpak.
You already posted about this, and I already gave a solution.
If it's not working then Windows is erroneously generating a mouse move event when you position the mouse. It doesn't happen on OS X, and apparently it doesn't happen on Linux.
Thanks for testing this on Linux and OSX. I hope someone can test this on Windows 7. Here's the code, the mouse cursor should stay in the centre of the screen. And the text on the screen should be small numbers reflecting how far the mouse has moved since the last mouse event.
http://www.1001freefonts.com/Pirulen.php
(copy Pirulen.ttf to the same directory as your executable).
I don't have any problems with event.mouse.dx or .dy on Vista at all :
Code used :
It prints out reasonable numbers for dx and dy, and the mouse x and y I tracked using dx and dy from EVENT_MOUSE_AXES and EVENT_MOUSE_WARPED matches the mouse x and y that EVENT_MOUSE_AXES reports.
Aside from that though, the bouncer doesn't follow the mouse worth shit (major display delays - could be stalled in al_wait_for_event somehow?), and I have no idea why. Couldn't figure it out in the other thread where this was happening either.
What if you don't use the WARP event? That shouldn't be necessary. As I understand it, it should work like this:
set mouse to 320,240; set x,y to 320,240
move mouse to 300,240
axes event: dx = -20; set x -= 20
set position to 320,240
warp event: dx = 20 (ignore)
move mouse to 300,240
axes event: dx = -20; set x -= 20
So after this, x should be 280.
If you have to listen to the warp event to achieve that, something is wrong.
Edgar's code works for me in windowed mode but not in fullscreen.
http://www.allegro.cc/forums/thread/608627/934943#target
This code works pretty well in windowed mode, but seems to only work on one mouse axis at a time - when x is 0, y is usually 2, and when y is 0, x is usually 2.
It doesn't work in fullscreen.
Matthew, I'm not sure what you mean by not using a warp event. Is there a way to move the mouse cursor in fullscreen without using a warp event?
I can confirm that al_set_mouse_xy(display , SCREEN_W/2 , SCREEN_H/2) does nothing in fullscreen in Vista using the default driver at 800 X 600.
I can also confirm that in the same mode that event.mouse.dx and event.mouse.dy from the EVENT_MOUSE_AXES event show the distance from the center of the screen and not the actual dx and dy of the last mouse move.
Thanks Edgar! I wish I knew enough about programming to help fix this 'bug'.
Unfortunately, my only programming experience is a few 3d programs in Turing, and some sine-wave programs and Lissajous curve generators in BASIC. I've learned the basics of the C language, but don't know how to use recursion or pointers.
Well, I don't see anything obviously wrong with set_mouse_xy (called by al_set_mouse_xy) or with al_win_mouse_handle_move (sends ALLEGRO_EVENT_MOUSE_AXES events). Any one else see any problems with them?
A5.1 SVN r15021 :
wmouse.c lines 146-178
wmouse.c 289-321
Maybe there's something wrong with the way wwindows.c's window_callback calls al_win_mouse_handle_move. I don't really know. Maybe I can look more tomorrow.
What does the if (!(win_disp->display.flags & ALLEGRO_FULLSCREEN)) { check do? Seems the mouse position deliberately is not altered in fullscreen.
Looking at older revisions, there used to be a huge "else" block for full screen.
OK that's good to know. Maybe in the next version of Allegro the else block can go back in?
It might not be needed. It looks like the mouse input code was simplified to use a different Windows API at some point.
Without that fullscreen check it seems to sort of work here. The pink bitmap doesn't display or displays corrupt though, for some reason (both OpenGL and D3D).
So it looks like this problem wont be fixed before the next version of Allegro. Should I close this thread? I'm grateful to the people who tested this.
I think it'll get fixed if the people who know the windows code figure out where the problem is.
OK I'll just wait for an Allegro devpak to come out with this problem fixed.
Have a good weekend folks!
Can anyone tell me if full screen (not full screen window) works for them in 5.1 svn on Windows? I haven't tested yet myself except Edgar's example where the
magenta square shows up blank or with a little corrupted data and the rest blank.
Downloading latest SVN now... Will build in a bit and then test again.
Edit
Nope - Revision 15053 still doesn't work. al_set_mouse_xy still doesn't do anything in fullscreen. MOUSE_AXES dx and dy are still screwed up, reporting the distance from the center of the screen except for occasionally being right???
Edit2
Well, if I enable the SetCursorPos call for full screen, it works for me. No corruption of the bouncer bitmap for me.
src/win/wmouse.c lines 172-174
Revision 15053 still doesn't work
I didn't commit anything yet.
Well, if I enable the SetCursorPos call for full screen, it works for me. No corruption of the bouncer bitmap for me.
Ok, it worked for me besides the bitmap corruption, so I'll commit it.