0
我正在试图制作一个基本的动画,在窗口上有一个'飞艇'浮动。我曾尝试调整不同的教程和源代码,以帮助构建我的代码,以便在批评中轻松完成。我还在搞清楚。我的主要问题是为什么我的glutWireSphere不填充指定的颜色?只是轮廓可见。让我知道任何建议。代码如下。为什么我的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);
}
我想,和轮廓比用wireSphere更加微弱,仍然不能与颜色填充。任何其他想法?在其他情况下,我已经使用了glutSolidSphere并且它已被填充。 – user2196667 2013-03-22 09:00:27