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
39
40
41
42
43
44
45
46
47
48
49
#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[0]);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-5, 1, -5, 5, 5, 16);
glMatrixMode(GL_MODELVIEW);
}
double k = 1;
void Display() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(0.5, 0, 0.1);
glPushMatrix();
glTranslated(-3, 1, -15);
glRotatef(90, 1.0, 1.0, 1.0);
k += 0.01;
glutSolidTeapot(cos(k) * 3);
glPopMatrix();
glutPostRedisplay();
glutSwapBuffers();
}
void main() {
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(480, 480);
glutInitWindowPosition(100, 100);
glutCreateWindow(" ");
init();
glutDisplayFunc(Display);
glutMainLoop();
}