1

我在 winform 上测试 SharpGL 示例,它在 openGLDraw 事件上呈现三角形。但是当我试图用按钮渲染它时,它不起作用。它不应该在 openGLDraw 事件之外呈现吗?以下是代码:

private void DrawScene()
{
    OpenGL gl = openGLControl.OpenGL;
    gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
    gl.LoadIdentity();
    gl.Begin(OpenGL.GL_TRIANGLES);
    gl.Color(1.0f, 0.0f, 0.0f);
    gl.Vertex(0.0f, 1.0f, 0.0f);
    gl.Color(0.0f, 1.0f, 0.0f);
    gl.Vertex(-1.0f, -1.0f, 1.0f);
    gl.Color(0.0f, 0.0f, 1.0f);
    gl.Vertex(1.0f, -1.0f, 1.0f);
    gl.Color(1.0f, 0.0f, 0.0f);
    gl.Vertex(0.0f, 1.0f, 0.0f);
    gl.Color(0.0f, 0.0f, 1.0f);
    gl.Vertex(1.0f, -1.0f, 1.0f);
    gl.Color(0.0f, 1.0f, 0.0f);
    gl.Vertex(1.0f, -1.0f, -1.0f);
    gl.Color(1.0f, 0.0f, 0.0f);
    gl.Vertex(0.0f, 1.0f, 0.0f);
    gl.Color(0.0f, 1.0f, 0.0f);
    gl.Vertex(1.0f, -1.0f, -1.0f);
    gl.Color(0.0f, 0.0f, 1.0f);
    gl.Vertex(-1.0f, -1.0f, -1.0f);
    gl.Color(1.0f, 0.0f, 0.0f);
    gl.Vertex(0.0f, 1.0f, 0.0f);
    gl.Color(0.0f, 0.0f, 1.0f);
    gl.Vertex(-1.0f, -1.0f, -1.0f);
    gl.Color(0.0f, 1.0f, 0.0f);
    gl.Vertex(-1.0f, -1.0f, 1.0f);
    gl.End();
}

private void openGLControl_OpenGLDraw(object sender, RenderEventArgs e)
{
    //this.DrawScene(); //Working
}

private void button1_Click(object sender, EventArgs e)
{
    this.DrawScene(); //Not working
}
4

1 回答 1

0

只需添加 openGLControl.Refresh(); 在 DrawScene() 之后。过去几天一直在愚弄我。我是在阅读他们的源代码后发现的。:D

private void button1_Click(object sender, EventArgs e)
{
    this.DrawScene(); //Not working
    openGLControl.Refresh(); 
}
于 2017-07-29T00:40:29.587 回答