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++ 显示列表中的GLU二次曲面?_C++_Opengl_Glut_Glu_Displaylist - Fatal编程技术网

C++ 显示列表中的GLU二次曲面?

C++ 显示列表中的GLU二次曲面?,c++,opengl,glut,glu,displaylist,C++,Opengl,Glut,Glu,Displaylist,我不知道为什么当我运行此代码并使用菜单时,我在屏幕上看不到任何形状。当我用glu[insertshape]和相同的参数替换glCallLists行时,它工作得很好,但代码行完全相同,但这次是通过显示列表调用的,不起作用 我甚至用打印语句来检查,代码肯定正在运行 有人能帮忙吗 #include <GL/freeglut.h> #include <GL/gl.h> #include <cstdio> GLUquadricObj* ptrSphere; GLUq

我不知道为什么当我运行此代码并使用菜单时,我在屏幕上看不到任何形状。当我用glu[insertshape]和相同的参数替换glCallLists行时,它工作得很好,但代码行完全相同,但这次是通过显示列表调用的,不起作用

我甚至用打印语句来检查,代码肯定正在运行

有人能帮忙吗

#include <GL/freeglut.h>
#include <GL/gl.h>
#include <cstdio>


GLUquadricObj* ptrSphere;
GLUquadricObj* ptrCylinder;
GLUquadricObj* ptrDisk;
GLUquadricObj* ptrPartDisk;

GLuint sphereListID;
GLuint cylinderListID;
GLuint diskListID;
GLuint partialDiskListID;

GLuint menuID;

GLuint currentListID;

void drawSphere()
{
    gluSphere(ptrSphere, 2, 25, 25);
    printf("sphere");
}

void drawCylinder()
{
    gluCylinder(ptrCylinder, 3, 3, 4, 25, 25);
    printf("cylinder");
}

void drawDisk()
{
    gluDisk(ptrDisk, 1.5, 3, 25, 25);
    printf("disk");
}

void drawPartDisk()
{
    gluPartialDisk(ptrPartDisk, 1.5, 3, 25, 25, 0, 90);
    printf("part disk");
}

void initQuadrics()
{
    ptrSphere = gluNewQuadric();
    gluQuadricDrawStyle(ptrSphere, GLU_LINE);
    ptrCylinder = gluNewQuadric();
    gluQuadricDrawStyle(ptrCylinder, GLU_LINE);
    ptrDisk = gluNewQuadric();
    gluQuadricDrawStyle(ptrDisk, GLU_LINE);
    ptrPartDisk = gluNewQuadric();
    gluQuadricDrawStyle(ptrPartDisk, GLU_LINE); 
}

void initLists()
{
    sphereListID = glGenLists(0);
    cylinderListID = glGenLists(0);
    diskListID = glGenLists(0);
    partialDiskListID = glGenLists(0);
    glNewList(sphereListID, GL_COMPILE);
        drawSphere();
    glEndList();
    glNewList(cylinderListID, GL_COMPILE);
        drawCylinder();
    glEndList();
    glNewList(diskListID, GL_COMPILE);
        drawDisk();
    glEndList();
    glNewList(partialDiskListID, GL_COMPILE);
        drawPartDisk();
    glEndList();
    currentListID = sphereListID;
}

void myMenu(int value)
{
    switch(value)
    {
        case(1):
        currentListID = sphereListID;
        break;
        case(2):
        currentListID = cylinderListID;
        break;
        case(3):
        currentListID = diskListID;
        break;
        case(4):
        currentListID = partialDiskListID;
        break;
    }
    glutPostRedisplay();
}

void initMenu()
{
    menuID = glutCreateMenu(myMenu);
    glutSetMenu(menuID);
    glutAddMenuEntry("Sphere", 1);
    glutAddMenuEntry("Cylinder", 2);
    glutAddMenuEntry("Disk", 3);
    glutAddMenuEntry("Partial Disk", 4);
    glutAttachMenu(GLUT_RIGHT_BUTTON);
}

void init()
{
    initQuadrics();
    initLists();
    initMenu();
}

void display()
{
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0);
    glClear(GL_COLOR_BUFFER_BIT);
    glCallList(currentListID);
    glutSwapBuffers();
}

void reshape(int w, int h)
{
    glViewport(0,0,w,h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-4.0,4.0,-4.0,4.0,-4.0,4.0);
}

int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE);
    glutInitWindowSize(500,500);
    glutInitWindowPosition(100,100);
    glutCreateWindow("OpenGL - First window demo");
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    init();
    glutMainLoop();
    return 0;
}

我不确定这是否是OPs计划中的唯一问题,但肯定是一个问题:

void initLists()
{
    sphereListID = glGenLists(0);
    cylinderListID = glGenLists(0);
    diskListID = glGenLists(0);
    partialDiskListID = glGenLists(0);
医生。当然,这一点非常明确:

glgenlist有一个参数range。它返回一个整数n,使得范围连续的空显示列表,名为n,n+1,创建n+范围-1。如果范围为0,如果没有范围连续名称组可用,或者如果生成任何错误,则不生成显示列表,并返回0

强调我的

因此,我建议:

使用glGenLists1而不是glGenLists0,或者甚至使用单个glGenLists4一次生成所有列表ID。 检查glGenLists的返回值是否不是0。 在切换到OpenGL 3+之前,我们使用显示列表来提高视觉模拟应用程序的性能。这非常好,我们甚至很难在OpenGL3+中使用缓冲区和着色器获得相同的性能


使用显示列表仍然适用于最近的专业昂贵图形卡。在价格便宜得多的消费者图形卡上,我们注意到传统代码的性能下降令人不满意,而当我们仅使用OpenGL 3+函数时,我们的性能相当。

我不确定这是否是OPs程序中的唯一问题,但肯定是一个问题:

void initLists()
{
    sphereListID = glGenLists(0);
    cylinderListID = glGenLists(0);
    diskListID = glGenLists(0);
    partialDiskListID = glGenLists(0);
医生。当然,这一点非常明确:

glgenlist有一个参数range。它返回一个整数n,使得范围连续的空显示列表,名为n,n+1,创建n+范围-1。如果范围为0,如果没有范围连续名称组可用,或者如果生成任何错误,则不生成显示列表,并返回0

强调我的

因此,我建议:

使用glGenLists1而不是glGenLists0,或者甚至使用单个glGenLists4一次生成所有列表ID。 检查glGenLists的返回值是否不是0。 在切换到OpenGL 3+之前,我们使用显示列表来提高视觉模拟应用程序的性能。这非常好,我们甚至很难在OpenGL3+中使用缓冲区和着色器获得相同的性能


使用显示列表仍然适用于最近的专业昂贵图形卡。在价格便宜得多的消费者图形卡上,我们注意到传统代码的性能下降令人不满意,而当我们仅使用OpenGL 3+函数时,我们获得了相当的性能。

@phantomheartsdev不客气。你介意吗?@phantomheartsdev不客气。你介意吗?