为什么我的glutWireSphere没有填充颜色?

时间:2013-03-21 19:33:27

标签: opengl colors glut

我正在尝试制作一个基本的动画,窗口上有一个'blimp'浮动。我尝试过调整不同的教程和资源来帮助构建我的代码,以便在评论中轻松完成。我还在搞清楚。我的主要问题是为什么我的glutWireSphere没有用其指定的颜色填充?只是轮廓是可见的。让我知道任何建议。代码如下。

#include <stdlib.h> // need to include for non keywords like NULL
#include <GLUT/GLUT.h> // open gl wrapper class

GLfloat speedX = 0.01; // blimp's speed in x & y position
GLfloat speedY = 0.001;
GLfloat blimpX = 0.0; // blimp's (x,y) position
GLfloat blimpY = 0.0;
GLfloat blimpXMax, blimpXMin, blimpYMax, blimpYMin; // blimp's bounds

class Blimp {

    public:
    void draw(void);
};

void Blimp::draw(void)
{
    glPushMatrix();
        glColor3f(1.0,1.0,0.0);
        glutWireSphere(8, 25.0, 25.0);
        glPushMatrix();
        glTranslatef(-8, 0,0);
        glutWireSphere(6, 25, 25);
        glPopMatrix();
    glPopMatrix();
}


void display()
{

    glMatrixMode(GL_MODELVIEW);
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix(); // save modelview matrix
    Blimp blimp;
    glTranslatef(blimpX, blimpY, 0.0); // move blimp
    blimp.draw();
    glPopMatrix(); // restore modelview matrix
    glutSwapBuffers();

    // compute location for next refresh
    blimpX += speedX;
    blimpY += speedY;

    //check if blimp exceeds edges: return on other side
    if (blimpX > blimpXMax + 14) {
        blimpX = blimpXMin - 14;
    } else if (blimpX < blimpXMin - 14) {
        blimpX = blimpXMax + 14;
    }
    /*  
    // check if blimp exceeds edges: bounce back other direction
    if (blimpX > blimpXMax) {
        blimpX = blimpXMax;
        speedX = -speedX;
    }   else if (blimpX < blimpXMin) {
        blimpX = blimpXMin;
        speedX = -speedX;
    }
     */

    if (blimpY > blimpYMax) {
        blimpY = blimpYMax;
        speedY = -speedY;
    }   else if (blimpY < blimpYMin){
        blimpY = blimpYMin;
        speedY = -speedY;
    }


}


void reshape(int w, int h)
{
    glViewport (0, 0, (GLsizei) w, (GLsizei) h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0);
    blimpXMin = -50.0 + 14;
    blimpXMax = 50 - 8;
    blimpYMin = 25;
    blimpYMax = 50 - 8;

}

int main(int argc, char** argv)
{

    glutInit(&argc, argv);
    glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE);
    glutInitWindowSize (500, 500);
    glutInitWindowPosition (100, 100);
    glutCreateWindow (argv[0]);
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutIdleFunc(display);
    glutMainLoop();
    return(0);
}

1 个答案:

答案 0 :(得分:4)

glutWireSphere绘制线框球体。你想要glutSolidSphere

请参阅:http://www.opengl.org/documentation/specs/glut/spec3/node81.html