Advertisement

drawing a mouse cursor

Started by April 02, 2005 07:09 PM
7 comments, last by markr 19 years, 5 months ago
Hi, I'm trying to draw a mouse cursor but it's turning out to be a bit trickier than I had anticipated. Right now I'm basically setting up orthographic projection with the size of the window, and then drawing the triangle. My code is below:

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0,800,0,600,-1,1);
	
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();

//draw the mouse
glBegin(GL_TRIANGLES);
	glColor4f(0.75,0.75,0.75,0.75);
     	glVertex3d(mouse_x,mouse_y,0);
     	glVertex3d(mouse_x,mouse_y-0.5f,0);
     	glVertex3d(mouse_x+0.5f,mouse_y,0);
glEnd();

glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();	
Is there something wrong with what I'm doing or could my problem be elsewhere? Thanks
What exactly is the problem?
Is the mouse showing up at all?
Is it in the wrong place?
Is it the wrong shape?

As far as I can see it looks okay...
Possibly the mouse coordinates are out?
Or your have textured enabled when your not using them?
Advertisement
Well, the other objects in the scene draw fine without the mouse, but once I try calling the function above I get a black screen. I don't use textures, are they enabled by default? I printed the mouse coordinates and they stay within the range 0-800 and 0-600, respectively.

Any other ideas? Does the order matter? I tried mouse first and scene first and neither worked...
actually where can i learn how to use mouse for opengl. Is there any tutorial for mouse or draw button for opengl.
Psychedelico,

Opengl handles graphics exclusively. You have to use functions supplied by your window manager (Windows, X) to get the mouse position, or alternatively use a wrapper such as SDL.
Psychedelico,

Opengl handles graphics exclusively. You have to use functions supplied by your window manager (Windows, X) to get the mouse position, or alternatively use a wrapper such as SDL.
Advertisement
At the end you're leaving glMatrixMode at GL_PROJECTION. Set it back to GL_MODELVIEW.
I think the problem lies in the coordinates you use with glVertex3d.
Since your screen coordinates varies from 0 to 800, an increment of 0.5 (which you use both on the X and on the Y axes) is not even a pixel.
Basically your mouse is drawn, but it's so small that you can't see it.
I agree - your geometry is too small for 800x600

But there are some other things to make sure:

- Make sure depth testing is off
- Make sure lighting is off
- Make sure culling is right for the polygon you're drawing
- Make sure blending is right

If in doubt, try drawing the mouse pointer as a point with GL_POINTS

Normally I'd render the pointer as the very last thing (because usually you want it to be on top). If you do this, you don't need to push or pop any matrixes, you can just reset them all again at the beginning of the next rendering.

Another entirely different option is to let the OS draw the cursor (in hardware if supported). However, I've seen some problems happen with that in Windows sometimes. It may vary depending on the user's settings and video driver.

Mark

This topic is closed to new replies.

Advertisement