Archived

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

mouse coords

This topic is 4943 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

Guest Anonymous Poster
I am glad you asked this question Tera_Dragon, as I have been beating my head against this wall for a few days now. All the tut''s I find out there dealing with mouse coords are for glut. >:/

If any of you peeps could lend a hand it would me much appreciated!

Thanks,
Daedalus

Share this post


Link to post
Share on other sites
It depends on what you are trying to achieve:
- to transform mouse coords into OpenGL coordinates, use gluUnProject (fully documented on the web).
- to check if your mouse is over an object, there are two solutions:
1) either you are in glOrtho mode with viewport coordinates corresponding to the screen coordinates: the windows mouse coordinates then corresponds to the OpenGL coordinates (fully documented on the web).
2) or you are in 3D. You need to enter the selection mode, redraw your scene and interpret the selection data returned by OpenGL (see NeHe lesson number 33).

Hope that helps.

Ghostly yours,
Red.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
This is where I seem to by having my troubles. I render everything else in projection mode and then when I want to render a GUI element, I do this:

glPushMatrix();
glOrtho(0, 640, 480, 0, 1, 20);
glViewport(0, 0, 640, 480);

Trying to get the object coords to correspond 1:1 with the pixels in the window. OpenGL still draws the object from the origen, not top left and 1 doesn''t mean 1 pixel, it means maybe 50 or 75 pixels.

So when I try this for testing for hits with a click or something like that, the mouse coordinates do not line up either. Any ideas?

-Daedalus

Share this post


Link to post
Share on other sites
quote:
Original post by Red Ghost

2) or you are in 3D. You need to enter the selection mode, redraw your scene and interpret the selection data returned by OpenGL (see NeHe lesson number 33).



lesson 33 is all about tga file loading...

____________________________________________________________
Programmers Resource Central

Share this post


Link to post
Share on other sites
@Tera_Dragon:
It is now numbered lesson 32 (I had dowloaded a while ago NeHe''s PDF where it was numbered 33). A synonym to selection method is picking method.

@Daedalus:
Your call to glViewport is what makes your code fail. There are already plentiful posts about switching between 2D and 3D under OpenGL (see http://www.gamedev.net/community/forums/topic.asp?topic_id=104791: it is even a sticky in the OpenGL Forum). Just copy and paste the code proposed by Dwarf_With_Axe and you will be all set to correctly map mouse and 2D screen coordinates.

Hope that helps.

Ghostly yours,
Red.

Share this post


Link to post
Share on other sites