我有一个影响我的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上编译它不会导致这个故障。此外,在调整窗口大小后,黑色线条的数量和位置也会发生变化,从第二张和第三张图片中可以看出。
答案 0 :(得分:2)
这是关于最慢的可能方式将位图blit到帧缓冲区。至少将glBegin()/glEnd()
对移出for
- 循环!
尝试将位图上传到纹理并渲染视口大小的纹理四边形。