使用Opengl绘制超过50k球时如何提高速度

Nic*_*ick 2 c++ opengl geometry

现在,我用glutSolidSphere绘制了50k +球体的多个球体,速度极低.

有没有提高速度的方法或建议?

下面是我的代码......

void COpenGlWnd::OnPaint()
{
    CPaintDC dc(this);
    ::wglMakeCurrent(m_hDC, m_hRC);
    for(int k = 0; k < m_nCountZ; k++)
    {   
        for(int j = 0; j < m_nCountY; j ++)
        {   
            for(int i = 0; i < m_nCountX; i ++)
            {
            ::glPushMatrix();
            ........
            ::glutSolidSphere(Size[i][j][k], 36, 36);
            ........
            ::glPopMatrix();
            }
        }
    }
    ::SwapBuffers(m_hDC);
}
Run Code Online (Sandbox Code Playgroud)

有关更多信息:球体将始终位于特定位置,但用户可以使用鼠标旋转并从差异视图中查看所有球体.

And*_*nck 5

以下是一些建议:

  1. 创建包含球体的顶点缓冲区对象(VBO)并渲染它而不是使用glutSolidSphere.
  2. 查看实例化,即通过单个绘制调用绘制多个领域.

以下文章几乎完全符合您的要求:http://sol.gfxile.net/instancing.html