#include <glut.h>
int width = 1280;
int height = 800;
bool direction = true;
GLfloat sphereX = 0.0f;
void onInit(void) {
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
}
void onResize(int w, int h) {
glViewport(0, 0, w, h);
width = w;
height = h;
}
void onDisplay(void) {
glutPostRedisplay();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, (double)width / (double)height, 0.1f, 500.f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0f, -65.0f, 80.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f);
if (direction && sphereX >= 57.7f) direction = false;
else if (!direction && sphereX <= -57.7f) direction = true;
if (direction) sphereX += (GLfloat) 57.7 * 2 / 5 / 1300;
else sphereX -= (GLfloat) 57.7 * 2 / 5 / 1300;
glTranslatef(sphereX, 0.0f, 1.2f);
glColor3f(1.0f, 1.0f, 1.0f);
glutSolidSphere(1.2f, 50, 50);
glFlush();
}
int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH);
glutInitWindowPosition(185, 125);
glutInitWindowSize(width, height);
glutCreateWindow("Test");
glutDisplayFunc(onDisplay);
glutReshapeFunc(onResize);
onInit();
glutMainLoop();
return 0;
}