我想知道在OpenGL中是否有可能模拟通过钥匙孔观察的效果。
我已经绘制好了我的3D场景,但我想让除了一个中心圆之外的所有东西都变黑。
我尝试了这个解决方案,但它完全做相反的事情:
// here i draw my 3D scene
// Begin 2D orthographic mode
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
GLint viewport [4];
glGetIntegerv(GL_VIEWPORT, viewport);
gluOrtho2D(0, viewport[2], viewport[3], 0);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
// Here I draw a circle in the center of the screen
float radius=50;
glBegin(GL_TRIANGLE_FAN);
glVertex2f(x, y);
for( int n = 0; n <= 100; ++n )
{
float const t = 2*M_PI*(float)n/(float)100;
glVertex2f(x + sin(t)*r, y + cos(t)*r);
}
glEnd();
// end orthographic 2D mode
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
我得到的是一个在中心绘制的圆形,但我想要得到它的补集...
glVertex2f
以及其它相似函数都是即时模式。我强烈建议使用glVertexPointer
/glDrawArrays
/glDrawRangeElements
等替代它们。把glVertex2f
看作已经过时的古董,而将glVertexPointer
视为“老方法”(但并没有那么老)。 - Dietrich Epp