Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
GeometryGL.cpp
1 #include <Base/Common/W32Compat.hh>
2 #include "GeometryGL.hh"
3 
4 // must be first
5 #include "biasgl.h"
6 
7 #include <Base/Debug/DebugSimple.hh>
8 #include <Base/Debug/TimeMeasure.hh>
9 #include <Base/Math/Vector2.hh>
10 #include <Base/Math/Vector3.hh>
11 #include <Base/Math/Matrix3x3.hh>
12 #include <Base/Math/Matrix3x4.hh>
13 #include <Geometry/RMatrix.hh>
14 #include <Geometry/PMatrix.hh>
15 
16 #include <Base/Image/ImageBase.hh>
17 #include <math.h>
18 
19 
20 // convert GLBoolean for output in stream:
21 #define GL2Cbool(arg) (unsigned int)(arg)<< (arg?" (true)":" (false)")
22 
23 
24 // ----------------------------------------------------------
25 // namespace stuff:
26 using namespace BIAS;
27 using namespace std;
28 // ----------------------------------------------------------
29 
30 /** @author Jan Woetzel 04/2005 */
31 
33 
35 
36 
37 void GeometryGL::GetInfoGLmatrices(std::ostream & os)
38 {
39  GLfloat modelviewMatrix[16];
40  glGetFloatv(GL_MODELVIEW_MATRIX, &modelviewMatrix[0]);
41  GLfloat projectionMatrix[16];
42  glGetFloatv(GL_PROJECTION_MATRIX, &projectionMatrix[0]);
43  GLfloat textureMatrix0[16];
44  glGetFloatv(GL_TEXTURE_MATRIX, &textureMatrix0[0]);
45 
46  unsigned int row=0;
47  os << "GL_MODELVIEW_MATRIX = (column-major!)"<<endl;
48  for (row=0; row<4; row++) {
49  os<<std::setprecision(10)<<modelviewMatrix[row+ 0]<<" \t";
50  os<<std::setprecision(10)<<modelviewMatrix[row+ 4]<<" \t";
51  os<<std::setprecision(10)<<modelviewMatrix[row+ 8]<<" \t";
52  os<<std::setprecision(10)<<modelviewMatrix[row+12];
53  os<<endl;
54  };
55  os << "GL_PROJECTION_MATRIX = (column-major!) "<<endl;
56  for (row=0; row<4; row++) {
57  os<<std::setprecision(10)<<projectionMatrix[row+ 0]<<" \t";
58  os<<std::setprecision(10)<<projectionMatrix[row+ 4]<<" \t";
59  os<<std::setprecision(10)<<projectionMatrix[row+ 8]<<" \t";
60  os<<std::setprecision(10)<<projectionMatrix[row+12];
61  os<<endl;
62  };
63  os << "GL_TEXTURE_MATRIX = (column-major!) "<<endl;
64  for (row=0; row<4; row++) {
65  os<<std::setprecision(10)<<textureMatrix0[row+ 0]<<" \t";
66  os<<std::setprecision(10)<<textureMatrix0[row+ 4]<<" \t";
67  os<<std::setprecision(10)<<textureMatrix0[row+ 8]<<" \t";
68  os<<std::setprecision(10)<<textureMatrix0[row+12];
69  os<<endl;
70  };
71  CHECK_GL_ERROR;
72 }
73 
74 
75 void GeometryGL::GetInfoGLDisplayLists(std::ostream & os)
76 {
77  unsigned int i=0;
78  // query all available display lists
79  int foundDisplists=0;
80  for (i=0; i<MAX_GL_DISPLIST_ID; i++)
81  {
82  if(glIsList(i) == GL_TRUE)
83  {
84  foundDisplists++;
85  os<<"valid displaylistID="<<i<<endl;
86  };
87  };
88  os<<"** found a total of "<<foundDisplists<<" valid display lists/IDs <MAX_GL_DISPLIST_ID="<<MAX_GL_DISPLIST_ID<<" **"<<endl;
89 }
90 
91 
92 void GeometryGL::GetInfoGLTexID(const GLint id,
93  int & foundTextures,
94  std::ostream & os,
95  const bool & noOutputIfInvalid)
96 {
97  if (!glIsTexture(id)) {
98  if (!noOutputIfInvalid)
99  os<<"texid="<<id<<" invalid."<<endl;
100  return;
101  }
102 
103  // query residence and priority status of all texobj's
104  GLint target=GL_TEXTURE_2D;
105  GLint resident=GL_FALSE;
106  GLfloat priority=0;
107  GLint width=0, height=0;
108  GLint min_tex=0, mag_tex=0;
109  GLint tex_state=0;
110  GLint tex_env=0;
111  GLint int_fmt=0;
112  GLint components=0, red=0, green=0, blue=0, alpha=0;
113 
114  foundTextures++;
115  glBindTexture(GL_TEXTURE_2D, id );
116  glGetIntegerv(GL_TEXTURE_2D, &tex_state);
117 
118  glGetTexParameteriv(target, GL_TEXTURE_WIDTH, &width);
119  glGetTexParameteriv(target, GL_TEXTURE_HEIGHT, &height);
120  glGetTexParameteriv(target, GL_TEXTURE_INTERNAL_FORMAT, &int_fmt);
121  glGetTexParameteriv(target, GL_TEXTURE_COMPONENTS, &components );
122  glGetTexParameteriv(target, GL_TEXTURE_RED_SIZE, &red);
123  glGetTexParameteriv(target, GL_TEXTURE_GREEN_SIZE, &green);
124  glGetTexParameteriv(target, GL_TEXTURE_BLUE_SIZE, &blue);
125  glGetTexParameteriv(target, GL_TEXTURE_ALPHA_SIZE, &alpha);
126 
127  glGetTexParameteriv(target, GL_TEXTURE_MAG_FILTER, &mag_tex);
128  glGetTexParameteriv(target, GL_TEXTURE_MIN_FILTER, &min_tex);
129  glGetTexParameteriv(target, GL_TEXTURE_RESIDENT, &resident);
130  glGetTexParameterfv(target, GL_TEXTURE_PRIORITY, &priority);
131 
132  glGetTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &tex_env);
133 
134  CHECK_GL_ERROR;
135  os<<"valid texID="<<id<<" : "<<endl;
136  os<<"\tminifiction filter = "<<GetName(min_tex)<<endl;
137  os<<"\tmagnifictaion filter = "<<GetName(mag_tex)<<endl;
138  //target="<<GetName(target)
139  os<<"\tdim "<<width<<" x "<<height<<endl;
140  os<<"\tcomponents "<<components<<endl;
141  os<<"\ttex red bits "<<red<<endl;
142  os<<"\ttex green bits "<<green<<endl;
143  os<<"\ttex blue bits "<<blue<<endl;
144  os<<"\ttex alpha bits "<<alpha<<endl;
145 
146  os<<"\tinternal_fmt="<<GetName(int_fmt)<<endl;
147  os<<"\ttex_state ="<<GetName(tex_state)<<endl;
148  os<<"\ttex_env ="<<GetName(tex_env)<<endl;
149  os<<"\tresident="<<GetName(resident)<<" priority="<<(float)priority<<endl;
150  const unsigned int maxLevels=(unsigned int)(log((float)max(width,height))/log(2.0f));
151  for (int level=-1*(int)(maxLevels); level<=(int)maxLevels; level++){
152  //GL_PROXY_TEXTURE_2D
153  glGetTexLevelParameteriv(target, level, GL_TEXTURE_WIDTH, &width);
154  glGetTexLevelParameteriv(target, level, GL_TEXTURE_HEIGHT, &height);
155  CHECK_GL_ERROR;
156  if ((width!=0) || (height!=0))
157  {
158  // can use that texture
159  os<<"\t"<<level<<". level dim: "<<width<<"x"<<height<<endl;
160  }
161  }
162 }
163 
164 
165 void GeometryGL::GetInfoGLTexObjects(std::ostream & os)
166 {
167  int foundTextures=0;
168  for (unsigned int id=0; id<MAX_GL_TEXOBJ_ID; id++)
169  {
170  GetInfoGLTexID(id, foundTextures, os);
171  }
172  os<<"** found a total of "<<foundTextures<<" validtextures/IDs <MAX_GL_TEXOBJ_ID="<<MAX_GL_TEXOBJ_ID<<" **"<<endl;
173 }
174 
175 
176 // TODO implement as macro: JW
177 void GeometryGL::GetInfoGLenvironment(std::ostream & os)
178 {
179  // get OpenGL info strings into std. strings:
180  if ( NULL==(char *) glGetString(GL_VENDOR)) {
181  BIASERR("No Context available (NULL ptr). Skipping RenderGL::GetInfo."<<endl<<flush);;
182  //CheckGLError();
183  return;
184  };
185 #ifdef BIAS_HAVE_GLEW
186  string strGlewVersion = (char*) glewGetString(GLEW_VERSION);
187 #endif // BIAS_HAVE_GLEW
188  string strVendor = (char *) glGetString(GL_VENDOR);
189  string strRenderer = (char *) glGetString(GL_RENDERER);
190  string strVersion = (char *) glGetString(GL_VERSION);
191  string strExtensions = (char *) glGetString(GL_EXTENSIONS);
192  //strExtensions = (char*) wglGetExtensionsStringARB();
193  // replace blank by newline:
194  unsigned int index = 0;
195  while ((index = strExtensions.find(' ', index)) != string::npos)
196  strExtensions[index++] = '\n';
197 
198  // only on Win32
199  string strWglExtensions;
200 #ifdef WIN32
201 # ifdef BIAS_HAVE_GLEW
202  if (WGLEW_EXT_extensions_string)
203  {
204  strWglExtensions = (char*) wglGetExtensionsStringEXT();
205  CHECK_GL_ERROR;
206  // replace blank by newline:
207  index = 0;
208  while ((index = strWglExtensions.find(' ', index)) != string::npos)
209  strWglExtensions[index++]='\n';
210  };
211 # endif // BIAS_HAVE_GLEW
212 #endif // WIN32
213 
214  GLint max_texture_units=0;
215 #if defined(BIAS_HAVE_GLEW)
216  glGetIntegerv(GL_MAX_TEXTURE_UNITS, &max_texture_units);
217  //CHECK_GL_ERROR;
218 #endif
219 
220  GLint max_texture_image_units=0;
221 #ifdef BIAS_HAVE_GLEW
222  glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &max_texture_image_units);
223 #endif // BIAS_HAVE_GLEW
224 
225 
226 //#if defined(BIAS_HAVE_GLEW)
227 // GLint max_general_combiners=0;
228 // glGetIntegerv(GL_MAX_GENERAL_COMBINERS_NV, &max_general_combiners);
229 //#endif
230  //CHECK_GL_ERROR;
231  //GLint max_vertex_units;
232  //glGetIntegerv(GL_MAX_VERTEX_UNITS_ARB, &max_vertex_units);
233  //CHECK_GL_ERROR;
234  //GLint max_vertex_shader_instructions;
235  //glGetIntegerv(GL_MAX_VERTEX_SHADER_INSTRUCTIONS_EXT, &max_vertex_shader_instructions);
236  //CHECK_GL_ERROR;
237 
238  GLint red_bits;
239  glGetIntegerv(GL_RED_BITS, &red_bits);
240  GLint green_bits;
241  glGetIntegerv(GL_GREEN_BITS, &green_bits);
242  GLint blue_bits;
243  glGetIntegerv(GL_BLUE_BITS, &blue_bits);
244  GLint alpha_bits;
245  glGetIntegerv(GL_ALPHA_BITS, &alpha_bits);
246  GLfloat alpha_bias;
247  glGetFloatv(GL_ALPHA_BIAS, &alpha_bias);
248  GLfloat alpha_scale;
249  glGetFloatv(GL_ALPHA_SCALE, &alpha_scale);
250  GLboolean cull_face;
251  glGetBooleanv(GL_CULL_FACE, &cull_face);
252  GLfloat depth_scale;
253  glGetFloatv(GL_DEPTH_SCALE, &depth_scale);
254  GLint depth_bits;
255  glGetIntegerv(GL_DEPTH_BITS, &depth_bits);
256  GLfloat depth_bias;
257  glGetFloatv(GL_DEPTH_BIAS, &depth_bias);
258  GLfloat depth_range[2];
259  glGetFloatv(GL_DEPTH_BIAS, &depth_range[0]);
260  GLfloat depth_clear_value;
261  glGetFloatv(GL_DEPTH_CLEAR_VALUE, &depth_clear_value);
262  GLboolean fog;
263  glGetBooleanv(GL_FOG, &fog);
264  GLfloat line_width;
265  glGetFloatv(GL_LINE_WIDTH, &line_width);
266  GLboolean lighting;
267  glGetBooleanv(GL_LIGHTING, &lighting);
268  GLint max_modelview_stack_depth;
269  glGetIntegerv(GL_MAX_MODELVIEW_STACK_DEPTH, &max_modelview_stack_depth);
270  GLint max_projection_stack_depth;
271  glGetIntegerv(GL_MAX_PROJECTION_STACK_DEPTH, &max_projection_stack_depth);
272  GLint max_texture_stack_depth;
273  glGetIntegerv(GL_MAX_TEXTURE_STACK_DEPTH, &max_texture_stack_depth);
274  GLint max_texture_size;
275  glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size);
276  GLint max_viewport_dims[2];
277  glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_viewport_dims[0]);
278  GLint name_stack_depth;
279  glGetIntegerv(GL_NAME_STACK_DEPTH, &name_stack_depth);
280  GLint max_name_stack_depth;
281  glGetIntegerv(GL_MAX_NAME_STACK_DEPTH, &max_name_stack_depth);
282  GLint point_size;
283  glGetIntegerv(GL_POINT_SIZE, &point_size);
284  GLint point_size_range[2];
285  glGetIntegerv(GL_POINT_SIZE_RANGE, &point_size_range[0]);
286  GLboolean rgba_mode;
287  glGetBooleanv(GL_RGBA_MODE, &rgba_mode);
288  GLboolean stencil_test;
289  glGetBooleanv(GL_STENCIL_TEST, &stencil_test);
290  GLint stencil_bits;
291  glGetIntegerv(GL_STENCIL_BITS, &stencil_bits);
292 
293  GLint draw_buffer;
294  glGetIntegerv(GL_DRAW_BUFFER, &draw_buffer);
295  GLint aux_buffers;
296  glGetIntegerv(GL_AUX_BUFFERS, &aux_buffers);
297  GLboolean double_buffer;
298  glGetBooleanv(GL_DOUBLEBUFFER, &double_buffer);
299  GLboolean stereo;
300  glGetBooleanv(GL_STEREO, &stereo);
301  GLint polygon_mode[2];
302  glGetIntegerv(GL_POLYGON_MODE, &polygon_mode[0]);
303  GLint max_cube_map_texture_size=0;
304 #if defined(BIAS_HAVE_GLEW)
305  glGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE_EXT, &max_cube_map_texture_size);
306 #endif
307 
308  GLint viewport[4];
309  glGetIntegerv(GL_VIEWPORT, &viewport[0]);
310  CHECK_GL_ERROR;
311 
312  GLint max_texture_lod_bias=0;
313 #if defined(BIAS_HAVE_GLEW)
314  glGetIntegerv(GL_MAX_TEXTURE_LOD_BIAS_EXT, &max_texture_lod_bias);
315  //CHECK_GL_ERROR;
316 #endif
317 
318 
319  os << "Getting Info about OpenGL: " << endl;
320 #ifdef BIAS_HAVE_GLEW
321  os << "GLEW_VERSION = " << strGlewVersion << endl;
322 #endif // BIAS_HAVE_GLEW
323  os << "GL_VENDOR = " << strVendor << endl;
324  os << "GL_RENDERER = " << strRenderer << endl;
325  os << "GL_VERSION = " << strVersion << endl;
326  os << "* GL_EXTENSIONS: " << endl << strExtensions << endl;
327  os << "* WGL_EXTENSIONS: " << endl << strWglExtensions << endl;
328 
329  os << endl;
330 
331  os<<"GL_RED_BITS = "<<red_bits<<endl;
332  os<<"GL_GREEN_BITS= "<<green_bits<<endl;
333  os<<"GL_BLUE_BITS = "<<blue_bits<<endl;
334  os<<"GL_ALPHA_BITS= "<<alpha_bits<<endl;
335  os<<"GL_DEPTH_BITS ="<<depth_bits<<endl;
336  os<<"GL_STENCIL_BITS="<<stencil_bits<< endl;
337 
338  os << "GL_MAX_TEXTURE_UNITS= "<<max_texture_units<<" (detected texture units)" << endl;
339  os << "GL_MAX_TEXTURE_IMAGE_UNITS= " << max_texture_image_units <<endl;
340 //#if defined(BIAS_HAVE_GLEW)
341 // os << "GL_MAX_GENERAL_COMBINERS_NV= " << max_general_combiners<<endl;
342 //#endif
343  //os << "GL_MAX_VERTEX_UNITS = " << max_vertex_units <<" (detected vertex units)" << endl;
344  //os << "GL_MAX_VERTEX_SHADER_INSTRUCTIONS= "<<max_vertex_shader_instructions << endl;
345  os << "GL_ALPHA_SCALE = " << alpha_scale << endl;
346  os << "GL_ALPHA_BIAS = " << alpha_bias << endl;
347  os << "GL_CULL_FACE = " << GL2Cbool(cull_face) << endl;
348  os << "GL_STENCIL_TEST = " << GL2Cbool(stencil_test) << endl;
349  os << "GL_DEPTH_SCALE = " << depth_scale << endl;
350  os << "GL_DEPTH_BIAS = " << depth_bias << endl;
351  os << "GL_DEPTH_RANGE = " << depth_range[0] << " " <<depth_range[1] << endl;
352  os << "GL_DEPTH_CLEAR_VALUE= " << depth_clear_value << endl;
353  os << "GL_DRAW_BUFFER = " << GetName(draw_buffer)<<endl;
354  os << "GL_AUX_BUFFERS = " << aux_buffers <<endl;
355  os << "GL_DOUBLE_BUFFER = " << GL2Cbool(double_buffer)<<endl;
356  os << "GL_STEREO = " << GL2Cbool(stereo);
357  if (stereo) os<<" (but not neccessarily enabled)"<<endl;
358 
359  os << "GL_FOG = " << GL2Cbool(fog) << endl;
360  os << "GL_LINE_WIDTH = " << line_width << endl;
361  os << "GL_LIGHTING = " << GL2Cbool(lighting) << endl;
362  os << "GL_MAX_MODELVIEW_STACK_DEPTH = " <<max_modelview_stack_depth << endl;
363  os << "GL_MAX_PROJECTION_STACK_DEPTH= " <<max_projection_stack_depth << endl;
364  os << "GL_MAX_TEXTURE_LOD_BIAS_EXT = " << max_texture_lod_bias << endl;
365  os << "GL_MAX_TEXTURE_STACK_DEPTH = " << max_texture_stack_depth<< endl;
366  os << "GL_MAX_TEXTURE_SIZE = " << max_texture_size << endl;
367  os << "GL_MAX_VIEWPORT_DIMS= " << max_viewport_dims[0]
368  <<" "<<max_viewport_dims[1] << endl;
369  os << "GL_POINT_SIZE = " << point_size << endl;
370  os << "GL_POINT_SIZE_RANGE = " << point_size_range[0]
371  <<" "<<point_size_range[1] << endl;
372 
373  os << "GL_MAX_CUBE_MAP_TEXTURE_SIZE="<<max_cube_map_texture_size<<endl;
374 
375  os << "GL_MAX_NAME_STACK_DEPTH = " << max_name_stack_depth<<endl;
376  os << "GL_NAME_STACK_DEPTH = " << name_stack_depth<<endl;
377 
378  os << "GL_POLYGON_MODE = ("<<GetName(polygon_mode[0])<<", "<<GetName(polygon_mode[1])<<")"<<endl;
379  os << "GL_RGBA_MODE = " << GL2Cbool(rgba_mode) << endl;
380  os << "GL_VIEWPORT = x="<<viewport[0]<<" y="<<viewport[1]<<" w="<<viewport[2]<<" h="<<viewport[3]<<endl;
381 }
382 
383 
384 void GeometryGL::GetInfoGLWriteMasks(std::ostream & os)
385 {
386  // write masks
387  GLboolean depth_writemask;
388  glGetBooleanv(GL_DEPTH_WRITEMASK, &depth_writemask);
389 
390  GLboolean color_writemask[4] = {false,false,false,false};
391  glGetBooleanv(GL_COLOR_WRITEMASK, color_writemask);
392 
393  GLboolean stencil_writemask;
394  glGetBooleanv(GL_STENCIL_WRITEMASK, &stencil_writemask);
395 
396  GLboolean index_writemask;
397  glGetBooleanv(GL_INDEX_WRITEMASK, &index_writemask);
398 
399  os<<"GL_DEPTH_WRITEMASK = "<<depth_writemask<<endl;
400  os<<"GL_COLOR_WRITEMASK = "
401  <<color_writemask[0]<<" "
402  <<color_writemask[1]<<" "
403  <<color_writemask[2]<<" "
404  <<color_writemask[3]<<" "
405  <<endl;
406  os<<"GL_STENCIL_WRITEMASK = "<<stencil_writemask<<endl;
407  os<<"GL_INDEX_WRITEMASK = "<<index_writemask<<endl;
408 }
409 
410 
411 void GeometryGL::GetInfoGL(std::ostream & os)
412 {
413  GetInfoGLenvironment(os);
414  GetInfoGLWriteMasks(os);
415  GetInfoGLmatrices(os);
416  GetInfoGLDisplayLists(os);
417  GetInfoGLTexObjects(os);
418 
419  glGetError();
420 }
421 
422 
423 // static
424 void GeometryGL::DisplayClear(const GLbitfield & mask)
425 {
426  CHECK_GL_ERROR;
427 
428  // set values for clear:
429  glClearColor(0, 0, 0, 0); // rgba [0,1]
430  glClearDepth(1.0);
431  glClearAccum(0,0,0,0);
432  glClearStencil(0);
433  glClearIndex(0);
434 
435  glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // no color mask RGBA
436 
437  // perform clear operation:
438  //glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_ACCUM_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
439  glClear( mask );
440 
441  // set gl states (on or off)
442  glDisable(GL_ALPHA_TEST);
443  glDisable(GL_LIGHTING);
444 
445  // counter clockwise on screen is front face:
446  glFrontFace(GL_CCW);
447  glDisable(GL_CULL_FACE);
448  glDisable(GL_FOG);
449  glDisable(GL_NORMALIZE); // just for glNormal
450 
451  //glDisable(GL_DEPTH_TEST);
452  glEnable(GL_DEPTH_TEST);
453 
454  glDisable(GL_BLEND);
455 
456  glDisable(GL_STENCIL_TEST);
457  //glEnable(GL_STENCIL_TEST);
458 
459  glDisable(GL_TEXTURE_2D);
460  //glDisable(GL_TEXTURE_RECTANGLE_NV); // non-pow2 textures?
461 
462  // set compare functions
463  glDepthFunc(GL_LEQUAL);
464  glAlphaFunc(GL_LEQUAL, (GLclampf)1 );
465 
466  // set matrices:
467  glMatrixMode(GL_PROJECTION);
468  glLoadIdentity();
469  glMatrixMode(GL_TEXTURE);
470  glLoadIdentity();
471  glMatrixMode(GL_MODELVIEW);
472  glLoadIdentity();
473 
474  CHECK_GL_ERROR;
475 }
476 
477 
479 {
480  CHECK_GL_ERROR;
481  glPolygonMode(GL_FRONT, m.polygonmodeFRONT);
482  glPolygonMode(GL_BACK, m.polygonmodeBACK);
483 
484  glShadeModel(m.shademodel);
485 
486  glEnable(GL_CULL_FACE);
487  glCullFace(m.cullface);
488  if (m.enable_cullface) {
489  glEnable(GL_CULL_FACE);
490  } else {
491  glDisable(GL_CULL_FACE);
492  };
493 
494  glPointSize(m.pointsize);
495  glLineWidth(m.linewidth);
496 
497  CHECK_GL_ERROR;
498 }
499 
500 
501 void
503 {
504  //COUT("DBG time="<<time<<endl);
505 
506  // animation: rotate depending on current time
507  glRotated(
508  time, /*angle*/
509  0,1,1 /* axis */
510  );
511 
512  DisplaySceneExampleSimple();
513 }
514 
515 
516 void
518 {
519  // A simple scene not using push or pop
520  glDisable(GL_LIGHTING); // may be switched on/off for every object
521  glEnable(GL_DEPTH_TEST); // depth buffer occlusions of objects
522  glShadeModel(GL_SMOOTH);
523 
524  const float z = 1.0f;
525  const float xd= 0.9f; // x dimension
526  const float yd= 0.9f; // y dimension
527 
528  // 3 2
529  // 0 1
530  BIAS::Vector3<float> p0(-xd, -yd, z);
531  BIAS::Vector3<float> p1( xd, -yd, z);
532  BIAS::Vector3<float> p2( xd, yd, z);
533  BIAS::Vector3<float> p3(-xd, yd, z);
534 
535  {
536  glBegin(GL_QUADS);
537  glColor3f(1,0,0); // red 0
538  glVertex3fv( &(p0[0]));
539 
540  glColor3f(0,1,0); // green 1
541  glVertex3fv( &(p1[0]));
542 
543  glColor3f(0,0,1); // blue 2
544  glVertex3fv( &(p2[0]));
545 
546  glColor3f(1,1,1); // white 3
547  glVertex3fv( &(p3[0]));
548  glEnd();
549 
551  }
552  CHECK_GL_ERROR;
553 }
554 
555 #ifdef BIAS_HAVE_FONTGL
556 void GeometryGL::DisplayCoordCross(const float & size,
557  const float & linewidth,
558  const BIAS::DrawTextGL & font,
559  const std::string & LabelX,
560  const std::string & LabelY,
561  const std::string & LabelZ )
562 {
563  DisplayCoordCrossAxesLabel(size, font, LabelX, LabelY, LabelZ);
564  DisplayCoordCross(size, linewidth);
565 }
566 
567 
569  const DrawTextGL & font,
570  const std::string & LabelX,
571  const std::string & LabelY,
572  const std::string & LabelZ )
573 {
574  if (!font.IsInitialized()) {
575  BIASERR("font not initialized. Please do it on your OpenGLCanvas (because of the context). aborting");
576  return;
577  }
578  // X
579  glColor3f(
580  1.0f, 0.0f, 0.0f);
581  font.Print3D(LabelX,
582  size, 0.0f, 0.0f);
583 
584  // Y
585  glColor3f(
586  0.0f, 1.0f, 0.0f);
587  font.Print3D(LabelY,
588  0.0f, size, 0.0f);
589 
590  // Z
591  glColor3f(
592  0.0f, 0.0f, 1.0f);
593  font.Print3D(LabelZ,
594  0.0f, 0.0f, size);
595 }
596 #endif //BIAS_HAVE_FONTGL
597 
598 void GeometryGL::DisplayCoordCross(const float & size,
599  const float & linewidth )
600 {
601 
602  // X-axis:
603  glDisable(GL_TEXTURE_2D);
604  glDisable(GL_LIGHTING);
605 
606  if ((linewidth>=1.0) && (linewidth<32.0))
607  glLineWidth((GLfloat)linewidth);
608  else
609  glLineWidth((GLfloat)1.0);
610 
611  glColor4f(1,0,0, VISIBLEALPHA); // r
612  glBegin(GL_LINES);
613  glVertex3f(0,0,0);
614  glVertex3f(size,0,0);
615  glEnd();
616  // Y-axis:
617  glColor4f(0,1,0, VISIBLEALPHA); // g
618  glBegin(GL_LINES);
619  glVertex3f(0,0,0);
620  glVertex3f(0,size,0);
621  glEnd();
622  // Z-axis:
623  glColor4f(0,0,1, VISIBLEALPHA); // r
624  glBegin(GL_LINES);
625  glVertex3f(0,0,0);
626  glVertex3f(0,0,size);
627  glEnd();
628 }
629 
630 
631 
632 void
634  const int & x0,
635  const int & y0,
636  const unsigned int & width,
637  const unsigned int & height,
638  const float & fovY,
639  const float & zNear,
640  const float & zFar )
641 {
642  BIASASSERT(width>=0);
643  BIASASSERT(height>=0);
644  BIASASSERT(fovY>0.0);// min. field of view Y (in deg.)
645  BIASASSERT(fovY<180.0); // max field of view Y (in deg.)
646 
647  glMatrixMode(GL_PROJECTION);
648  glLoadIdentity();
649 
650  float aspect=1.0;
651  if ((height==0) || (width==0)) {
652  // degenerate case
653  aspect = 1.0;
654  } else {
655  aspect = (float)width/(float)height;
656  };
657  //COUT("DBG aspect w/h = "<<aspect<<endl);
658  gluPerspective(fovY,
659  aspect,
660  zNear, zFar);
661 
662  // pixel rasterization=which part of image plane: origin, w, h
663  glViewport((GLint)x0, (GLint)y0,
664  (GLsizei)width, (GLsizei)height);
665 
666 }
667 
668 
669 
672  P.GetC()
673  ,P.GetV() // P.GetUp_gl()
674  ,P.GetA()
675  );
676 }
677 
678 
680  const BIAS::Vector3<double> & up,
681  const BIAS::Vector3<double> & a )
682 {
683  // pose and orientation of the camera (where is it looking at)
684  Vector3<double> viewAt = C + a;
685 
686  glMatrixMode(GL_MODELVIEW);
687  glLoadIdentity();
688  gluLookAt((GLdouble)C[0],
689  (GLdouble)C[1],
690  (GLdouble)C[2],
691  (GLdouble)viewAt[0],
692  (GLdouble)viewAt[1],
693  (GLdouble)viewAt[2],
694  (GLdouble)up[0],
695  (GLdouble)up[1],
696  (GLdouble)up[2]
697  );
698 }
699 
700 
702 GeometryGL::GetImgCorner2d( const unsigned int & w
703  ,const unsigned int & h
704  ,const unsigned int & corner
705  ,const int texMode
706  ,const bool flipY )
707 {
708  float width = 1.0;
709  float height= 1.0;
710 
711 #if defined(BIAS_HAVE_GLEW)
712  if (texMode==GL_TEXTURE_RECTANGLE_NV)
713  {
714  // TexRECT has pixel coordinates NOT normalized and possibly non-pow2
715  // texRect dim is in pixel, e.g. 0..1024
716  width = float( w );
717  height = float( h );
718  } else
719 #endif
720  {
721  // pow2 texture has normalized coordinates
722  // assign the fractional (filled) part.
723  BIASASSERT(w <= BIAS::ImageBase::PowerOfTwoSize(w) );
724  BIASASSERT(h <= BIAS::ImageBase::PowerOfTwoSize(h) );
725  width = float(w) / float(BIAS::ImageBase::PowerOfTwoSize(w));
726  //float tmp = BIAS::ImageBase::PowerOfTwoSize(h);
727  height = float(h) / float(BIAS::ImageBase::PowerOfTwoSize(h));
728  };
729  BIASASSERT(0<width);
730  BIASASSERT(0<height);
731 
732  // return texture coordinates in OpenGL coordinate system
733  switch (corner)
734  {
735  case LOWER_LEFT:
736  if (flipY) return Vector2<double>(0.0, height);
737  return Vector2<double>(0.0, 0.0);
738  break;
739  case LOWER_RIGHT:
740  if (flipY) return Vector2<double>(width, height);
741  return Vector2<double>(width, 0.0);
742  break;
743  case UPPER_RIGHT:
744  if (flipY) return Vector2<double>(width, 0.0);
745  return Vector2<double>(width, height);
746  break;
747  case UPPER_LEFT:
748  if (flipY) return Vector2<double>(0.0, 0.0);
749  return Vector2<double>(0.0, height);
750  break;
751  default:
752  BIASERR("corner="<<corner<<" invalid."<<endl);
753  return Vector2<double>(0.0, 0.0);
754  };
755 }
756 
757 
758 /** compute 3D pos. of P in OpenGL coordinate system
759 TODO: move this to PMatrix with addition imgDim parameter JW */
762  ,const unsigned int & w
763  ,const unsigned int & h
764  ,const unsigned int & corner
765  ,const double & scale )
766 {
767  HomgPoint2D p2d(0,0, 1);
768  BIAS::Vector3<double> p3d(0,0,0);
769 
770  // these pixel coordinates are in MIP coordinaet system:
771  switch (corner)
772  {
773  case LOWER_LEFT:
774  p2d.Set(0,h, 1);
775  break;
776  case LOWER_RIGHT:
777  p2d.Set(w,h, 1);
778  break;
779  case UPPER_RIGHT:
780  p2d.Set(w,0, 1);
781  break;
782  case UPPER_LEFT:
783  p2d.Set(0,0, 1);
784  break;
785  case OPTICAL_CENTER:
786  p2d.Set( P.GetK().GetHx()
787  ,P.GetK().GetHy()
788  ,1);
789  break;
790  default:
791  BIASERR("corner="<<corner<<" invalid."<<endl);
792  return p3d;
793  };
794 
795  Vector3< double > dir; // vector from C to 3D point
796  dir = P.GetRayWorldCoo(p2d);
797  dir.Normalize(); // length 1
798  p3d = P.GetC() + scale * dir;
799 
800  return p3d;
801 }
802 
803 
805  ,const unsigned int & w
806  ,const unsigned int & h
807  ,const int & texID
808  ,const int & texTarget
809  ,const double & scale
810  ,const bool & flipY
811  ,const BIAS::Vector4<float> & vertexColor)
812 {
813  // Display the image plane at a distant scale from projection center textured:
814  BIASASSERT( GL_TRUE == glIsTexture( texID ) ); // success ?
815  glEnable( texTarget );
816  glBindTexture(texTarget, texID );
817  //glActiveTexture(GL_TEXTURE0);
818  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
819  CHECK_GL_ERROR;
820 
821  // fancy pink in case of texturing error:
822  //glColor4d(1.0, 0.0, 1.0, VISIBLEALPHA);
823  glColor4fv( & vertexColor[0] );
824  glBegin(GL_QUADS);
825  glTexCoord2dv( & GetImgCorner2d(w,h, LOWER_LEFT, texTarget, flipY)[0] );
826  glVertex3dv( & GetImgCorner3d(P,w,h, LOWER_LEFT, scale)[0]);
827 
828  glTexCoord2dv( & GetImgCorner2d(w,h, LOWER_RIGHT, texTarget, flipY)[0] );
829  glVertex3dv( & GetImgCorner3d(P,w,h, LOWER_RIGHT, scale)[0] );
830 
831  glTexCoord2dv( & GetImgCorner2d(w,h, UPPER_RIGHT, texTarget, flipY)[0] );
832  glVertex3dv( & GetImgCorner3d(P,w,h, UPPER_RIGHT, scale)[0] );
833 
834  glTexCoord2dv( & GetImgCorner2d(w,h, UPPER_LEFT, texTarget, flipY)[0] );
835  glVertex3dv( & GetImgCorner3d(P,w,h, UPPER_LEFT, scale)[0] );
836  glEnd();
837 }
838 
839 
840 
841 
843  ,const unsigned int & w
844  ,const unsigned int & h
845  ,const double & scale
846  ,const float & linewidth
847  )
848 {
849  //Vector3<double> C(0,0,0);
850  Vector3<double> C( P.GetC() );
851 
852  const float alpha = VISIBLEALPHA;
853 
854  // Display textured image plane
855  //DisplayImgPlaneTextured(cam, scale);
856 
857  glDisable(GL_TEXTURE_2D);
858  glLineWidth(linewidth);
859 
860  // rectangle between image corners
861  glBegin(GL_LINE_LOOP);
862  glColor4f(0,1,0, alpha); // plane corners green
863  glVertex4d( GetImgCorner3d(P,w,h, LOWER_LEFT, scale)[0],
864  GetImgCorner3d(P,w,h, LOWER_LEFT, scale)[1],
865  GetImgCorner3d(P,w,h, LOWER_LEFT, scale)[2],
866  1.0
867  );
868 
869  //glVertex3dv( & GetImgCorner3d(P,w,h, LOWER_LEFT, scale)[0] );
870  glVertex3dv( & GetImgCorner3d(P,w,h, LOWER_RIGHT,scale)[0] );
871  glVertex3dv( & GetImgCorner3d(P,w,h, UPPER_RIGHT,scale)[0] );
872  glVertex3dv( & GetImgCorner3d(P,w,h, UPPER_LEFT, scale)[0] );
873  glEnd();
874 
875  glBegin(GL_LINES);
876  // Display view vector from red=C=eye=red to center=blue
877  glColor4f(1,0,0, alpha); // eye=red
878  glVertex3dv( & C[0] );
879  glColor4f(0,0,1, alpha); // blue
880  glVertex3dv( & GetImgCorner3d(P,w,h, OPTICAL_CENTER, scale)[0] );
881 
882  // connect eye=center to all 4 corners
883  glColor4f(0,1,0, alpha); // plane corners green
884  glVertex3dv( & GetImgCorner3d(P,w,h, LOWER_LEFT, scale)[0] );
885  glColor4f(1,0,0, alpha); // center=red
886  glVertex3dv( & C[0] );
887 
888  glColor4f(0,1,0, alpha); // plane corners green
889  glVertex3dv( & GetImgCorner3d(P,w,h, LOWER_RIGHT, scale)[0] );
890  glColor4f(1,0,0, alpha); // center=red
891  glVertex3dv( & C[0] );
892 
893  glColor4f(0,1,0, alpha); // plane corners green
894  glVertex3dv( & GetImgCorner3d(P,w,h, UPPER_LEFT, scale)[0] );
895  glColor4f(1,0,0, alpha); // center=red
896  glVertex3dv( & C[0] );
897 
898  glColor4f(0,1,0, alpha); // plane corners green
899  glVertex3dv( & GetImgCorner3d(P,w,h, UPPER_RIGHT, scale)[0] );
900  glColor4f(1,0,0, alpha); // center=red
901  glVertex3dv( & C[0] );
902  glEnd();
903 }
904 
905 
906 
909  ,const unsigned int w
910  ,const unsigned int h
911  ,const bool & useRECTcoord )
912 {
913  Matrix4x4<double> result;
914  result.SetIdentity();
915 
916  // HACK: determine next pow2 depending on RECT or POW2 texture.
917  //Vector2<unsigned int> RescaledDimension(1024,768);
918 
919  // scaleMatrix for normalization
920  Matrix3x3<double> Mat;
921  Mat.SetIdentity();
922  //Mat[0][2] = 1.0; //hx
923  //Mat[1][2] = 1.0; //hy
924 
925  // normalized power of two coords required (RECT otherwise)
926  if (!useRECTcoord ) {
927  Mat[0][0] = 1.0/w;
928  Mat[1][1] = 1.0/h;
929  //Mat[0][2] = 1.0/w;
930  //Mat[1][2] = 1.0/h;
931  }
932 
933  // transform workaround...
934  Matrix3x4<double> newP;
935  newP = Mat * P;
936 
937  // create transposed special 4x4 marix of PTexture
938  // for OpenGL
939  // old line 2 will become 3 (for projective comp.)
940  // new line 2 will be filled with 0 to removed z-component
941  for (int s=0; s<4; s++) {
942  result[0][s] = newP[0][s];
943  result[1][s] = newP[1][s];
944  result[2][s] = 0.0;
945  result[3][s] = newP[2][s];
946  }
947 
948  // normalize all elements by W (lower right)
949  result /= result[3][3];
950 
951  return result;
952 }
953 
954 
955 
957  const bool & additionalFlipY)
958 {
959  glMatrixMode(GL_MODELVIEW);
960  glPushMatrix();
961  glLoadIdentity();
962  {
963  glMatrixMode(GL_PROJECTION);
964  glLoadIdentity();
965  glPushMatrix();
966  {
967  DisplayQuadTexCoord2D(texobj, additionalFlipY);
968  }
969  glMatrixMode(GL_PROJECTION);
970  glPopMatrix();
971  }
972  glMatrixMode(GL_MODELVIEW);
973  glPopMatrix();
974 }
975 
977  const bool & additionalFlipY)
978 {
979  CHECK_GL_ERROR;
980  BIASASSERT(texobj.widthOrig>0);
981  BIASASSERT(texobj.heightOrig>0);
982  BIASASSERT(glIsTexture(texobj.id));
983  CHECK_GL_ERROR;
984 
985  // pow2 texture dim is normalized to 0..1
986  float width = 1.0f;
987  float height= 1.0f;
988 
989  if (texobj.IsRectangleTexture()){
990  // texRect dim is in pixel, e.g. 0..1024
991  width = (float) texobj.widthOrig;
992  height = (float) texobj.heightOrig;
993  } else
994  //if (texobj.IsTexture2D())
995  {
996  // pow2 texture which may be used partially, only.
997  //width = 1.0f;
998  //height= 1.0f;
999  width = float(texobj.widthOrig) / float(texobj.widthBrutto);
1000  height= float(texobj.heightOrig) / float(texobj.heightBrutto);
1001  //} else {
1002  // BIASERR("unsupported. Neither RECT nor 2D texture.");
1003  // BIASBREAK;
1004  }
1005  // 3 2
1006  // 0 1
1007  BIAS::Vector2<float> tc0, tc1, tc2, tc3; // 2d RECT texcoords
1008  if (!additionalFlipY) {
1009  // OpenGL orientation Y up (=Y is NOT flipped)
1010  tc0.Set(0, 0 );
1011  tc1.Set( width, 0 );
1012  tc2.Set( width, height);
1013  tc3.Set( 0, height);
1014  } else {
1015  // y is flipped (MIP img orientation)
1016  tc0.Set(0, height );
1017  tc1.Set( width, height );
1018  tc2.Set( width, 0);
1019  tc3.Set( 0, 0);
1020  };
1021 
1022  // enable texture mapping:
1023  //glPushAttrib( texobj.target );
1024 
1025 #ifdef BIAS_HAVE_GLEW
1026  glActiveTexture( GL_TEXTURE0 );
1027 #endif // BIAS_HAVE_GLEW
1028  // the rest of multitexturing is left to the caller
1029  glEnable( texobj.target );
1030  glBindTexture(texobj.target, texobj.id );
1031  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
1032  CHECK_GL_ERROR;
1033  glTexParameteri(texobj.target, GL_TEXTURE_MIN_FILTER, texobj.minificationMode);
1034  glTexParameteri(texobj.target, GL_TEXTURE_MAG_FILTER, texobj.magnificationMode);
1035  CHECK_GL_ERROR;
1036 
1037  glColor3f(1, 1, 0); // pink - fallback color
1038  //const float z = -1.0;
1039  const float z = 0;
1040 
1041 #ifdef BIAS_HAVE_GLEW
1042  // for multitexturing:
1043  const unsigned int maxTU=4;
1044  unsigned int i=0;
1045 #endif // BIAS_HAVE_GLEW
1046 
1047  glBegin(GL_QUADS);
1048  glTexCoord2fv( &tc0[0] );
1049 #ifdef BIAS_HAVE_GLEW
1050  for (i=0; i<maxTU;i++)
1051  glMultiTexCoord2fv(GL_TEXTURE0+i, &tc0[0]);
1052 #endif // BIAS_HAVE_GLEW
1053  glVertex3f(-1,-1, z);
1054  glTexCoord2fv(&tc1[0]);
1055 #ifdef BIAS_HAVE_GLEW
1056  for (i=0; i<maxTU;i++)
1057  glMultiTexCoord2fv(GL_TEXTURE0+i, &tc1[0]);
1058 #endif // BIAS_HAVE_GLEW
1059  glVertex3f( 1,-1, z);
1060  glTexCoord2fv(&tc2[0]);
1061 #ifdef BIAS_HAVE_GLEW
1062  for (i=0; i<maxTU;i++)
1063  glMultiTexCoord2fv(GL_TEXTURE0+i, &tc2[0]);
1064 #endif // BIAS_HAVE_GLEW
1065  glVertex3f( 1, 1, z);
1066  glTexCoord2fv(&tc3[0]);
1067 #ifdef BIAS_HAVE_GLEW
1068  for (i=0; i<maxTU;i++)
1069  glMultiTexCoord2fv(GL_TEXTURE0+i, &tc3[0]);
1070 #endif // BIAS_HAVE_GLEW
1071  glVertex3f(-1, 1, z);
1072  glEnd();
1073  // texmapping done.
1074  //glPopAttrib();
1075  glDisable( texobj.target );
1076 
1077  CHECK_GL_ERROR;
1078 }
1079 
1080 
1082 {
1083 #ifndef BIAS_HAVE_GLUT
1084  BIASERR("not implemented without glut, please recompile BIAS with USE_GLUT to see a a fancy dispal ylist scene !");
1085  dplistID=0;
1086 #else // BIAS_HAVE_GLUT
1087 
1088  // init once:
1089  static bool initDone=false;
1090  if(initDone)
1091  return;
1092 
1093  // do init
1094  CHECK_GL_ERROR;
1095  // example for an OpenGL display list
1096  dplistID = glGenLists(1); // identifier
1097  glNewList(dplistID, GL_COMPILE ); // or: GL_COMPILE_AND_EXECUTE
1098  {
1099  // light source proeprties for enabled lighting:
1100  // specified pos by w=1, direction by w=0:
1101  GLfloat light_position0[] = {10.0f, 10.0, 10.0f, 0.0f}; // w=0: direction
1102  GLfloat light_maincolor0[] = {1.0f, 1.0, 1.0f, 1.0f};
1103  GLfloat light_ambientcolor0[] = {0.4f, 0.2f, 0.2f, 1.0f};
1104 
1105  // GL create light 0
1106  glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
1107  glLightfv(GL_LIGHT0, GL_DIFFUSE, light_maincolor0);
1108  glLightfv(GL_LIGHT0, GL_SPECULAR, light_maincolor0);
1109  glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambientcolor0);
1110 
1111  glEnable(GL_LIGHT0);
1112  glEnable(GL_LIGHTING); // may be switched on/off for every object
1113  glEnable(GL_DEPTH_TEST); // depth buffer occlusions of objects
1114 
1115  // material properties for enabled lighting:
1116  GLfloat paintcolor0[] = { 0.9, 0.2, 0.5, 1.0};
1117  GLfloat specularcolor0[] = { 1.0, 1.0, 1.0, 1.0};
1118  GLfloat shininess0[] = { 70. }; // 1..128, large values make smaller specular highlights
1119 
1120  GLfloat paintcolor1[] = { 0.3, 0.9, 0.4, 1.0};
1121  GLfloat paintcolor2[] = { 0.1, 0.2, 0.9, 0.5};
1122  GLfloat paintcolor3[] = { 0.5, 0.0, 0.5, 1.0};
1123 
1124  glMatrixMode(GL_MODELVIEW);
1125  glPushMatrix();
1126 
1127  //// activate material properties:
1128  glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, specularcolor0);
1129  glMaterialfv( GL_FRONT_AND_BACK, GL_SHININESS, shininess0);
1130  glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE,
1131  paintcolor0);
1132  glColor4fv(paintcolor0);
1133 
1134  // draw geometry
1135  BIAS::Vector3<float> dtea(-0.5,-0.2,0);
1136  // position of the scene "modeling" matrix
1137  glTranslatef( dtea[0], dtea[1], dtea[2] );
1138  // teapot has strange vertex ordering for historical reasons
1139  glFrontFace(GL_CW);
1140  glutSolidTeapot(0.6);
1141  glFrontFace(GL_CCW);
1142 
1143  glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE,
1144  paintcolor1 );
1145  glColor4fv(paintcolor1);
1146 
1147  glTranslatef( -2*dtea[0], -2*dtea[1], -2*dtea[2] );
1148  glFrontFace(GL_CW);
1149  glutSolidTeapot(0.3);
1150  glFrontFace(GL_CCW);
1151  glTranslatef( dtea[0], dtea[1], dtea[2] );
1152  // back on origin
1153 
1154  // activate material properties:
1155  glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, paintcolor2);
1156  glColor4fv(paintcolor2);
1157 
1158  glTranslatef(0,0,-2);
1159  glutSolidSphere(0.8, 30, 60);
1160  glTranslatef(0,0, 2); // back to origin
1161 
1162  glTranslatef( 1,0,-3);
1163  glutSolidSphere(0.5, 50, 100);
1164  glTranslatef(-1,0, 3);// back to origin
1165 
1166 
1167  glTranslatef(0,2,0);
1168  glutSolidCube(0.7);
1169  glTranslatef(0,-2,0);
1170 
1171  glTranslatef(0,-1,0);
1172  glutSolidIcosahedron();
1173  glTranslatef(0, 1,0);
1174 
1175  glTranslatef(0,-2.2,0);
1176  glutSolidTetrahedron();
1177  glTranslatef(0, 2.2,0);
1178 
1179  // environment sphere to demonstrate back face
1180  glColor4fv( paintcolor3 );
1181  glutSolidSphere(75.0, 50, 100);
1182 
1183  glPopMatrix();
1184  }
1185  glEndList();
1186 
1187  CHECK_GL_ERROR;
1188  initDone=true;
1189 #endif // BIAS_HAVE_GLUT
1190 }
1191 
1192 
1194 {
1195  //CALLINFO;
1196  CHECK_GL_ERROR;
1197  static int dplist = -1;
1198 
1199  // setup scenen as one displaylist
1201 
1202 
1203  CHECK_GL_ERROR;
1204  {
1205  if(glIsList(dplist) == GL_TRUE)
1206  {
1207  // animation: rotate the scene (not the camera) by using global time as angle:
1208  // thus light and camera stay in the same place
1209  {
1210  const float cycletime=10.0; // approx. sec for a full cycle
1211  const float angleM = fmodf( float(2.0*360.0/cycletime *curTime), 2.0*360.0);
1212  if (angleM<=360.0){
1213  glRotatef( angleM, 0.0f, 1.0f, 0.0f );
1214  } else {
1215  glRotatef( angleM-360.0f, 1.0f, 0.0f, 0.0f );
1216  }
1217  }
1218 
1219  //// interpolate between vertices
1220  //glShadeModel(GL_SMOOTH);
1221  glCallList(dplist);
1222 
1223  // no interpolation between vertices
1224  //glTranslatef(0.3,0.2,0.2);
1225  //glShadeModel(GL_FLAT);
1226  //glCallList(dplist);
1227 
1228  DisplayCoordCross();
1229 
1230  } else {
1231  BIASERR("invalid display list dplist="<<dplist);
1232  }
1233 
1234  //glPopAttrib();
1235  }
1236 }
1237 
1238 
1239 
1240 // convert flag from define into string with preprocessor
1241 #define GLS(_flag) case _flag: {s=string(#_flag); break;}
1242 
1243 std::string GeometryGL::GetName(const GLint flag,
1244  const bool withNumericDisplay,
1245  const bool numerixHexFormat )
1246 {
1247  // catch special non verbose defs
1248  if(flag==0) // GL_FALSE
1249  return string("0");
1250 
1251  std::string s;
1252  bool unknownFlag=false;
1253  /// TODO \todo extract all OpenGL defines from gl.h/glew.h with regular expression.
1254  switch(flag)
1255  {
1256  GLS(GL_TRUE);
1257  GLS(GL_FRONT_LEFT);
1258  GLS(GL_FRONT_RIGHT);
1259  GLS(GL_BACK_LEFT );
1260  GLS(GL_BACK_RIGHT);
1261  GLS(GL_FRONT);
1262  GLS(GL_BACK);
1263  GLS(GL_LEFT);
1264  GLS(GL_RIGHT);
1265  GLS(GL_FRONT_AND_BACK);
1266  GLS(GL_POINT);
1267  GLS(GL_LINE);
1268  GLS(GL_FILL);
1269  GLS(GL_BYTE);
1270  GLS(GL_SHORT);
1271  GLS(GL_INT);
1272  GLS(GL_FLOAT);
1273  GLS(GL_DOUBLE);
1274  GLS(GL_TEXTURE_INTERNAL_FORMAT);
1275  GLS(GL_TEXTURE_BORDER_COLOR);
1276  GLS(GL_TEXTURE_BORDER);
1277  GLS(GL_DONT_CARE);
1278  GLS(GL_FASTEST);
1279  GLS(GL_NICEST);
1280  GLS(GL_COMPILE);
1281  GLS(GL_COMPILE_AND_EXECUTE);
1282  GLS(GL_CLEAR);
1283  GLS(GL_AND);
1284  GLS(GL_AND_REVERSE);
1285  GLS(GL_COPY);
1286  GLS(GL_AND_INVERTED);
1287  GLS(GL_NOOP);
1288  GLS(GL_XOR);
1289  GLS(GL_NOR);
1290  GLS(GL_EQUIV);
1291  GLS(GL_INVERT);
1292  GLS(GL_OR_REVERSE);
1293  GLS(GL_COPY_INVERTED);
1294  GLS(GL_OR_INVERTED);
1295  GLS(GL_NAND);
1296  GLS(GL_SET);
1297  GLS(GL_TEXTURE_1D);
1298  GLS(GL_TEXTURE_2D);
1299 #if defined(BIAS_HAVE_GLEW)
1300  GLS(GL_TEXTURE_3D);
1301  GLS(GL_TEXTURE_CUBE_MAP_EXT);
1302  GLS(GL_TEXTURE_RECTANGLE_NV);
1303 #endif
1304  GLS(GL_NEAREST);
1305  GLS(GL_LINEAR);
1306  GLS(GL_NEAREST_MIPMAP_NEAREST);
1307  GLS(GL_LINEAR_MIPMAP_NEAREST);
1308  GLS(GL_NEAREST_MIPMAP_LINEAR);
1309  GLS(GL_LINEAR_MIPMAP_LINEAR);
1310  GLS(GL_MODULATE);
1311  GLS(GL_DECAL);
1312  GLS(GL_BLEND);
1313  GLS(GL_RENDER);
1314  GLS(GL_FEEDBACK);
1315  GLS(GL_SELECT);
1316  GLS(GL_FLAT);
1317  GLS(GL_SMOOTH);
1318  GLS(GL_KEEP);
1319  GLS(GL_REPLACE);
1320  GLS(GL_INCR);
1321  GLS(GL_DECR);
1322  GLS(GL_TEXTURE_ENV);
1323  GLS(GL_OBJECT_LINEAR);
1324  GLS(GL_SPHERE_MAP);
1325  GLS(GL_ALPHA4 );
1326  GLS(GL_ALPHA8 );
1327  GLS(GL_ALPHA12 );
1328  GLS(GL_ALPHA16 );
1329  GLS(GL_LUMINANCE4);
1330  GLS(GL_LUMINANCE8 );
1331  GLS(GL_LUMINANCE12 );
1332  GLS(GL_LUMINANCE16 );
1333  GLS(GL_LUMINANCE4_ALPHA4 );
1334  GLS(GL_LUMINANCE6_ALPHA2 );
1335  GLS(GL_LUMINANCE8_ALPHA8 );
1336  GLS(GL_LUMINANCE12_ALPHA4 );
1337  GLS(GL_LUMINANCE12_ALPHA12 );
1338  GLS(GL_LUMINANCE16_ALPHA16 );
1339  GLS(GL_INTENSITY );
1340  GLS(GL_INTENSITY4 );
1341  GLS(GL_INTENSITY8 );
1342  GLS(GL_INTENSITY12 );
1343  GLS(GL_INTENSITY16 );
1344  GLS(GL_R3_G3_B2 );
1345  GLS(GL_RGB4 );
1346  GLS(GL_RGB5 );
1347  GLS(GL_RGB8 );
1348  GLS(GL_RGB10 );
1349  GLS(GL_RGB12 );
1350  GLS(GL_RGB16 );
1351  GLS(GL_RGBA2 );
1352  GLS(GL_RGBA4 );
1353  GLS(GL_RGB5_A1 );
1354  GLS(GL_RGBA8 );
1355  GLS(GL_RGB10_A2);
1356  GLS(GL_RGBA12 );
1357  GLS(GL_RGBA16 );
1358 
1359  default:
1360  unknownFlag=true;
1361  //s="unknown";
1362  }
1363 
1364  stringstream ss;
1365  if (withNumericDisplay || unknownFlag){
1366  if (flag!=1) {
1367  if (numerixHexFormat){
1368  // imitate OpenGL define format from gl.h/glew.h
1369  ss<<"0x"<<setw(4)<<setfill('0')<<hex<<flag<<" ";
1370  } else {
1371  ss<<setw(8)<<setfill(' ')<<dec<<flag<<" ";
1372  }
1373  }
1374  }
1375  if (!unknownFlag)
1376  ss<<s;
1377 
1378  return ss.str();
1379 }
1380 #undef GLS // save the environemt
1381 
1382 
1383 //static
1384 void GeometryGL::FillCubemap(BIAS::ImgObjGL & im, const bool & mipmapColorChange)
1385 {
1386  CALLINFO;
1387  // TODO
1388  //BIASASSERT(im.IsCubemap());
1389  //std::vector< BIAS::Image<unsigned char> > vImg;
1390 }
1391 
Vector3< double > GetRayWorldCoo(const HomgPoint2D &point)
returns vector from C to point, w of point determines ray length analytical inverse of K is used ...
Definition: PMatrix.cpp:665
unsigned int heightOrig
Definition: ImgObjGL.hh:148
void Print3D(const std::string &text, const float &xpos, const float &ypos, const float &zpos) const
Definition: DrawTextGL.cpp:275
static unsigned int PowerOfTwoSize(const unsigned int &val)
Definition: ImageBase.cpp:971
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
Definition: HomgPoint2D.hh:67
static void DisplayImgPlaneTextured(BIAS::PMatrix &P, const unsigned int &w, const unsigned int &h, const int &texID, const int &texTarget, const double &scale, const bool &flipY, const BIAS::Vector4< float > &vertexColor=BIAS::Vector4< float >(1.0, 0.0, 1.0, 0.0))
draws a pkane with attched texture coordinates
Definition: GeometryGL.cpp:804
static BIAS::Vector3< double > GetImgCorner3d(BIAS::PMatrix &P, const unsigned int &width, const unsigned int &height, const unsigned int &corner, const double &scale)
compute 3D pos.
Definition: GeometryGL.cpp:761
static void DisplayCoordCross(const float &size=1.0f, const float &linewidth=1.0f)
draw a coord cross as three lines in r,g,b
Definition: GeometryGL.cpp:598
GLenum minificationMode
Definition: ImgObjGL.hh:143
static void GetInfoGL(std::ostream &os)
print all GL state informatino to os including displaylist, texobj and matric info ...
Definition: GeometryGL.cpp:411
static void DisplayRenderMode(const BIAS::RenderModeGL &m)
Definition: GeometryGL.cpp:478
static void DisplaySimpleAnimation(const double &time)
time dependant scene for samples
Definition: GeometryGL.cpp:502
bool IsRectangleTexture() const
Definition: ImgObjGL.cpp:140
GLenum cullface
glCullFace: GL_FRONT, GL_BACK, and GL_FRONT_AND_BACK
Definition: RenderModeGL.hh:83
unsigned int heightBrutto
Definition: ImgObjGL.hh:152
static void DisplayClear(const GLbitfield &mask=CLEAR_DEFAULT_MASK)
utility functions
Definition: GeometryGL.cpp:424
data holder describing OpenGL texture objects in addition to its unique texID.
Definition: ImgObjGL.hh:34
bool IsInitialized() const
Definition: DrawTextGL.hh:130
GLenum polygonmodeBACK
glPoygonMode(GL_BACK...
Definition: RenderModeGL.hh:77
GLenum shademodel
glShadeModel(...
Definition: RenderModeGL.hh:80
GLenum magnificationMode
Definition: ImgObjGL.hh:144
virtual ~GeometryGL()
destructor
Definition: GeometryGL.cpp:32
void Set(const T &scalar)
set all elements to a scalar value
Definition: Vector2.hh:190
static void DisplayQuadTexCoord2DFull(const BIAS::ImgObjGL &texobj, const bool &additionalFlipY)
Definition: GeometryGL.cpp:956
static void CreateSampleDisplayListScene(int &dplistID)
creates a sample scene as one dispaly list returned in dplistID once the arg is kept as it is if init...
GLenum polygonmodeFRONT
glPoygonMode(GL_FRONT...
Definition: RenderModeGL.hh:71
static void GetInfoGLenvironment(std::ostream &os)
print individual information to os
Definition: GeometryGL.cpp:177
static void GetInfoGLTexObjects(std::ostream &os)
Definition: GeometryGL.cpp:165
static BIAS::Matrix4x4< double > CreateTextureMatrix(BIAS::PMatrix &P, const unsigned int w, const unsigned int h, const bool &useRECTcoord=false)
compose an OpenGL 4x4 (projective) texture matrix
Definition: GeometryGL.cpp:908
static void GetInfoGLmatrices(std::ostream &os)
Definition: GeometryGL.cpp:37
static BIAS::Vector2< double > GetImgCorner2d(const unsigned int &w, const unsigned int &h, const unsigned int &corner, const int texMode, const bool flipY)
Definition: GeometryGL.cpp:702
unsigned int widthOrig
Definition: ImgObjGL.hh:147
static void DisplayCameraExternalParams(BIAS::PMatrix &P)
Definition: GeometryGL.cpp:670
static void FillCubemap(BIAS::ImgObjGL &im, const bool &mipmapColorChange=false)
fill
static void DisplayP(BIAS::PMatrix &P, const unsigned int &w, const unsigned int &h, const double &scale, const float &linewidth=1.0f)
Definition: GeometryGL.cpp:842
static void GetInfoGLWriteMasks(std::ostream &os)
Definition: GeometryGL.cpp:384
static void DisplayCallsSampleDisplayListScene(const double &curTime)
int GetC(Vector3< double > &C)
computes translation vector origin world coo -&gt; origin camera coo (center), uses decomposition, which is cached
Definition: PMatrix.cpp:165
void SetIdentity()
set the elements of this matrix to the identity matrix (posisbly overriding the inherited method) ...
Definition: Matrix4x4.hh:260
static void DisplayCameraInternalParams(const int &x0, const int &y0, const unsigned int &width, const unsigned int &height, const float &fovY, const float &zNear, const float &zFar)
Definition: GeometryGL.cpp:633
static void DisplaySceneExampleSimple()
Definition: GeometryGL.cpp:517
int GetA(Vector3< double > &A)
returns the unit vector A which is the normal vector to the image plane in world coordinates.
Definition: PMatrix.cpp:287
static void GetInfoGLTexID(const GLint id, int &foundTextures, std::ostream &os, const bool &noOutputIfInvalid=true)
Definition: GeometryGL.cpp:92
static void DisplayCoordCrossAxesLabel(const float &size, const BIAS::DrawTextGL &font, const std::string &LabelX=std::string("x"), const std::string &LabelY=std::string("y"), const std::string &LabelZ=std::string("z"))
draw only the axes labels for a coord cross as text in r,g,b JW
Definition: GeometryGL.cpp:568
GLenum target
Definition: ImgObjGL.hh:138
GLRenderMode describes mode for rendering.
Definition: RenderModeGL.hh:45
describes a projective 3D -&gt; 2D mapping in homogenous coordinates
Definition: PMatrix.hh:88
static void GetInfoGLDisplayLists(std::ostream &os)
Definition: GeometryGL.cpp:75
void Set(const HOMGPOINT2D_TYPE &x, const HOMGPOINT2D_TYPE &y)
set elementwise with given 2 euclidean scalar values.
Definition: HomgPoint2D.hh:174
unsigned int widthBrutto
Definition: ImgObjGL.hh:151
static void DisplayQuadTexCoord2D(const BIAS::ImgObjGL &texobj, const bool &additionalFlipY)
Definition: GeometryGL.cpp:976
Vector3< T > & Normalize()
normalize this vector to length 1
Definition: Vector3.hh:663
int GetV(Vector3< double > &V)
This is not the cam.# standard CAHV, but the unit vector H0.
Definition: PMatrix.cpp:264
Draw text to OpenGL as 2D bitmap font.
Definition: DrawTextGL.hh:71
void SetIdentity()
set the elements of this matrix to the identity matrix (possibly overriding the inherited method) ...
Definition: Matrix3x3.hh:429
static std::string GetName(const GLint flag, const bool withNumericDisplay=true, const bool numerixHexFormat=true)
return a name for an OpenGL flags nr.
int GetK(KMatrix &K)
calibration matrix
Definition: PMatrix.cpp:220