I seemed to have done something that nobody thought of…
I don’t think so, i don’t believe that any thought has not been
Using OpenGL (remember that OpenGL’s 0,0 is the middle of the screen by
default) I set the viewport up so it matches screen coordinates (0,0 is the
upper left corner), and then created a mouse cursor through OpenGL commands
instead of using the built in SDL cursor ( I wanted a RGBA blended mouse
I have made a similar OpenGL Cursor for a tiled landscape to scroll the
mousecursor over the tiles. The landscape is rotatable around every axis
and translatable in every direction, so i had to calculate the momentary
camera position into the cursor coordinates, if the camera has rotated,
a mousemove to the right will move the OpenGL cursor in another
direction than before the rotation. Also, a Zoom should change the
OpenGL cursor speed, or the mouse would move to fast when zoomed in.
The Problem with OpenGL and the mousecursor is, that mouse is 2D and
OpenGL 3D, but there are ways to deal with it:
- You can use the OpenGL Feedback mode, If you switch to this mode, the
Operations will not been drawn to the screen but the data is saved to an
array. This array is then passed back to you and you can evaluate it.
You can specify an area on your screen and the feedbackbuffer says if an
object is inside, or so. I don’t know exactly, I didn’t use it, i just
I thought about using this method, but i don’t like the idea of drawing
every scene twice, once on the screen and once in the feedback array, at
least not on every mousemove. So i used the other method:
- You know what you draw where in OpenGL, so you can calculate the
visible parts on your screen and you know the mouse position. if you
hide the SDL cursor, grab the input, use Relative MouseMove and then
move the OpenGL cursor on Mousemovement, you haven’t got to be too
exact, and you can scale your MouseSpeed. You can also correct the real
Mouse Position using SDL_WarpMouse but be careful, my experience was, if
i Warp the mouse with this function, this will also create a MOUSEMOTION
Event, so don’t warp the mouse simply on a mousemotionevent! It took me
a lot of time testing the behaviour of the mouse and adjusting the mouse
movement to the Scene but now i have a good looking cursor movement and
the cursor is in the OpenGL Scene.
Now here is what happens. If the view port is set to the same resolution as
the game’s resolution (both are 640x480) the mouse works fine (tracking
seems slower in Fullscreen), but if the viewport is not the same as the
games resolution (say 1024x764 window size, but the game is really 640x480)
the mouse is using the window coordinates not the games coordinates. The
comments I’ve recieved is like “The higher resolution I use, the more
sluggish the mouse becomes” .
What I’ve been doing so far is using the mouse’s absolute coordinates to set
the mouse pointer, however if you see how I explained this already, the
games resolution is NOT the same as the window resolution, which makes using
the absolute coordinates not a good idea.
So I have a few possible solutions to fix this, either 1: use relative
coordinates based on the games resolution or 2: divide the games coordinates
by the screen coordinates and multiply by the absolute coordinates or 3:
figure out how to increase the tracking rate of the mouse.
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
SDL is Great, isn’t it?
ZUKEN GmbH * Vattmannstr. 3 * D-33100 Paderborn * Germany
Phone: +49 (0) 52 51-150 600 * Fax: +49 (0) 52 51-150 700
******* http://www.zuken.com * mailto:Enno.Ostendorf at zuken.de *******
Enno Ostendorf * http://www.supersmart.de * mailto:no at supersmart.de
Download GPG public key: http://www.supersmart.de/nogpg.askey