OSVR-Core
OpenGLCube.h
Go to the documentation of this file.
1 
11 // Copyright 2015 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 #ifndef INCLUDED_OpenGLCube_h_GUID_CC4A4D86_AD2D_4FBC_82F1_877BEEBA8434
26 #define INCLUDED_OpenGLCube_h_GUID_CC4A4D86_AD2D_4FBC_82F1_877BEEBA8434
27 
29 void draw_cube(double radius) {
30  static const GLfloat matspec[4] = {0.5, 0.5, 0.5, 0.0};
31  static const float red_col[] = {1.0, 0.0, 0.0};
32  static const float grn_col[] = {0.0, 1.0, 0.0};
33  static const float blu_col[] = {0.0, 0.0, 1.0};
34  static const float yel_col[] = {1.0, 1.0, 0.0};
35  static const float lightblu_col[] = {0.0, 1.0, 1.0};
36  static const float pur_col[] = {1.0, 0.0, 1.0};
37  glPushMatrix();
38  glScaled(radius, radius, radius);
39  glMaterialfv(GL_FRONT, GL_SPECULAR, matspec);
40  glMaterialf(GL_FRONT, GL_SHININESS, 64.0);
41  glBegin(GL_POLYGON);
42  glColor3fv(lightblu_col);
43  glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, lightblu_col);
44  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, lightblu_col);
45  glNormal3f(0.0, 0.0, -1.0);
46  glVertex3f(1.0, 1.0, -1.0);
47  glVertex3f(1.0, -1.0, -1.0);
48  glVertex3f(-1.0, -1.0, -1.0);
49  glVertex3f(-1.0, 1.0, -1.0);
50  glEnd();
51  glBegin(GL_POLYGON);
52  glColor3fv(blu_col);
53  glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, blu_col);
54  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, blu_col);
55  glNormal3f(0.0, 0.0, 1.0);
56  glVertex3f(-1.0, 1.0, 1.0);
57  glVertex3f(-1.0, -1.0, 1.0);
58  glVertex3f(1.0, -1.0, 1.0);
59  glVertex3f(1.0, 1.0, 1.0);
60  glEnd();
61  glBegin(GL_POLYGON);
62  glColor3fv(yel_col);
63  glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, yel_col);
64  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, yel_col);
65  glNormal3f(0.0, -1.0, 0.0);
66  glVertex3f(1.0, -1.0, 1.0);
67  glVertex3f(-1.0, -1.0, 1.0);
68  glVertex3f(-1.0, -1.0, -1.0);
69  glVertex3f(1.0, -1.0, -1.0);
70  glEnd();
71  glBegin(GL_POLYGON);
72  glColor3fv(grn_col);
73  glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, grn_col);
74  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, grn_col);
75  glNormal3f(0.0, 1.0, 0.0);
76  glVertex3f(1.0, 1.0, 1.0);
77  glVertex3f(1.0, 1.0, -1.0);
78  glVertex3f(-1.0, 1.0, -1.0);
79  glVertex3f(-1.0, 1.0, 1.0);
80  glEnd();
81  glBegin(GL_POLYGON);
82  glColor3fv(pur_col);
83  glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, pur_col);
84  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pur_col);
85  glNormal3f(-1.0, 0.0, 0.0);
86  glVertex3f(-1.0, 1.0, 1.0);
87  glVertex3f(-1.0, 1.0, -1.0);
88  glVertex3f(-1.0, -1.0, -1.0);
89  glVertex3f(-1.0, -1.0, 1.0);
90  glEnd();
91  glBegin(GL_POLYGON);
92  glColor3fv(red_col);
93  glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, red_col);
94  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, red_col);
95  glNormal3f(1.0, 0.0, 0.0);
96  glVertex3f(1.0, -1.0, 1.0);
97  glVertex3f(1.0, -1.0, -1.0);
98  glVertex3f(1.0, 1.0, -1.0);
99  glVertex3f(1.0, 1.0, 1.0);
100  glEnd();
101  glPopMatrix();
102 }
103 
104 #endif // INCLUDED_OpenGLCube_h_GUID_CC4A4D86_AD2D_4FBC_82F1_877BEEBA8434
void draw_cube(double radius)
Fixed-function pipeline OpenGL code to draw a cube.
Definition: OpenGLCube.h:29