84 ((double)col.green()) / 255.0f, |
84 ((double)col.green()) / 255.0f, |
85 ((double)col.blue()) / 255.0f, |
85 ((double)col.blue()) / 255.0f, |
86 1.0f); |
86 1.0f); |
87 } |
87 } |
88 |
88 |
89 void renderer::setObjectColor (LDObject* obj) { |
89 void renderer::setObjectColor (LDObject* obj, bool bBack) { |
|
90 if (gl_colorbfc && |
|
91 obj->getType () != OBJ_Line && |
|
92 obj->getType () != OBJ_CondLine) |
|
93 { |
|
94 if (bBack) |
|
95 glColor4f (0.9f, 0.0f, 0.0f, 1.0f); |
|
96 else |
|
97 glColor4f (0.0f, 0.8f, 0.0f, 1.0f); |
|
98 return; |
|
99 } |
|
100 |
90 if (obj->dColor == dMainColor) |
101 if (obj->dColor == dMainColor) |
91 setColor (gl_maincolor, glColor4f); |
102 setColor (gl_maincolor, glColor4f); |
92 else { |
103 else { |
93 color* col = g_LDColors[obj->dColor]; |
104 color* col = g_LDColors[obj->dColor]; |
94 QColor qCol (col->zColor.chars()); |
105 QColor qCol (col->zColor.chars()); |
144 |
155 |
145 glRotatef (fRotX, 1.0f, 0.0f, 0.0f); |
156 glRotatef (fRotX, 1.0f, 0.0f, 0.0f); |
146 glRotatef (fRotY, 0.0f, 1.0f, 0.0f); |
157 glRotatef (fRotY, 0.0f, 1.0f, 0.0f); |
147 glRotatef (fRotZ, 0.0f, 0.0f, 1.0f); |
158 glRotatef (fRotZ, 0.0f, 0.0f, 1.0f); |
148 |
159 |
149 glCallList (uObjList); |
160 if (gl_colorbfc) { |
|
161 glEnable (GL_CULL_FACE); |
|
162 |
|
163 glCullFace (GL_FRONT); |
|
164 glCallList (uObjList); |
|
165 |
|
166 glCullFace (GL_BACK); |
|
167 glCallList (uObjListBack); |
|
168 |
|
169 glDisable (GL_CULL_FACE); |
|
170 } else |
|
171 glCallList (uObjList); |
150 glPopMatrix (); |
172 glPopMatrix (); |
151 } |
173 } |
152 |
174 |
153 // ============================================================================= |
175 // ============================================================================= |
154 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
176 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
155 // ============================================================================= |
177 // ============================================================================= |
156 void renderer::compileObjects () { |
178 void renderer::compileObjects () { |
157 uObjList = glGenLists (1); |
|
158 glNewList (uObjList, GL_COMPILE); |
|
159 |
179 |
160 g_faObjectOffset[0] = -(g_BBox.v0.x + g_BBox.v1.x) / 2; |
180 g_faObjectOffset[0] = -(g_BBox.v0.x + g_BBox.v1.x) / 2; |
161 g_faObjectOffset[1] = -(g_BBox.v0.y + g_BBox.v1.y) / 2; |
181 g_faObjectOffset[1] = -(g_BBox.v0.y + g_BBox.v1.y) / 2; |
162 g_faObjectOffset[2] = -(g_BBox.v0.z + g_BBox.v1.z) / 2; |
182 g_faObjectOffset[2] = -(g_BBox.v0.z + g_BBox.v1.z) / 2; |
163 |
183 |
164 if (!g_CurrentFile) { |
184 if (!g_CurrentFile) { |
165 printf ("renderer: no files loaded, cannot compile anything\n"); |
185 printf ("renderer: no files loaded, cannot compile anything\n"); |
166 return; |
186 return; |
167 } |
187 } |
168 |
188 |
169 for (ulong i = 0; i < g_CurrentFile->objects.size(); i++) |
189 GLuint* upaLists[2] = { |
170 compileOneObject (g_CurrentFile->objects[i]); |
190 &uObjList, |
171 |
191 &uObjListBack, |
172 glEndList (); |
192 }; |
173 } |
193 |
174 |
194 for (uchar j = 0; j < 2; ++j) { |
175 // ============================================================================= |
195 if (j && !gl_colorbfc) |
176 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
196 continue; |
177 // ============================================================================= |
197 |
178 void renderer::compileOneObject (LDObject* obj) { |
198 *upaLists[j] = glGenLists (1); |
|
199 glNewList (*upaLists[j], GL_COMPILE); |
|
200 |
|
201 for (ulong i = 0; i < g_CurrentFile->objects.size(); i++) |
|
202 compileOneObject (g_CurrentFile->objects[i], j); |
|
203 |
|
204 glEndList (); |
|
205 } |
|
206 } |
|
207 |
|
208 // ============================================================================= |
|
209 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
|
210 // ============================================================================= |
|
211 void renderer::compileOneObject (LDObject* obj, bool bBack) { |
179 if (!obj) |
212 if (!obj) |
180 return; |
213 return; |
181 |
214 |
182 switch (obj->getType ()) { |
215 switch (obj->getType ()) { |
183 case OBJ_Line: |
216 case OBJ_Line: |
184 { |
217 { |
185 setObjectColor (obj); |
218 setObjectColor (obj, bBack); |
186 |
219 |
187 // draw lines |
220 // draw lines |
188 LDLine* line = static_cast<LDLine*> (obj); |
221 LDLine* line = static_cast<LDLine*> (obj); |
189 glBegin (GL_LINES); |
222 glBegin (GL_LINES); |
190 for (short i = 0; i < 2; ++i) |
223 for (short i = 0; i < 2; ++i) |
211 break; |
244 break; |
212 |
245 |
213 case OBJ_Triangle: |
246 case OBJ_Triangle: |
214 { |
247 { |
215 LDTriangle* tri = static_cast<LDTriangle*> (obj); |
248 LDTriangle* tri = static_cast<LDTriangle*> (obj); |
216 setObjectColor (obj); |
249 setObjectColor (obj, bBack); |
217 glBegin (GL_TRIANGLES); |
250 glBegin (GL_TRIANGLES); |
218 for (short i = 0; i < 3; ++i) |
251 for (short i = 0; i < 3; ++i) |
219 GL_VERTEX (tri->vaCoords[i]) |
252 GL_VERTEX (tri->vaCoords[i]) |
220 glEnd (); |
253 glEnd (); |
221 } |
254 } |
222 break; |
255 break; |
223 |
256 |
224 case OBJ_Quad: |
257 case OBJ_Quad: |
225 { |
258 { |
226 LDQuad* quad = static_cast<LDQuad*> (obj); |
259 LDQuad* quad = static_cast<LDQuad*> (obj); |
227 setObjectColor (obj); |
260 setObjectColor (obj, bBack); |
228 glBegin (GL_QUADS); |
261 glBegin (GL_QUADS); |
229 for (short i = 0; i < 4; ++i) |
262 for (short i = 0; i < 4; ++i) |
230 GL_VERTEX (quad->vaCoords[i]) |
263 GL_VERTEX (quad->vaCoords[i]) |
231 glEnd (); |
264 glEnd (); |
232 } |
265 } |