1

如果我注释掉DrawGLScene(),我会看到一个大的阴影三角形,如果我注释掉,drawtri()我会看到一个方形纹理。但我无法将两者结合起来——当两个函数都被调用时,我只看到三角形轮廓,并且纹理是使用强红色滤镜渲染的。

可能是什么问题呢?

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();
}
4

2 回答 2

0

在调用这两个函数时,您是否真的按照代码显示的顺序调用了这些方法?因为我怀疑顺序颠倒了。如果我是对的,我认为您必须在绘制三角形时重置 glPolygonMode。尝试在调用 glBegin(GL_TRIANGLES) 之前添加 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)。

于 2013-03-12T18:01:32.473 回答
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);
于 2013-03-12T17:56:22.940 回答