include gl glut include cmath GLUquadricObj theqw GLfloat lightpositio

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <gl/glut.h>
#include <cmath>
GLUquadricObj* theqw;
GLfloat lightposition[] = {13, 0, -5, 0};
void init() {
glClearColor(0.1, 0.98, 0.3, 1);
theqw = gluNewQuadric();
glEnable(GL_DEPTH_TEST);
glEnable(GL_COLOR_MATERIAL);
glLightfv(GL_LIGHT0, GL_POSITION, lightposition);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
}
double k = 1;
void Display() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glRotatef(1.0, 1.0, 1.0, 1.0);
glColor3f(0.5, 0, 0.1);
k += 0.01;
glutSolidTeapot(cos(k) + 0.5);
glutPostRedisplay();
glutSwapBuffers();
}
void main() {
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(480, 480);
glutInitWindowPosition(100, 100);
glutCreateWindow(" ");
init();
glutDisplayFunc(Display);
glutMainLoop();
}