-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
82 lines (66 loc) · 1.65 KB
/
main.c
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#ifdef __APPLE__
# include <GLUT/glut.h>
#else
# include <GL/glut.h>
#endif
#define TIMERMSECS 17.0f
static void drawGeometry(void);
static double theta = 0;
static void render(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(0.0f, 0.0f, 0.0f);
glLineWidth(4);
glCullFace(GL_FRONT);
glPolygonMode(GL_BACK, GL_LINE);
drawGeometry();
glColor3f(1.0f, 0.0f, 0.0f);
glCullFace(GL_BACK);
glPolygonMode(GL_FRONT, GL_FILL);
drawGeometry();
glColor3f(0.0f, 0.0f, 0.0f);
glLineWidth(1);
glCullFace(GL_BACK);
glPolygonMode(GL_FRONT, GL_LINE);
drawGeometry();
glutSwapBuffers();
}
static void drawGeometry(void) {
glPushMatrix();
glRotated(theta, 1, 0.5, 0);
glutSolidTorus(20, 100, 10, 30);
glPopMatrix();
}
static void update(int value) {
(void) value;
glutTimerFunc(TIMERMSECS, update, 0);
theta = theta + 1;
glutPostRedisplay();
}
static void init(void) {
glClearColor(0.5f, 0.5f, 0.5f, 0.0f);
//glOrtho(-200, 200, -150, 150, -200, 200);
glFrustum(-200, 200, -150, 150, 600, 1000);
glTranslatef(0, 0, -800);
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LINE_SMOOTH);
glEnable(GL_POLYGON_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
extern int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(400, 300);
glutCreateWindow("Hello World");
glutDisplayFunc(render);
glutTimerFunc(TIMERMSECS, update, 0);
init();
glutMainLoop();
return 0;
}