26 #include "SimpleSceneGL.hh"
27 #include <Gui/GeometryGL.hh>
29 #ifndef BIAS_HAVE_GLUT
30 # error Please recompile BIAS with USE_GLUT to compile this example.
31 #endif // BIAS_HAVE_GLUT
32 #define GLUT_BUILDING_LIB
39 class SimpleSceneGLData {
41 SimpleSceneGLData() : dplist(0) {};
51 void InitGeometry(
int &dplist)
54 static bool initDone =
false;
59 dplist = glGenLists(1);
60 glNewList(dplist, GL_COMPILE);
64 GLfloat light_position0[] = { 10.0f, 10.0, 10.0f, 0.0f };
65 GLfloat light_maincolor0[] = { 1.0f, 1.0, 1.0f, 1.0f };
66 GLfloat light_ambientcolor0[] = { 0.4f, 0.2f, 0.2f, 1.0f };
69 glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
70 glLightfv(GL_LIGHT0, GL_DIFFUSE, light_maincolor0);
71 glLightfv(GL_LIGHT0, GL_SPECULAR, light_maincolor0);
72 glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambientcolor0);
75 glEnable(GL_LIGHTING);
76 glEnable(GL_DEPTH_TEST);
79 GLfloat paintcolor0[] = { 0.9, 0.2, 0.5, 1.0 };
80 GLfloat specularcolor0[] = { 1.0, 1.0, 1.0, 1.0 };
81 GLfloat shininess0[] = { 70. };
83 GLfloat paintcolor1[] = { 0.3, 0.9, 0.4, 1.0 };
84 GLfloat paintcolor2[] = { 0.1, 0.2, 0.9, 1.0 };
86 glMatrixMode(GL_MODELVIEW);
90 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specularcolor0);
91 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, shininess0);
92 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE,
94 glColor3f(paintcolor0[0], paintcolor0[1], paintcolor0[2]);
99 glTranslatef(dtea[0], dtea[1], dtea[2]);
102 glutSolidTeapot(0.6);
105 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE,
107 glColor3f(paintcolor1[0], paintcolor1[1], paintcolor1[2]);
109 glTranslatef(-2 * dtea[0], -2 * dtea[1], -2 * dtea[2]);
111 glutSolidTeapot(0.3);
113 glTranslatef(dtea[0], dtea[1], dtea[2]);
117 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE,
119 glColor3f(paintcolor2[0], paintcolor2[1], paintcolor2[2]);
121 glTranslatef(0, 0, -2);
122 glutSolidSphere(0.8, 30, 60);
123 glTranslatef(0, 0, 2);
125 glTranslatef(1, 0, -3);
126 glutSolidSphere(0.5, 50, 100);
127 glTranslatef(-1, 0, 3);
130 glTranslatef(0, 2, 0);
132 glTranslatef(0, -2, 0);
134 glTranslatef(0, -1, 0);
135 glutSolidIcosahedron();
136 glTranslatef(0, 1, 0);
138 glTranslatef(0, -2.2, 0);
139 glutSolidTetrahedron();
140 glTranslatef(0, 2.2, 0);
157 void SimpleSceneGL::Display()
159 if (this->pc == NULL)
162 BIASASSERT(this->pc != NULL);
164 static SimpleSceneGLData data;
165 InitGeometry(data.dplist);
168 pc->DisplayCameraView();
169 pc->DisplayRenderMode();
179 glColor3f(1.0, 0.5, 0.2);
181 if (glIsList(data.dplist) == GL_TRUE) {
185 const float cycletime = 10.0;
186 const float angleM = fmodf(
float
187 (2.0 * 360.0 / cycletime *
188 OpenGLCanvasBase::time),
190 if (angleM <= 360.0) {
191 glRotatef(angleM, 0.0, 1.0, 0.0);
193 glRotatef(angleM - 360.0, 1.0, 0.0, 0.0);
199 glCallList(data.dplist);
207 BIASERR(
"invalid display list dplist=" << data.dplist);
210 pc->DisplayCoordCross();
212 glColor3f(1.0f, 1.0f, 0.5f);