View Full Version : Clicking Objects in the gamewindow
03-01-2010, 11:47 AM
In all games your able to click on NPC's, Items, Players etc to either bring up a window or to pick up a something off the ground or to even attack. How is this done with OpenGL?
03-01-2010, 02:31 PM
I believe this is typically done without using any OpenGL. Most games probably cast a ray based on the position of the mouse on the screen and do an intersection test against the bounding volumes of pickable objects in the game. Did you need per-pixel picking accuracy?
03-01-2010, 03:22 PM
not really, sure I am just trying to figure out how this type of thing is done. I would like to move on from text based games to something more visual. An that type of thing comes with it
03-01-2010, 04:28 PM
Maybe you want to check out one of the following cross-platform libraries that are used to handle windows.
SDL at http://www.libsdl.org/
wxWidgets at http://www.wxwidgets.org/
OpenGL by itself does not provide any functionality for this purpose.
03-01-2010, 04:51 PM
Opengl is for display objects to the user. The best method for this is to have a scenegraph, that contains all the geometry of the objects you are displaying. Then when the user clicks on the screen, get the near and far points to create a ray, of which you project through your objects in memory, and test if it intersects with any of them.
Hope this helps
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.