This repository has been archived by the owner on Jul 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
cube.cpp
63 lines (58 loc) · 1.59 KB
/
cube.cpp
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
#include "main.h"
// TODO turn this into a special objects section
float cube_angle = 0.0f;
void draw_cube() {
glRotatef( cube_angle, 1.0f, 0.0f, 0.0f );
if( ++cube_angle > 360.0f ) {
cube_angle = 0.0f;
}
GLfloat cube[] = {
// FRONT
-0.5f, -0.5f, 0.5f,
0.5f, -0.5f, 0.5f,
-0.5f, 0.5f, 0.5f,
0.5f, 0.5f, 0.5f,
// BACK
-0.5f, -0.5f, -0.5f,
-0.5f, 0.5f, -0.5f,
0.5f, -0.5f, -0.5f,
0.5f, 0.5f, -0.5f,
// LEFT
-0.5f, -0.5f, 0.5f,
-0.5f, 0.5f, 0.5f,
-0.5f, -0.5f, -0.5f,
-0.5f, 0.5f, -0.5f,
// RIGHT
0.5f, -0.5f, -0.5f,
0.5f, 0.5f, -0.5f,
0.5f, -0.5f, 0.5f,
0.5f, 0.5f, 0.5f,
// TOP
-0.5f, 0.5f, 0.5f,
0.5f, 0.5f, 0.5f,
-0.5f, 0.5f, -0.5f,
0.5f, 0.5f, -0.5f,
// BOTTOM
-0.5f, -0.5f, 0.5f,
-0.5f, -0.5f, -0.5f,
0.5f, -0.5f, 0.5f,
0.5f, -0.5f, -0.5f
};
glVertexPointer(3, GL_FLOAT, 0, cube);
//glDrawElements( GL_TRIANGLES, 8, GL_UNSIGNED_BYTE, &cube_i );
glColor3fv( red );
glNormal3f(0, 0, 1);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glNormal3f(0, 0, -1);
glDrawArrays(GL_TRIANGLE_STRIP, 4, 4);
glColor3fv( green );
glNormal3f(-1, 0, 0);
glDrawArrays(GL_TRIANGLE_STRIP, 8, 4);
glNormal3f(1, 0, 0);
glDrawArrays(GL_TRIANGLE_STRIP, 12, 4);
glColor3fv( blue );
glNormal3f(0, 1, 0);
glDrawArrays(GL_TRIANGLE_STRIP, 16, 4);
glNormal3f(0, -1, 0);
glDrawArrays(GL_TRIANGLE_STRIP, 20, 4);
}