gldraw.cpp

changeset 62
915fc477cb6a
parent 60
961663d05463
child 63
aa40ce18f869
equal deleted inserted replaced
61:109b07334fa0 62:915fc477cb6a
82 ((double)col.green()) / 255.0f, 82 ((double)col.green()) / 255.0f,
83 ((double)col.blue()) / 255.0f, 83 ((double)col.blue()) / 255.0f,
84 1.0f); 84 1.0f);
85 } 85 }
86 86
87 void renderer::setObjectColor (LDObject* obj, bool bBack) { 87 void renderer::setObjectColor (LDObject* obj, bool bBackSide) {
88 if (gl_colorbfc && 88 if (gl_colorbfc &&
89 obj->getType () != OBJ_Line && 89 obj->getType () != OBJ_Line &&
90 obj->getType () != OBJ_CondLine) 90 obj->getType () != OBJ_CondLine)
91 { 91 {
92 if (bBack) 92 if (bBackSide)
93 glColor4f (0.9f, 0.0f, 0.0f, 1.0f); 93 glColor4f (0.9f, 0.0f, 0.0f, 1.0f);
94 else 94 else
95 glColor4f (0.0f, 0.8f, 0.0f, 1.0f); 95 glColor4f (0.0f, 0.8f, 0.0f, 1.0f);
96 return; 96 return;
97 } 97 }
199 } 199 }
200 200
201 // ============================================================================= 201 // =============================================================================
202 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 202 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
203 // ============================================================================= 203 // =============================================================================
204 void renderer::compileOneObject (LDObject* obj, bool bBack) { 204 template<class T>void renderer::compileSubObject (LDObject* obj,
205 const bool bBackSide, const GLenum eGLType, const short dVerts)
206 {
207 setObjectColor (obj, bBackSide);
208 T* newobj = static_cast<T*> (obj);
209 glBegin (eGLType);
210
211 for (short i = 0; i < dVerts; ++i)
212 compileVertex (newobj->vaCoords[i]);
213
214 glEnd ();
215 }
216
217 // =============================================================================
218 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
219 // =============================================================================
220 void renderer::compileOneObject (LDObject* obj, bool bBackSide) {
205 if (!obj) 221 if (!obj)
206 return; 222 return;
207 223
208 switch (obj->getType ()) { 224 switch (obj->getType ()) {
209 case OBJ_Line: 225 case OBJ_Line:
226 compileSubObject<LDLine> (obj, bBackSide, GL_LINES, 2);
227 break;
228
229 case OBJ_CondLine:
230 glLineStipple (1, 0x6666);
231 glEnable (GL_LINE_STIPPLE);
232
233 compileSubObject<LDCondLine> (obj, bBackSide, GL_LINES, 2);
234
235 glDisable (GL_LINE_STIPPLE);
236 break;
237
238 case OBJ_Triangle:
239 compileSubObject<LDTriangle> (obj, bBackSide, GL_TRIANGLES, 3);
240 break;
241
242 case OBJ_Quad:
243 compileSubObject<LDQuad> (obj, bBackSide, GL_QUADS, 4);
244 break;
245
246 case OBJ_Subfile:
210 { 247 {
211 setObjectColor (obj, bBack); 248 LDSubfile* ref = static_cast<LDSubfile*> (obj);
212 249
213 // draw lines 250 vector<LDObject*> objs = ref->inlineContents (ref->faMatrix, ref->vPosition, true);
214 LDLine* line = static_cast<LDLine*> (obj); 251
215 glBegin (GL_LINES); 252 for (ulong i = 0; i < (ulong)objs.size(); ++i)
216 for (short i = 0; i < 2; ++i) 253 compileOneObject (objs[i], bBackSide);
217 compileVertex (line->vaCoords[i]);
218 glEnd ();
219 }
220 break;
221
222 case OBJ_CondLine:
223 {
224 glLineStipple (1, 0x6666);
225 glEnable (GL_LINE_STIPPLE);
226
227 setObjectColor (obj, bBack);
228 LDCondLine* line = static_cast<LDCondLine*> (obj);
229
230 glBegin (GL_LINES);
231 for (short i = 0; i < 2; ++i)
232 compileVertex (line->vaCoords[i]);
233 glEnd ();
234
235 glDisable (GL_LINE_STIPPLE);
236 }
237 break;
238
239 case OBJ_Triangle:
240 {
241 LDTriangle* tri = static_cast<LDTriangle*> (obj);
242 setObjectColor (obj, bBack);
243 glBegin (GL_TRIANGLES);
244 for (short i = 0; i < 3; ++i)
245 compileVertex (tri->vaCoords[i]);
246 glEnd ();
247 }
248 break;
249
250 case OBJ_Quad:
251 {
252 LDQuad* quad = static_cast<LDQuad*> (obj);
253 setObjectColor (obj, bBack);
254 glBegin (GL_QUADS);
255 for (short i = 0; i < 4; ++i)
256 compileVertex (quad->vaCoords[i]);
257 glEnd ();
258 } 254 }
259 break; 255 break;
260 256
261 default: 257 default:
262 break; 258 break;
268 // ============================================================================= 264 // =============================================================================
269 void renderer::compileVertex (vertex& vrt) { 265 void renderer::compileVertex (vertex& vrt) {
270 glVertex3d ( 266 glVertex3d (
271 (vrt.x + g_faObjectOffset[0]) / g_StoredBBoxSize, 267 (vrt.x + g_faObjectOffset[0]) / g_StoredBBoxSize,
272 -(vrt.y + g_faObjectOffset[1]) / g_StoredBBoxSize, 268 -(vrt.y + g_faObjectOffset[1]) / g_StoredBBoxSize,
273 (vrt.z + g_faObjectOffset[2]) / g_StoredBBoxSize); 269 -(vrt.z + g_faObjectOffset[2]) / g_StoredBBoxSize);
274 } 270 }
275 271
276 // ============================================================================= 272 // =============================================================================
277 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 273 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
278 // ============================================================================= 274 // =============================================================================

mercurial