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);
}
glEnable(GL_SCISSOR_TEST);
glScissor(x0, y0, x1 - x0, y1 - y0);
// DRAW NOW
glDisable(GL_SCISSOR_TEST);
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).]