-
Notifications
You must be signed in to change notification settings - Fork 0
/
glutapp.c
159 lines (129 loc) · 3 KB
/
glutapp.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
** OpenGL Demo: GLUT Skeleton Code
** Author: Michael Papasimeon (mikepsn)
** Date: February 2001
*/
#include <stdlib.h>
#ifdef __APPLE__
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <GLUT/glut.h>
#else
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#endif
#ifdef WIN32
#endif
#ifdef __linux__
#endif
// FUNCTION PROTOTYPES
static void display(void);
static void idle(void);
static void reshape(int width, int height);
static void key(unsigned char key, int x, int y);
//static void special_key(int key, int x, int y);
static void init(int argc, char** argv);
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitWindowSize(640, 480);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Skeleton GLUT Application - mikepsn");
init(argc, argv);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(key);
glutIdleFunc(idle);
glutMainLoop();
return 0;
}
static void init(int argc, char** argv)
{
glClearDepth(1.0);
glClearColor(0.5, 0.5, 0.5, 0.5);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
}
static void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -10.0f);
glRotatef(-70.0, 1.0, 0.0, 0.0);
glRotatef(-30.0, 0.0, 0.0, 1.0);
// DRAW SCENE HERE
glColor3f(0.0, 1.0, 0.0);
glBegin(GL_LINE_LOOP);
glVertex3i(0, 0, 0);
glVertex3i(1, 0, 0);
glVertex3i(1, 1, 0);
glVertex3i(0, 1, 0);
glVertex3i(0, 0, 0);
glEnd();
glColor3f(1.0, 0.0, 0.0);
glRectf(0.01, 0.01, 0.99, 0.99);
glPushMatrix();
glTranslatef(0.0, 0.0, 0.0);
glColor3f(0.35, 0.35, 0.35);
glBegin(GL_LINES);
for (int x = -10; x <= 10; x++)
{
glVertex3f((float)x, -10.0, 0.0);
glVertex3f((float)x, 10.0, 0.0);
}
glEnd();
glBegin(GL_LINES);
for (int y = -10; y <= 10; y++)
{
glVertex3f(-10.0, (float)y, 0.0);
glVertex3f( 10.0, (float)y, 0.0);
}
glEnd();
glPopMatrix();
// draw axes
glPushMatrix();
glLineWidth(2.0);
glColor3f(0.0, 0.0, 0.0);
glBegin(GL_LINES);
glVertex3i(-10, 0, 0);
glVertex3i( 10, 0, 0);
glEnd();
glBegin(GL_LINES);
glVertex3i(0, -10, 0);
glVertex3i(0, 10, 0);
glEnd();
glBegin(GL_LINES);
glVertex3i(0, 0, -10);
glVertex3i(0, 0, 10);
glEnd();
glLineWidth(1.0);
glPopMatrix();
glutSwapBuffers();
}
static void reshape(int width, int height)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(40.0, 4.0/3.0, 1.0, 100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0f, 0.0f, -10.0f,
0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f);
glViewport(0, 0, (GLint) width, (GLint) height);
}
static void key(unsigned char key, int x, int y)
{
switch (key)
{
case 27: // Escape key
exit (0);
break;
}
glutPostRedisplay();
}
static void idle(void)
{
glutPostRedisplay();
}