Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/163.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 是否可以在openGL的显示列表中执行for循环?_C++_Opengl - Fatal编程技术网

C++ 是否可以在openGL的显示列表中执行for循环?

C++ 是否可以在openGL的显示列表中执行for循环?,c++,opengl,C++,Opengl,我尝试使用对椭圆函数的多次调用创建一个模式,该函数绘制如下特征: glBegin(GL_LINE_LOOP); for(int i=0; i < 360; i++) { //convert degrees into radians float degInRad = i*DEG2RAD; glVertex2f(cos(degInRad)*xradius,sin(degInRad)*yradius); } glEnd()

我尝试使用对椭圆函数的多次调用创建一个模式,该函数绘制如下特征:

 glBegin(GL_LINE_LOOP);
    for(int i=0; i < 360; i++)
    {
        //convert degrees into radians
        float degInRad = i*DEG2RAD;
        glVertex2f(cos(degInRad)*xradius,sin(degInRad)*yradius);
    }
glEnd();

我做错了什么,还是显示列表中不允许使用for循环?

OpenGL显示列表不关心循环或任何其他编程结构。本质上,它们只是glNewList和glEndList之间按顺序调用的每个OpenGL函数的记录。这就好像你用一个打印到某种文件中的print语句包围了从gl开始的每个函数…(而且只有那些函数)。调用显示列表时,仅“播放”内容。构建显示列表时使用的任何循环都只与围绕printf调用进行循环一样有效–基本上效果相同


为什么你看不到性能上的差异?因为使用现代GPU,驱动程序必须将对glVertex及其朋友的调用(即时模式绘图调用)编译到命令缓冲区中,然后提交给GPU。这个命令缓冲区与显示列表本身没有太大区别。如果对glVertex的调用量增加,您将看到函数调用和内存分配开销的影响。试着用一些大数字替换360,比如1000000。

如果
drawerlipse()
索引通过值传递,那么
ellipseList
中的
ellipseList
应该如何更新?你的
glCallList()
呼叫在哪里?
void features::drawEllipse(float xradius, float yradius, GLuint index)
{
    glNewList(index, GL_COMPILE);
        glBegin(GL_LINE_LOOP);
        for(int i=0; i < 360; i++)
        {
            //convert degrees into radians
            float degInRad = i*DEG2RAD;
            glVertex2f(cos(degInRad)*xradius,sin(degInRad)*yradius);
        }
        glEnd();
    glEndList();
}
static GLuint ellipseList;
...
drawEllipse(0.2,0.3,ellipseList);