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