-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
97 lines (88 loc) · 2.92 KB
/
README
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
#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
#include <stdlib.h>
#include <stdio.h>
void drawCube(float size)
{
glBegin(GL_QUADS);
// front face
glColor3f(1.0,0.0,0.0);
glVertex3f(size/2,size/2,size/2);
glVertex3f(-size/2,size/2,size/2);
glVertex3f(-size/2,-size/2,size/2);
glVertex3f(size/2,-size/2,size/2);
// left face
glColor3f(0.0,1.0,0.0);
glVertex3f(-size/2,size/2,size/2);
glVertex3f(-size/2,-size/2,size/2);
glVertex3f(-size/2,-size/2,-size/2);
glVertex3f(-size/2,size/2,-size/2);
// back face
glColor3f(0.0,0.0,1.0);
glVertex3f(size/2,size/2,-size/2);
glVertex3f(-size/2,size/2,-size/2);
glVertex3f(-size/2,-size/2,-size/2);
glVertex3f(size/2,-size/2,-size/2);
// right face
glColor3f(1.0,1.0,0.0);
glVertex3f(size/2,size/2,size/2);
glVertex3f(size/2,-size/2,size/2);
glVertex3f(size/2,-size/2,-size/2);
glVertex3f(size/2,size/2,-size/2);
// top face
glColor3f(1.0,0.0,1.0);
glVertex3f(size/2,size/2,size/2);
glVertex3f(-size/2,size/2,size/2);
glVertex3f(-size/2,size/2,-size/2);
glVertex3f(size/2,size/2,-size/2);
// bottom face
glColor3f(0.0,1.0,1.0);
glVertex3f(size/2,-size/2,size/2);
glVertex3f(-size/2,-size/2,size/2);
glVertex3f(-size/2,-size/2,-size/2);
glVertex3f(size/2,-size/2,-size/2);
glEnd();
}
float angle = 0.0;
const int triangle = 1;
void init()
{
glClearColor(0.0,0.0,0.0,1.0); //background color and alpha
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45,640.0/480.0,1.0,500.0);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_DEPTH_TEST);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0,0.0,-5.0);
glRotatef(angle,1.0,1.0,1.0); // angle, x-axis, y-axis, z-axis
drawCube(1.0);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
/* setup the size, position, and display mode for new windows */
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(1000, 1000);
glutInitWindowPosition(100, 100);
/* create and set up a window */
glutCreateWindow("sample");
init();
glutDisplayFunc(display);
//glutReshapeFunc(reshape);
//glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
return 0;
}