problem with gluProject

my problem is i can’t really get bounding rectangle for polygon i want to render
i thought i would use gluProject in the way that i call gluProject for every vertex of polygon and update my bounding rectangle on the screen every time
problem is when come relatively close to that polygon, then result vert of gluProject is usually out of range (>32 bit i guess), because it’s projected onto the screen plane

actually what i want is to apply scissor test for that polygon’s bounding rectangle (i mean bounding rectangle cut to screen sizes)
so finally how to simply determine bounding rectangle of polygon on the screen (using gluProject?)?

thx for reply

Post your glProject code for a vertex and let’s see. I can’t think of any reason why glProject should give you that error.

PS Just curious, why would you want a scissors test linked to your image sizes?

here’s my code (num is id of face for which i want to find scissor box)

i need it for displaying mirrors (optimizing) for both reasons:

1st - cutting all faces which aren’t within mirror face as there’s no point to draw something that’s not visible

2nd - clearing z-buffer after mirror is done to avoid wrong result of drawing faces in space in which they’re not in fact (reflected faces) - it’s much better to clear only in scissor box rather than clear whole screen’s z-buffer

GLint viewport[4];
GLdouble mvmatrix[16], projmatrix[16];
GLdouble x, y, z;
GLdouble x0, y0;
GLdouble x1, y1;

glGetIntegerv (GL_VIEWPORT, viewport);
glGetDoublev (GL_MODELVIEW_MATRIX, mvmatrix);
glGetDoublev (GL_PROJECTION_MATRIX, projmatrix);

x1 = screen.glLeft;
y1 = screen.glBottom;
x0 = screen.glLeft + screen.glWidth;
y0 = screen.glBottom + screen.glHeight;

for (i = 0; i < 3; i++)
if (gluProject(
(GLdouble) map.verts[ map.faces[num].first + i ].pos[0],
(GLdouble) map.verts[ map.faces[num].first + i ].pos[1],
(GLdouble) map.verts[ map.faces[num].first + i ].pos[2],
mvmatrix, projmatrix, viewport, &x, &y, &z))
x0 = min(x0, x);
y0 = min(y0, y);
x1 = max(x1, x);
y1 = max(y1, y);

  x0 = max(x0, screen.glLeft);
  y0 = max(y0, screen.glBottom);
  x1 = min(x1, screen.glLeft + screen.glWidth);
  y1 = min(y1, screen.glBottom + screen.glHeight);


glScissor(x0, y0, x1 - x0, y1 - y0);



anyway i think it’s clear why i get wrong results(hope so) - when you’re VERY close to face so that you don’t see any of it’s vertices imagine what would be screen coordinates for these verts after projection (very, very big)

not quite sure though

[This message has been edited by MickeyMouse (edited 04-15-2002).]