0

我有一个程序可以画一条线,如下所示。

private void glControl1_Paint(object sender, PaintEventArgs e)
    {
        GL.glClear(GL.GL_DEPTH_BUFFER_BIT | GL.GL_COLOR_BUFFER_BIT);

        GL.glMatrixMode(GL.GL_MODELVIEW);
        GL.glLoadIdentity();
        GL.glColor(Color.Yellow);

        GL.glBegin(GL.GL_LINES);
        GL.glVertex3f(100.0f, 100.0f, 0.0f); // origin of the line
        GL.glVertex3f(200.0f, 140.0f, 5.0f); // ending point of the line
        GL.glEnd();

        glControl1.SwapBuffers();
    }

上面的方法在 Paint 事件期间被调用。

但我有另一种方法,如下所示:

    private void glControl1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
    {
            GL.glClear(GL.GL_DEPTH_BUFFER_BIT | GL.GL_COLOR_BUFFER_BIT);
            GL.glMatrixMode(GL.GL_MODELVIEW);
            GL.glLoadIdentity();
            GL.glColor(Color.Yellow);

            GL.glBegin(GL.GL_LINES);
            GL.glVertex3f(100.0f, 100.0f, 0.0f); // origin of the FIRST line
            GL.glVertex3f(200.0f, 140.0f, 5.0f); // ending point of the FIRST line
            GL.glVertex3f(120.0f, 170.0f, 10.0f); // origin of the SECOND line
            GL.glVertex3f(240.0f, 120.0f, 5.0f); // ending point of the SECOND line
            GL.glEnd();
    }

我想用这种方法画一些东西,但是没有用。

怎么了。

谢谢

4

1 回答 1

1

您应该调用glControl1.SwapBuffers(); 在您的 Paint 事件结束时完成所有绘图。

SwapBuffers 会将当前缓冲区呈现到屏幕上。通常你有两个缓冲区在渲染循环中一直在切换。你可以清除它调用

GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

第二种方法的作用是在 Paint 循环之外进行绘画。您要么需要在该事件中使用 SwapBuffers,要么将您的绘图排队并在您的绘画事件中处理队列。

根据您的绘图代码的复杂程度,引入“场景”的概念可能是合适的,该概念包含要在每次绘制调用时绘制的所有对象。

于 2013-12-10T11:49:54.957 回答