PDA

View Full Version : 2d coordinate output of visible polygons



hereiam
08-05-2010, 02:44 AM
Hi there,

I'm a absoulte beginner of programming with OpenGL. Well everytime it's the same thing. If I want to draw some 3D shapes, the 3D coordnates have to be transformed to 2D coordniates that they can be displayed, I think.

So is it possible to get the 2D coordinates of rendered 3D shapes from OpenGL API? Well I only want use the visible shapes.

regards

hereiam

Rosario Leonardi
08-05-2010, 04:41 AM
If you are using the standard transofrmation (no strange vertex shaders) you can use gluProject.
You need to supply the point, the modelView matrix the proejection matrix and the viewport.

You should know all these information, if you don't you can use glGet to retrieve them.

hereiam
08-05-2010, 05:23 AM
Thank you for your help.

Here is a little sample why I asked that. For example, I want to draw two cuboids like in the attached image.

http://analyseandbet.de/opengl/cuboids_red.png

Will I get back the only visible shape of the backwards cuboid (marked as solid red border) or the coordinates of the whole front (solid red border + dotted red border) if I would calculate window coordinations from object coordinations?

ZbuffeR
08-05-2010, 06:46 AM
Taking in account the occlusion done thanks to depth test can only be done on pixels, not actual geometry if that is what you need.
For example gluProject will give you 2D result of each 3D vertex you pass, completely ignoring occlusion.

I only want use the visible shapes.
Can you explain more what you want to do with that ? There may be different ways to do it.

hereiam
08-05-2010, 07:18 AM
Ok, If I set a shape I have to set corners that it can be drawn for sure. So I think if I check these corners if they are visible or not I can decide if a area of a shape is visible.

What I want to do is the following. At first I want calculate the coordinations of a 3D shape with opengl. Then I want draw these single points another engine to use them out of opengl. These engines will be 2D engines. So I only want to draw things which a user can see and so I want to find out which areas of a shape is not visible. Because of this I think the draw process will be faster.

Rosario Leonardi
08-05-2010, 01:03 PM
Think it twice before writing the word "faster" in a openGL forum :P
Optimization is a matter of design, if at the end of the implementation you see that the program have low performance or the design was wrong or you code is wrong and you can try to optimize.
To make a good design you must know your bottleneck.

Now, you have a GPU, nowadays GPU are 8 to 20 times faster then the CPU, your design plan to remove work from the GPU (rendering) and give it to the CPU (gluProject). Maybe it's not a wise choice.