Creating a Sphere (using osg::Geometry) in OpenSceneGraph

后端 未结 3 803
遥遥无期
遥遥无期 2021-02-05 20:40

I spent quite some time to get this working, but my Sphere just won\'t display.
Used the following code to make my function:
Creating a 3D sphere in Opengl using Visual

3条回答
  •  Happy的楠姐
    2021-02-05 20:46

    That code calls glutSolidSphere() to draw a sphere, but it doesn't make sense to call it if your application is not using GLUT to display a window with 3D context.

    There is another way to draw a sphere easily, which is by invoking gluSphere() (you probably have GLU installed):

    void gluSphere(GLUquadric* quad, GLdouble radius, GLint slices, GLint stacks);

    Parameters

    quad - Specifies the quadrics object (created with gluNewQuadric).

    radius - Specifies the radius of the sphere.

    slices - Specifies the number of subdivisions around the z axis (similar to lines of longitude).

    stacks - Specifies the number of subdivisions along the z axis (similar to lines of latitude).

    Usage:

    // If you also need to include glew.h, do it before glu.h
    #include 
    
    GLUquadric* _quadratic = gluNewQuadric();
    if (_quadratic == NULL)
    {
        std::cerr << "!!! Failed gluNewQuadric" << std::endl;
        return;
    }
    
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    
    glTranslatef(0.0, 0.0, -5.0);
    glColor3ub(255, 97, 3);
    gluSphere(_quadratic, 1.4f, 64, 64);
    
    glFlush();
    
    gluDeleteQuadric(_quadratic);
    

    It's probably wiser to move the gluNewQuadric() call to the constructor of your class since it needs to be allocated only once, and move the call to gluDeleteQuadric() to the destructor of the class.

提交回复
热议问题