如果我评论DrawGLScene()
,我会看到一个大的阴影三角形,如果我注释掉drawtri()
,我会看到一个方形纹理。但是我无法将两者结合起来 - 当两个func都被调用时,我只看到三角形 outline ,并且应用强红色滤镜渲染纹理。
可能是什么问题?
void DrawGLScene()
{
int x, y;
float float_x, float_y, float_xb, float_yb;
float x0=0,y0=0,x1=10,y1=10,z=-3;
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glEnable(GL_TEXTURE_2D);
glLoadIdentity(); // Reset The View
glTranslatef(0.0f,0.0f,-12.0f); // move 12 units into the screen.
glBindTexture(GL_TEXTURE_2D, texture[0]); // choose the texture to use.
glPolygonMode(GL_BACK, GL_FILL);
glPolygonMode(GL_FRONT, GL_LINE);
glBegin(GL_QUADS);
glTexCoord2f( 0,0);
glVertex3f( x0, y0, z );
glTexCoord2f( 0, 1 );
glVertex3f( x0, y1, z );
glTexCoord2f( 1, 1);
glVertex3f( x1, y1, z );
glTexCoord2f( 1, 0 );
glVertex3f( x1, y0,z );
glEnd();
glDisable(GL_TEXTURE_2D);
// since this is double buffered, swap the buffers to display what just got drawn.
// glutSwapBuffers();
}
void drawtri() {
glBegin(GL_TRIANGLES);
glColor3f(0.0f,0.0f,1.0f);
glVertex3f( 0.0f, 1.0f, 0.0f);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glEnd();
}
void zdisplay()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen and Depth Buffer
glLoadIdentity();
glTranslatef(0.0f,0.0f,-3.0f);
//drawtri();
DrawGLScene();
glutSwapBuffers();
}
答案 0 :(得分:0)
红色滤镜是由应用的颜色引起的:
glColor3f(0.0f,0.0f,1.0f);
在绘制四边形之前将颜色重置为白色:
glColor3f(1.0f,1.0f,1.0f);
概要是由以下规范引起的:
glPolygonMode(GL_FRONT, GL_LINE);
指定填充模式:
glPolygonMode(GL_FRONT, GL_FILL);
答案 1 :(得分:0)
调用这两个函数时,您是否按照代码显示的顺序调用方法?因为我怀疑订单是逆转的。如果我是对的,我认为你必须在绘制三角形时重置glPolygonMode。尝试在调用glBegin(GL_TRIANGLES)之前添加glPolygonMode(GL_FRONT_AND_BACK,GL_FILL)。