简体   繁体   English

如何在OpenGL中确定一个全窗口矩形

[英]How to determine a full-window rectangle in OpenGL

That's problem: I'm currently in OpenGL eye-space, now I want make a black rectangle to cover all window's area. 那是问题:我目前处于OpenGL眼睛空间,现在我想制作一个黑色矩形来覆盖所有窗口的区域。 How can I determine a exactly X, Y, Z position to do this? 如何确定准确的X,Y,Z位置?

Update Or can someone tell me how can I determine the X, Y (top-left) of window when we have a Z value? 更新或者有人可以告诉我,当我们有Z值时,如何确定窗口的X,Y(左上角)?

You can try to calculate a rectangle that fits the camera exactly and go from there. 您可以尝试计算一个完全适合相机的矩形并从那里开始。 To do that, you would need to take into account the projection matrix and calculate an inverse. 要做到这一点,您需要考虑投影矩阵并计算逆。

However, there is a simpler method. 但是,有一种更简单的方法。 All you have to do is to change the camera temporarily, so that you know exactly how to draw the rectangle. 您所要做的就是暂时更换相机,以便准确了解如何绘制矩形。 A simple enough camera is the default orthogonal camera, with simple limits(from -1 to 1). 一个简单的相机是默认的正交相机,具有简单的限制(从-1到1)。 The following does that: 以下是这样的:

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdendity();

glBegin(GL_QUAD);
glVertex2f(-1.f, -1.f);
glVertex2f(1.f, -1.f);
glVertex2f(1.f, 1.f);
glVertex2f(-1.f, 1.f);
glEnd();

glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM