Jump to content
  • Advertisement
Sign in to follow this  
Thors1982

OpenGL how do you tell where things are in glutMouseFunc

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

hey, I am just starting to use OpenGL and I am trying to click on a triangle and move it around the screen. I think I have to use glutMouseFunc() but how do you know where the triangles are, you can't pass the coordinates into the function. I could use global, but from all my C++ classes we learned that global=bad... so what is the best way to go about doing this.

Share this post


Link to post
Share on other sites
Advertisement
globals aren't always bad...like a global class the encapsulates your scene...

If you put a triangle in a scene class, then have one instance of your scene, you can pass that scene the mouse coordinates of where you clicked, and use that to determine if you clicked on a triangle or not.

One thing to note is that the glutMouseFunc returns coordinates in pixel space (i.e. in the range of the size of your window) while the triangle may be drawn in any arbirary world space coordinate system (i.e. between 0 and 2 if that's how you set up your camera).

If you don't understand the last paragraph, then you need to read more about how OpenGL coordinates and camera system work. You can also use glOrtho and set the camera coodinates to match the window coordinates.

Share this post


Link to post
Share on other sites
a possible way to find out what is under the mouses cursor is using the selection buffer in opengl, check out glut or www.opengl.org for examples

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!