File: OpenGLVisitor.cpp

package info (click to toggle)
pinball 0.3.20201218-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 8,452 kB
  • sloc: cpp: 15,230; makefile: 840; sh: 381; xml: 24
file content (449 lines) | stat: -rw-r--r-- 18,788 bytes parent folder | download | duplicates (8)
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
/***************************************************************************
                          OpenGLVisitor.cpp  -  description
                             -------------------
    begin                : Sat Jan 6 2001
    copyright            : (C) 2001 by Henrik Enqvist
    email                : henqvist@excite.com
***************************************************************************/


#include "Private.h"
#include "OpenGLVisitor.h"
#include "Group.h"
#include "Shape3D.h"
#include "Polygon.h"
#include "BillBoard.h"
#include "Config.h"

#ifndef EM_VERTEXARRAY
#define EM_VERTEXARRAY 0
#endif

#ifndef EM_OPENGL_LIGHTS
#define EM_OPENGL_LIGHTS 0
#endif

/* Optimization observations:
 * * Voodoo 3 System
 * glVertex3f is a bit fatser than glVertex3fv ~3%.
 * glVertex3f is faster then glVertexArray ~10-20%, really strange.
 */

OpenGLVisitor * OpenGLVisitor::p_OpenGLVisitor = NULL;
int OpenGLVisitor::m_iPoly = 0;

OpenGLVisitor::OpenGLVisitor(){
  m_iMode = EM_GL_GCOL_TEX;
  m_bOffset = false;
}

OpenGLVisitor::~OpenGLVisitor(){
  p_OpenGLVisitor = NULL;
}

OpenGLVisitor * OpenGLVisitor::getInstance() {
  if (p_OpenGLVisitor == NULL) {
    p_OpenGLVisitor = new OpenGLVisitor();
  }
  return p_OpenGLVisitor;
}

void OpenGLVisitor::empty() {
#if EM_USE_SDL
#if EM_VERTEXARRAY
  glEnableClientState(GL_VERTEX_ARRAY);
  glEnableClientState(GL_COLOR_ARRAY);
#endif
	
  switch (m_iMode) {
  case EM_GL_GCOL_TEX: {
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);
    //glDisable(GL_TEXTURE_2D);
    glDisable(GL_BLEND);
    glDisable(GL_ALPHA_TEST);
    glDepthMask(GL_TRUE);

  } break;
  case EM_GL_GCOL_TEX_TRANS: {
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);
    //glDisable(GL_TEXTURE_2D);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glDepthMask(GL_FALSE);
    // 		glEnable(GL_ALPHA_TEST);
    // 		glAlphaFunc(GL_GREATER, 0.05);
  } break;
  case EM_GL_CLEAN: {
#if EM_DEBUG
    m_iPoly = 0;
#endif
    glDisable(GL_DEPTH_TEST);
    glDisable(GL_ALPHA_TEST);
    glDisable(GL_TEXTURE_2D);
    glDisable(GL_BLEND);
  } break;
  }
#endif
}

void OpenGLVisitor::visit(Group* g) {
#if EM_USE_SDL
  int filter = Config::getInstance()->getGLFilter();
  //bool lights = Config::getInstance()->useLights();

  switch (m_iMode) {
  case EM_GL_GCOL_TEX: {
    // shapes
    vector<Shape3D*>::iterator shapeIter = g->m_vShape3D.begin();
    vector<Shape3D*>::iterator shapeEnd = g->m_vShape3D.end();
    for ( ; shapeIter != shapeEnd; shapeIter++) {
      if (EM_SHAPE3D_HIDDEN & (*shapeIter)->m_iProperties) continue;

      if ((*shapeIter)->m_iProperties & EM_SHAPE3D_BEHIND) {
        glEnable(GL_POLYGON_OFFSET_FILL);
        glPolygonOffset(1.0, 1.0);
      } else if ((*shapeIter)->m_iProperties & EM_SHAPE3D_BEHIND2) {
        glEnable(GL_POLYGON_OFFSET_FILL);
        glPolygonOffset(1.0, 2.0);
      } else {
        glDisable(GL_POLYGON_OFFSET_FILL);
      }

      if ((*shapeIter)->m_Texture != NULL && filter != -1) { // textured polygons	
        glEnable(GL_TEXTURE_2D);
        glBindTexture(GL_TEXTURE_2D, *((*shapeIter)->m_Texture));
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

        if ((*shapeIter)->m_iProperties & EM_SHAPE3D_ALWAYSLIT) { // EM_SHAPE3D_ALWAYSLIT
          vector<Polygon3D*>::iterator polyIter = (*shapeIter)->m_vPolygon.begin();
          vector<Polygon3D*>::iterator polyEnd = (*shapeIter)->m_vPolygon.end();
          for ( ; polyIter != polyEnd; ++polyIter) {
            if ((*polyIter)->m_iProperties & EM_POLY_TRANS) continue;
#if EM_DEBUG
            ++m_iPoly;
#endif
            vector<int>::iterator indexIter = (*polyIter)->m_vIndex.begin();
            vector<int>::iterator indexEnd = (*polyIter)->m_vIndex.end();
            glBegin(GL_POLYGON);
            for ( ; indexIter != indexEnd; ++indexIter) {
              glTexCoord2f((*shapeIter)->m_vTexCoord[(*indexIter)].u,
                           (*shapeIter)->m_vTexCoord[(*indexIter)].v);
              glColor3f((*shapeIter)->m_vColor[(*indexIter)].r,
                        (*shapeIter)->m_vColor[(*indexIter)].g,
                        (*shapeIter)->m_vColor[(*indexIter)].b);
              glVertex3f((*shapeIter)->m_vVtxAlign[(*indexIter)].x,
                         (*shapeIter)->m_vVtxAlign[(*indexIter)].y,
                         (*shapeIter)->m_vVtxAlign[(*indexIter)].z);
            }
            glEnd();
          }
        } else { // ! EM_SHAPE3D_ALWAYSLIT
          vector<Polygon3D*>::iterator polyIter = (*shapeIter)->m_vPolygon.begin();
          vector<Polygon3D*>::iterator polyEnd = (*shapeIter)->m_vPolygon.end();
          for ( ; polyIter != polyEnd; ++polyIter) {
            if ((*polyIter)->m_iProperties & EM_POLY_TRANS) continue;
#if EM_DEBUG
            ++m_iPoly;
#endif
            vector<int>::iterator indexIter = (*polyIter)->m_vIndex.begin();
            vector<int>::iterator indexEnd = (*polyIter)->m_vIndex.end();
            glBegin(GL_POLYGON);
            for ( ; indexIter != indexEnd; ++indexIter) {
              glTexCoord2f((*shapeIter)->m_vTexCoord[(*indexIter)].u,
                           (*shapeIter)->m_vTexCoord[(*indexIter)].v);
              // Question should textured polygons have specular?
              glColor3f((*shapeIter)->m_vLight[(*indexIter)].r,
                        (*shapeIter)->m_vLight[(*indexIter)].g,
                        (*shapeIter)->m_vLight[(*indexIter)].b);
              glVertex3f((*shapeIter)->m_vVtxAlign[(*indexIter)].x,
                         (*shapeIter)->m_vVtxAlign[(*indexIter)].y,
                         (*shapeIter)->m_vVtxAlign[(*indexIter)].z);
            }
            glEnd();
          }
        }
      } else { // if ((*shapeIter)->m_Texture... // color polygons
        glDisable(GL_TEXTURE_2D);
        // if statement moved outside for loop for performance
        if ((*shapeIter)->m_iProperties & EM_SHAPE3D_ALWAYSLIT) { // EM_SHAPE3D_ALWAYSLIT
          vector<Polygon3D*>::iterator polyIter = (*shapeIter)->m_vPolygon.begin();
          vector<Polygon3D*>::iterator polyEnd = (*shapeIter)->m_vPolygon.end();
          for ( ; polyIter != polyEnd; ++polyIter) {
            if ((*polyIter)->m_iProperties & EM_POLY_TRANS) continue;
#if EM_DEBUG
            ++m_iPoly;
#endif
            vector<int>::iterator indexIter = (*polyIter)->m_vIndex.begin();
            vector<int>::iterator indexEnd = (*polyIter)->m_vIndex.end();
            glBegin(GL_POLYGON);
            for (; indexIter != indexEnd; ++indexIter) {
              glColor3f((*shapeIter)->m_vColor[(*indexIter)].r, 
                        (*shapeIter)->m_vColor[(*indexIter)].g, 
                        (*shapeIter)->m_vColor[(*indexIter)].b);
              glVertex3f((*shapeIter)->m_vVtxAlign[(*indexIter)].x,
                         (*shapeIter)->m_vVtxAlign[(*indexIter)].y,
                         (*shapeIter)->m_vVtxAlign[(*indexIter)].z);
            }
            glEnd();
          }
        } else { // ! EM_SHAPE3D_ALWAYSLIT
          vector<Polygon3D*>::iterator polyIter = (*shapeIter)->m_vPolygon.begin();
          vector<Polygon3D*>::iterator polyEnd = (*shapeIter)->m_vPolygon.end();
          for ( ; polyIter != polyEnd; ++polyIter) {
            if ((*polyIter)->m_iProperties & EM_POLY_TRANS) continue;
#if EM_DEBUG
            ++m_iPoly;
#endif
            vector<int>::iterator indexIter = (*polyIter)->m_vIndex.begin();
            vector<int>::iterator indexEnd = (*polyIter)->m_vIndex.end();
            glBegin(GL_POLYGON);
            for (; indexIter != indexEnd; ++indexIter) {
              glColor3f((*shapeIter)->m_vLitColor[(*indexIter)].r, 
                        (*shapeIter)->m_vLitColor[(*indexIter)].g, 
                        (*shapeIter)->m_vLitColor[(*indexIter)].b);
              glVertex3f((*shapeIter)->m_vVtxAlign[(*indexIter)].x,
                         (*shapeIter)->m_vVtxAlign[(*indexIter)].y,
                         (*shapeIter)->m_vVtxAlign[(*indexIter)].z);
            }
            glEnd();
          }
        }
      }
    }
    // billboard
    BillBoard * b = g->p_BillBoard;
    if (b != NULL && !(b->m_iProperties & EM_BILLBOARD_TRANS)) {
      EmAssert(b->m_Texture != NULL, "all billboards must have a texture");

      glBindTexture(GL_TEXTURE_2D, *(b->m_Texture));
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
      glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

      // a textured polygon
      glColor3f(1, 1, 1);
      glBegin(GL_POLYGON);
      glTexCoord2f(0, 0);
      glVertex3f(b->m_vtxAlign.x - b->m_fSizexD2, 
                 b->m_vtxAlign.y + b->m_fSizeyD2, 
                 b->m_vtxAlign.z);
      glTexCoord2f(1, 0);
      glVertex3f(b->m_vtxAlign.x + b->m_fSizexD2, 
                 b->m_vtxAlign.y + b->m_fSizeyD2, 
                 b->m_vtxAlign.z);
      glTexCoord2f(1, 1);
      glVertex3f(b->m_vtxAlign.x + b->m_fSizexD2, 
                 b->m_vtxAlign.y - b->m_fSizeyD2, 
                 b->m_vtxAlign.z);
      glTexCoord2f(0, 1);
      glVertex3f(b->m_vtxAlign.x - b->m_fSizexD2, 
                 b->m_vtxAlign.y - b->m_fSizeyD2, 
                 b->m_vtxAlign.z);
      glEnd();
			
      EM_COUT_D("OpenGLVisitor::visit() BillBoard at " << b->m_vtxAlign.x <<" "<<
                b->m_vtxAlign.y <<" "<< b->m_vtxAlign.z, 0);
    }
  } break;
  case EM_GL_GCOL_TEX_TRANS: {
    vector<Shape3D*>::iterator shapeIter = g->m_vShape3D.begin();
    vector<Shape3D*>::iterator shapeEnd = g->m_vShape3D.end();
    for ( ; shapeIter != shapeEnd; shapeIter++) {

      if (EM_SHAPE3D_HIDDEN & (*shapeIter)->m_iProperties) continue;
      if (!(EM_SHAPE3D_USE_TRANS & (*shapeIter)->m_iProperties)) continue;
#if 0 // I used wireframes when showing some demos in school
      {
        // wireframe
        glEnable(GL_POLYGON_OFFSET_FILL);
        glPolygonOffset(1.0, -1.0);
        vector<Polygon3D*>::iterator polyIter = (*shapeIter)->m_vPolygon.begin();
        vector<Polygon3D*>::iterator polyEnd = (*shapeIter)->m_vPolygon.end();
        for ( ; polyIter != polyEnd; ++polyIter) {
          ++m_iPoly;
          glColor3f(0.0f, 0.0f, 0.0f);
          vector<int>::iterator indexIter = (*polyIter)->m_vIndex.begin();
          vector<int>::iterator indexEnd = (*polyIter)->m_vIndex.end();
          glBegin(GL_LINE_LOOP);
          for ( ; indexIter != indexEnd; ++indexIter) {
            glVertex3f((*shapeIter)->m_vVtxAlign[(*indexIter)].x,
                       (*shapeIter)->m_vVtxAlign[(*indexIter)].y,
                       (*shapeIter)->m_vVtxAlign[(*indexIter)].z);
          }
          glEnd();
        }
        glDisable(GL_POLYGON_OFFSET_FILL);
      }
#endif

      if ((*shapeIter)->m_iProperties & EM_SHAPE3D_BEHIND) {
        glEnable(GL_POLYGON_OFFSET_FILL);
        glPolygonOffset(1.0, 1.0);
      } else if ((*shapeIter)->m_iProperties & EM_SHAPE3D_BEHIND2) {
        glEnable(GL_POLYGON_OFFSET_FILL);
        glPolygonOffset(1.0, 2.0);
      } else {
        glDisable(GL_POLYGON_OFFSET_FILL);
      }

      if ((*shapeIter)->m_Texture != NULL && filter != -1) { // textured polygon
        glEnable(GL_TEXTURE_2D);
        glBindTexture(GL_TEXTURE_2D, *((*shapeIter)->m_Texture));
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
				
        if ((*shapeIter)->m_iProperties & EM_SHAPE3D_ALWAYSLIT) { // EM_SHAPE3D_ALWAYSLIT
          vector<Polygon3D*>::iterator polyIter = (*shapeIter)->m_vPolygon.begin();
          vector<Polygon3D*>::iterator polyEnd = (*shapeIter)->m_vPolygon.end();
          for ( ; polyIter != polyEnd; polyIter++) {
            if (!((*polyIter)->m_iProperties & EM_POLY_TRANS)) continue;
#if EM_DEBUG
            ++m_iPoly;
#endif
            // textured polygon
            vector<int>::iterator indexIter = (*polyIter)->m_vIndex.begin();
            vector<int>::iterator indexEnd = (*polyIter)->m_vIndex.end();
            glBegin(GL_POLYGON);
            for ( ; indexIter != indexEnd; indexIter++) {
              glTexCoord2f((*shapeIter)->m_vTexCoord[(*indexIter)].u, 
                           (*shapeIter)->m_vTexCoord[(*indexIter)].v);
              glColor4f((*shapeIter)->m_vColor[(*indexIter)].r,
                        (*shapeIter)->m_vColor[(*indexIter)].g,
                        (*shapeIter)->m_vColor[(*indexIter)].b,
                        (*shapeIter)->m_vColor[(*indexIter)].a);
              glVertex3f((*shapeIter)->m_vVtxAlign[(*indexIter)].x,
                         (*shapeIter)->m_vVtxAlign[(*indexIter)].y,
                         (*shapeIter)->m_vVtxAlign[(*indexIter)].z);
            }
            glEnd();
          }
        } else { // ! EM_SHAPE3D_ALWAYSLIT
          vector<Polygon3D*>::iterator polyIter = (*shapeIter)->m_vPolygon.begin();
          vector<Polygon3D*>::iterator polyEnd = (*shapeIter)->m_vPolygon.end();
          for ( ; polyIter != polyEnd; polyIter++) {
            if (!((*polyIter)->m_iProperties & EM_POLY_TRANS)) continue;
#if EM_DEBUG
            ++m_iPoly;
#endif
            // textured polygon
            vector<int>::iterator indexIter = (*polyIter)->m_vIndex.begin();
            vector<int>::iterator indexEnd = (*polyIter)->m_vIndex.end();
            glBegin(GL_POLYGON);
            for ( ; indexIter != indexEnd; indexIter++) {
              glTexCoord2f((*shapeIter)->m_vTexCoord[(*indexIter)].u, 
                           (*shapeIter)->m_vTexCoord[(*indexIter)].v);
              glColor4f((*shapeIter)->m_vLight[(*indexIter)].r,
                        (*shapeIter)->m_vLight[(*indexIter)].g,
                        (*shapeIter)->m_vLight[(*indexIter)].b,
                        (*shapeIter)->m_vLight[(*indexIter)].a);
              glVertex3f((*shapeIter)->m_vVtxAlign[(*indexIter)].x,
                         (*shapeIter)->m_vVtxAlign[(*indexIter)].y,
                         (*shapeIter)->m_vVtxAlign[(*indexIter)].z);
            }
            glEnd();
          }
        }
      } else { // color polygon
        glDisable(GL_TEXTURE_2D);
        if ((*shapeIter)->m_iProperties & EM_SHAPE3D_ALWAYSLIT) {
          vector<Polygon3D*>::iterator polyIter = (*shapeIter)->m_vPolygon.begin();
          vector<Polygon3D*>::iterator polyEnd = (*shapeIter)->m_vPolygon.end();
          for ( ; polyIter != polyEnd; polyIter++) {
            if (!((*polyIter)->m_iProperties & EM_POLY_TRANS)) continue;
#if EM_DEBUG
            ++m_iPoly;
#endif
            vector<int>::iterator indexIter = (*polyIter)->m_vIndex.begin();
            vector<int>::iterator indexEnd = (*polyIter)->m_vIndex.end();
            glBegin(GL_POLYGON);
            for ( ; indexIter != indexEnd; indexIter++) {
              // transparent polygons should not be lit, or ?
              glColor4f((*shapeIter)->m_vColor[(*indexIter)].r,
                        (*shapeIter)->m_vColor[(*indexIter)].g,
                        (*shapeIter)->m_vColor[(*indexIter)].b,
                        (*shapeIter)->m_vColor[(*indexIter)].a);
              glVertex3f((*shapeIter)->m_vVtxAlign[(*indexIter)].x,
                         (*shapeIter)->m_vVtxAlign[(*indexIter)].y,
                         (*shapeIter)->m_vVtxAlign[(*indexIter)].z);
            }
            glEnd();
          }
        } else { // EM_SHAPE3D_ALWAYSLIT
          vector<Polygon3D*>::iterator polyIter = (*shapeIter)->m_vPolygon.begin();
          vector<Polygon3D*>::iterator polyEnd = (*shapeIter)->m_vPolygon.end();
          for ( ; polyIter != polyEnd; polyIter++) {
            if (!((*polyIter)->m_iProperties & EM_POLY_TRANS)) continue;
#if EM_DEBUG
            ++m_iPoly;
#endif
            vector<int>::iterator indexIter = (*polyIter)->m_vIndex.begin();
            vector<int>::iterator indexEnd = (*polyIter)->m_vIndex.end();
            glBegin(GL_POLYGON);
            for ( ; indexIter != indexEnd; indexIter++) {
              // transparent polygons should not be lit, or ?
              glColor4f((*shapeIter)->m_vLitColor[(*indexIter)].r,
                        (*shapeIter)->m_vLitColor[(*indexIter)].g,
                        (*shapeIter)->m_vLitColor[(*indexIter)].b,
                        (*shapeIter)->m_vLitColor[(*indexIter)].a);
              glVertex3f((*shapeIter)->m_vVtxAlign[(*indexIter)].x,
                         (*shapeIter)->m_vVtxAlign[(*indexIter)].y,
                         (*shapeIter)->m_vVtxAlign[(*indexIter)].z);
            }
            glEnd();
          }
        }
      }
    }
    // billboard
    BillBoard * b = g->p_BillBoard;
    if (b != NULL && b->m_iProperties & EM_BILLBOARD_TRANS) {
      EmAssert(b->m_Texture != NULL, "all billboards must have a texture");

      glBindTexture(GL_TEXTURE_2D, *(b->m_Texture));
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
      glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

      // a textured polygon
      glColor3f(1, 1, 1);
      glBegin(GL_POLYGON);
      glTexCoord2f(0, 0);
      glVertex3f(b->m_vtxAlign.x - b->m_fSizexD2, 
                 b->m_vtxAlign.y + b->m_fSizeyD2, 
                 b->m_vtxAlign.z);
      glTexCoord2f(1, 0);
      glVertex3f(b->m_vtxAlign.x + b->m_fSizexD2, 
                 b->m_vtxAlign.y + b->m_fSizeyD2, 
                 b->m_vtxAlign.z);
      glTexCoord2f(1, 1);
      glVertex3f(b->m_vtxAlign.x + b->m_fSizexD2, 
                 b->m_vtxAlign.y - b->m_fSizeyD2, 
                 b->m_vtxAlign.z);
      glTexCoord2f(0, 1);
      glVertex3f(b->m_vtxAlign.x - b->m_fSizexD2, 
                 b->m_vtxAlign.y - b->m_fSizeyD2, 
                 b->m_vtxAlign.z);
      glEnd();
			
      EM_COUT_D("OpenGLVisitor::visit() BillBoard at " << b->m_vtxAlign.x <<" "<<
                b->m_vtxAlign.y <<" "<< b->m_vtxAlign.z, 0);
    }
  } break;

  }
#endif // EM_USE_SDL
}