我有一个奇怪的错误影响了我的 GLUT 程序
void display(void) {
/* clear the screen to the clear colour */
glClear(GL_COLOR_BUFFER_BIT);
jVector** buff = antialias ? antialiasedBuffer : screen;
for (int y = 0; y < sceneModel.height(); ++y){
for (int x = 0; x < sceneModel.width(); ++x){
glBegin(GL_POINTS);
glColor3d(buff[x][y].x, buff[x][y].y, buff[x][y].z);
glVertex2f(x,y);
glEnd();
}
}
/* swap buffers */
glutSwapBuffers();
}
void reshape (int w, int h) {
/* set the viewport */
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
/* Matrix for projection transformation */
glMatrixMode (GL_PROJECTION);
/* replaces the current matrix with the identity matrix */
glLoadIdentity ();
/* Define a 2d orthographic projection matrix */
gluOrtho2D (0.0, (GLdouble) w, 0.0, (GLdouble) h);
}
int main(int argc, char** argv) {
// PROJECT CODE
sceneModel.generateProjectModel();
screen = rayTrace(sceneModel);
// OPENGL CODE
/* deal with any GLUT command Line options */
glutInit(&argc, argv);
/* create an output window */
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowSize(sceneModel.width(), sceneModel.height());
/* set the name of the window and try to create it */
glutCreateWindow("CS 488 - Project 3");
/* specify clear values for the color buffers */
glClearColor (0, 0, 0, 1.0);
/* Receive keyboard inputs */
glutKeyboardFunc (Keyboard);
/* assign the display function */
glutDisplayFunc(display);
/* assign the idle function */
glutIdleFunc(display);
/* sets the reshape callback for the current window */
glutReshapeFunc(reshape);
/* enters the GLUT event processing loop */
glutMainLoop();
return (EXIT_SUCCESS);
}
发生的情况是渲染图像显示了一些随机的垂直黑线。我可以向你保证缓冲区没有它们。这只发生在使用 GL_POINTS 绘图时,当我使用 GL_LINES 时,这些线不会出现。我还注意到在 Mac 上编译它不会导致这个故障。此外,在调整窗口大小后,黑线的数量和位置会发生变化,从第二张和第三张图像可以看出。