1

このコードを実行してメニューを使用すると、画面に図形が表示されない理由がわかりません。glCallLists 行を glu[insertshape] と同じパラメーターに置き換えると、完全に機能しますが、まったく同じコード行ですが、今回は表示リストを介して呼び出され、機能しません。

チェックするためにprintステートメントを使用したこともあり、コードは間違いなく実行されています

誰でも助けることができますか?

#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;
}
4

1 に答える 1