How can I find the 2D bounding rect of some triangles?


I need to find the 2D screen bounding rectangle/extent of a group of triangles drawn in OpenGL. Previously, when I’ve written software renderers, I maintained both the 3D world coordinates AND the projected 2D screen coordinates for each vertex and from this I could calculate the bounding rect.

But OpenGL doesn’t give me that information. How can I (easily) find the projected 2D coordinates of a vertex?

Apologies for my noobish posting :stuck_out_tongue:

Well, I guess what you could do is retrieve the transformation matrices back from OpenGL.
I believe there is a glGet… function for it - but I’m not sure if it’s in the 1.0 spec, so you may not find it in the redbook/bluebook as they can be found on the site.

OpenGL does not give this info easily because it is mean to be calculated by the card, and GPU to CPU transfers kills performance.
But it is possible, try gluProject/gluUnproject :
Or even maybe then search for “feedback”.

Oh I forgot to mention: I’m constructing all my own matrices, including the camera and projection matrices, along with their inversed versions for the ray-picking system I’m using if that helps any.

I suppose I could calculate the projected coordinates for each point seperately, but that seems OTT…