Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

OpenGL 2d mouse in a 3d world

This topic is 5595 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''ve looked for quite a while and haven''t found how to load and display a mouse in opengl. I''ve done it in Allegro. Is there no feature for it in opengl? My projects are in full screen view. My project now consists of a bunch of 3d pyramids and a large grid. Is there anyway to display a mouse?

Share this post


Link to post
Share on other sites
Advertisement
what you have to do, is make yourself a fine looking mouse pointer, bmp tga, whatever, get GL to load that text, then make a quad, and make it place the enter of that quad at the mouse position... i aint no programmer, but i know thats how AdmiralBinary''s been doin it since he started GL.

Share this post


Link to post
Share on other sites
ok, so I''ve done all that. What I have now is a jpg file loaded where the mouse is. At first, the picture moved in opposite direction as the mouse. I fixed that, but even before I fixed it, I noticed that the picture had restrictions. Right now (following the mouse), it seems that the mouse can''t move past 0,0 going to the upper left or bottom left. I think the problem has to do with my directions. I had to create a 3d quad to put the mouse pic in. And when using the glVertex3f() function, I had to switch the Y and Z inputs so the picture faces the user (the camera is fixed to look from the top downwards at the ground. Anyone know how to fix this?

Share this post


Link to post
Share on other sites
to get the mouse to openGL 3d coordinates.

something like this:

void MouseTo3d2()
{
glFlush();
POINT pt;
GetCursorPos(&pt);

GLint viewport[4];
GLdouble mvmatrix[16], projmatrix[16];
GLint realy; // OpenGL y coordinate position
GLdouble wx2, wy2, wz2;
glGetIntegerv (GL_VIEWPORT, viewport);
glGetDoublev (GL_MODELVIEW_MATRIX, mvmatrix);
glGetDoublev (GL_PROJECTION_MATRIX, projmatrix);

// note viewport[3] is height of window in pixels

realy = viewport[3] - (GLint) mousey - 1;

//glReadPixels(mousex,realy,1,1,GL_DEPTH_COMPONENT, GL_FLOAT, &depth);
//gluUnProject ((GLdouble) mousex, (GLdouble) realy, 0.5f,
// mvmatrix, projmatrix, viewport, &wx, &wy, &wz);

gluUnProject ((GLdouble) mousex, (GLdouble) realy, depth,
mvmatrix, projmatrix, viewport, &wx2, &wy2, &wz2);


space_x = wx2;// + (factor_t * x_AB);
space_y = wy2;// + (factor_t * y_AB);
space_z = wz2;// + (factor_t * z_AB);

}

Share this post


Link to post
Share on other sites
ok, this is what I have, and now no mouse shows up. What do the functions glGetDoublev and glGetIntegerv do? I kinda skipped the space_x,y,z part, not sure what it did. mCurrent is declared as POINT mCurrent.

void DrawMouse()
{
glFlush();
GLint viewport[4];
GLdouble mvmatrix[16], projmatrix[16];
GLint realy;
GLdouble wx2, wy2, wz2;
glGetIntegerv (GL_VIEWPORT, viewport);
glGetDoublev (GL_MODELVIEW_MATRIX, mvmatrix);
glGetDoublev (GL_PROJECTION_MATRIX, projmatrix);

if ((GetCursorPos(&mCurrent)) != 0)
{
realy = viewport[3] - (GLint) mCurrent.y - 1;
glColor3ub(255, 255, 255);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, g_Texture[0]);

glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); //top left
glVertex2f((float)-mCurrent.x, (float)-realy);

glTexCoord2f(0.0f, 1.0f); //bottom left
glVertex2f((float)-mCurrent.x, (float)-realy - 3.0f);

glTexCoord2f(1.0f, 1.0f); //bottom right
glVertex2f((float)-mCurrent.x - 2.0f, (float)-realy - 3.0f);

glTexCoord2f(1.0f, 0.0f); //top right
glVertex2f((float)-mCurrent.x - 2.0f, (float)-realy);
glEnd();
gluUnProject ((GLdouble) mCurrent.x, (GLdouble) realy, 32/*depth*/, mvmatrix, projmatrix, viewport, &wx2, &wy2, &wz2);

glDisable(GL_TEXTURE_2D);
}
}

Share this post


Link to post
Share on other sites
I don''t know what GLUT is but I managed to hack away and get what I wanted ( think). At least it looks that way for now

thanks for all the help

-chris

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!