【发布时间】:2012-03-11 14:09:40
【问题描述】:
我想知道是否可以在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();
我得到的是在中心画的一个圆圈,但我想获得它的互补......
【问题讨论】:
标签: opengl buffer geometry clipping