2010-09-19 111 views
1

我有一段很糟糕的時間試圖讓這些三角帶出現。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 

回答

2

設置你的顏色比純黑色的其他東西:

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