问题描述
我通过绘制四边形来创建简单的渐变背景,如下所示:
I am creating a simple gradient background by drawing a quad as follows:
glMatrixMode GL.GL_PROJECTION
glLoadIdentity
glMatrixMode GL.GL_MODELVIEW
glLoadIdentity
***glPolygonMode GL_FRONT_AND_BACK, GL_LINE***
glDisable glcDepthTest
glBegin bmQuads
glColor4d 1, 0, 0, 1
glVertex2i -1, -1
glVertex2i 1, -1
glColor4d 0, 0, 1, 1
glVertex2i 1, 1
glVertex2i -1, 1
GL.glEnd
GL.glEnable glcDepthTest
然后,我设置我的查看矩阵并绘制我的3D场景.当(场景的)多边形模式设置为GL_FILL时,这可以按预期工作,但是当我(场景的)多边形模式设置为GL_LINE或GL_POINT时,背景四边形消失,并且背景绘制为 glClearColor .
I then set up my viewing matrices and draw my 3D scene. This works as expected when the polygon mode (of the scene) is set to GL_FILL, but when I set the polygon mode (of the scene) to GL_LINE or GL_POINT, the background quad disappears and the background is drawn as the color specified in glClearColor.
我尝试了几种不同的混合选项(包括完全禁用它),所以我认为问题不在于混合模式.
I have tried several different blending options (including disabling it altogether), so I don't think the problem is blend mode related.
将以下多边形模式添加到上述代码中即可解决此问题!
Adding the following polygon mode to above code solves this issue!
glPolygonMode GL_FRONT_AND_BACK,GL_LINE
推荐答案
在绘制背景多边形之前,您需要将GL_FILL的多边形模式压入堆栈,然后将其从堆栈中弹出.
You need to push the polygon mode of GL_FILL onto the stack before drawing your background polygon, then pop it back off the stack.
这篇关于某些多边形模式下OpenGL背景消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!