My First post

Hi all,

I started OpenGL recently. I managed to create a window and render a triangle inside it and also rotate it based on a timer.
I was trying to find a command that retrieves the current position and orientation of a given polygon.
Like i assign a ID to each polygon i create and then based on that ID i can query information about that polygon. Can any1 plz guide me how to do it?

Regards,
Rohith H N

One little tip for future posts: put a summary of your problem in the subject. You’ll get more responses.

Well when you say “retrieve the current position and orientation of a given polygon” you need to state what coordinate space you want it in to have a properly defined question. I’ll presume window-space for now.

I’m also presuming you’re leaving the coordinates you provide to OpenGL (via glVertex, glVertexPointer, or whatever) the same and using glRotate to rotate the object.

In that case, the object-space position of your polygons (i.e. the coordinates you are providing OpenGL) are constant, but the window-space position of your polygons (i.e. those coordinates after being multiplied by the OpenGL MODELVIEW matrix, the PROJECTION matrix, and the VIEWING transform) are changing. And that you want to know what the window-space position of your polygon vertices are. Right?

If so, then the short answer is you “can” get the GPU to do what you ask (i.e. give you back where it transformed the vertices), but you’re probably not ready for that yet. Get a little more familiar with basic GPU programming first. In simplest use, you send the GPU “draw commands”, it draws your polygons, and then promptly tosses the details you gave it. So after it’s done, it doesn’t know anymore! :slight_smile:

So for now what I suggest you do is, right after you render your polygons (i.e. right after glEnd or a glDraw* call, depending on how you’re drawing), use gluProject to transform some of your object-space vertices into window-space. This gives you what you want, but just does it on the CPU instead of the GPU.

To call this function, you’re going to need the current MODELVIEW, PROJECTION and VIEWING transforms. Here’s some code that shows you exactly how to do that. Just call gluProject at the end instead of gluUnProject.