0

私の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);
}

What happens is that the rendered image shows some random vertical black lines. I can assure you that the buffer doesn't have them. And this only happens using the GL_POINTS drawing, when i use GL_LINES these lines don't show up. I also noticed that compiling it on a mac doesn't lead to this glitch. Also, after resizing the window, the number and the position of the black lines change, as it can be seen from the second and third images.

画像1 画像2 ウィンドウのサイズを変更した後の画像 2

4

1 に答える 1

2

これは、ビットマップをフレームバッファにブリットする最も遅い方法です。少なくともglBegin()/glEnd()ペアをループの外に移動してくださいfor!

代わりに、ビットマップをテクスチャにアップロードして、ビューポート サイズのテクスチャ付きクワッドをレンダリングしてみてください。

于 2012-12-07T21:03:42.363 に答える