We are independent & ad-supported. We may earn a commission for purchases made through our links.
Advertiser Disclosure
Our website is an independent, advertising-supported platform. We provide our content free of charge to our readers, and to keep it that way, we rely on revenue generated through advertisements and affiliate partnerships. This means that when you click on certain links on our site and make a purchase, we may earn a commission. Learn more.
How We Make Money
We sustain our operations through affiliate commissions and advertising. If you click on an affiliate link and make a purchase, we may receive a commission from the merchant at no additional cost to you. We also display advertisements on our website, which help generate revenue to support our work and keep our content free for readers. Our editorial team operates independently of our advertising and affiliate partnerships to ensure that our content remains unbiased and focused on providing you with the best information and recommendations based on thorough research and honest evaluations. To remain transparent, we’ve provided a list of our current affiliate partners here.
Software

Our Promise to you

Founded in 2002, our company has been a trusted resource for readers seeking informative and engaging content. Our dedication to quality remains unwavering—and will never change. We follow a strict editorial policy, ensuring that our content is authored by highly qualified professionals and edited by subject matter experts. This guarantees that everything we publish is objective, accurate, and trustworthy.

Over the years, we've refined our approach to cover a wide range of topics, providing readers with reliable and practical advice to enhance their knowledge and skills. That's why millions of readers turn to us each year. Join us in celebrating the joy of learning, guided by standards you can trust.

What Is OpenGL® Picking?

By Eugene P.
Updated: May 16, 2024
Views: 6,759
Share

OpenGL® picking in computer programming is the process of determining what object within a three-dimensional (3D) scene is located at a given point on the screen once the scene is rendered. It also can refer to locating multiple objects at a point or inside a box. Most often, OpenGL® picking is used to determine what 3D object on the screen a user is attempting to select with a mouse cursor. While this operation might appear to be simple, there are several subtleties in how OpenGL® renders a scene that can make it fairly complex. Additionally, there are intrinsic glitches in certain graphics cards and drivers that can cause the OpenGL® picking function to fail and return false results.

When a user is looking at a 3D scene on a computer monitor, the resulting image is known as a rendering of the scene. The scene is actually stored in memory as a collection of primitive shapes or polygons, which themselves are just collections of 3D points within the space of the scene. The computer uses world coordinates, which are sometimes called absolute coordinates, to perform most basic functions that manipulate objects in the scene. In most applications, the user is able to maneuver the view of the scene to different angles so objects can be seen in different perspectives. The virtual location of the user within the scene is called the camera angle or camera position.

The complexity of OpenGL® picking comes from determining the location of the mouse on the two-dimensional (2D) screen from a possibly arbitrary position and angle within the scene, the camera position. Additionally, because the rendering from the perspective of the human viewer is really 2D, there is no way for the user to provide the depth of the mouse click inside of the scene. The OpenGL® picking function solves this complex problem in two ways.

The first is that, instead of performing a series of separate calculations to translate where the viewer is abstractly and then find an object in the rendering window, the function actually renders the scene as it does when normally working, with the exception that the rendering used for selection is not displayed, it is only used to calculate the correct positions of objects. The difference is that, instead of rendering the whole area that would be visible to the user, it only renders the area where the mouse is located. This means any objects rendered are technically at the point where the mouse pointer is located.

The second problem, namely having no way to indicate the depth of an area selected, is solved by returning all objects that are under the mouse coordinates in the scene. The OpenGL® picking function returns all of the objects in an array along with how far away they are from the viewer’s location. This allows a program to quickly find the closest object if desired.

One way to visualize OpenGL® picking is to imagine a line, sometimes referred to as a ray in 3D programming, moving from the location of the mouse pointer into the scene and away from the viewer’s location. Each object this ray touches is added to an array of objects, along with how far away it is from the viewer. This is a very simple explanation of how one form of OpenGL® picking works.

Another method of object picking in OpenGL® involves locating an object by color, and it can be considerably faster. This method renders the scene but, instead of applying lighting and texture to the objects, they are instead rendered with a single, simple color. Each object or group of objects has its own distinct color. The scene is only rendered in memory and not displayed, so this does not affect what the user sees. Instead of looking for 3D collisions between objects, the color at the position of the mouse cursor is returned instead, and that color will correlate to a specific object.

Share
EasyTechJunkie is dedicated to providing accurate and trustworthy information. We carefully select reputable sources and employ a rigorous fact-checking process to maintain the highest standards. To learn more about our commitment to accuracy, read our editorial process.
Discussion Comments
Share
https://www.easytechjunkie.com/what-is-opengl-picking.htm
Copy this link
EasyTechJunkie, in your inbox

Our latest articles, guides, and more, delivered daily.

EasyTechJunkie, in your inbox

Our latest articles, guides, and more, delivered daily.