OpenGL三角带查看问题

时间:2010-09-19 23:47:02

标签: opengl

我正在努力让这些三角形条带出现。

我哪里错了?

InitGL:

InitGL()
{

glEnable(GL_DEPTH_TEST);    // Enables Depth Testing
glDepthFunc(GL_LEQUAL);

glMatrixMode(GL_PROJECTION);    
glLoadIdentity();//
gluPerspective(45, //view angle
    WINDOW_WIDTH/WINDOW_HEIGHT, //aspect ratio
    1.0, //near clip
    2000.0);//far clip

glMatrixMode(GL_MODELVIEW);
glClearColor(0, 0, 0, 0);

}

和显示:

void display ( void )   // Create The Display Function
{
int height = sourceImage->nx;
int width = sourceImage->ny;

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glLoadIdentity();
glScalef(.005, .004, .005); //all vertices are in the range x[0,200], y[0,255], z[0,200]
glTranslatef(0, 0, -2); //so scale to put all vertices in the range [0,1] and move the z coord from [0,1] to the -z axis [-1,-2]
glColor3f(0, 0, 0);

glPushMatrix(); //save this view

float cell_height = 0;
for(float z = 0; z < width; z++)
{
    glBegin(GL_TRIANGLE_STRIP);
    for(float x = 0; x < height; x++)
    {
        cell_height = cellHeight(x, z);
        glVertex3f(x, cell_height, z);

        cell_height = cellHeight(x, z+1);
        glVertex3f(x, cell_height,(z+1));

        cell_height = cellHeight(x+1, z);
        glVertex3f(x+1, cell_height, z);

        cell_height = cellHeight(x+1, z+1);
        glVertex3f(x+1, cell_height, (z+1));
    }
    glEnd();
}
glPopMatrix(); //restore view

1 个答案:

答案 0 :(得分:2)

将您的颜色设置为纯黑色以外的颜色:

glColor3f(1.0f, 1.0f, 1.0f);