//=========================================================================== // SISL - SINTEF Spline Library, version 4.5.0. // Definition and interrogation of NURBS curves and surfaces. // // Copyright (C) 2000-2005, 2010 SINTEF ICT, Applied Mathematics, Norway. // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation version 2 of the License. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., // 59 Temple Place - Suite 330, // Boston, MA 02111-1307, USA. // // Contact information: E-mail: tor.dokken@sintef.no // SINTEF ICT, Department of Applied Mathematics, // P.O. Box 124 Blindern, // 0314 Oslo, Norway. // // Other licenses are also available for this software, notably licenses // for: // - Building commercial software. // - Building software whose source code you wish to keep private. //=========================================================================== 00041 #ifndef M_PI 00042 #define M_PI 3.1415926535897932384 00043 #endif 00044 00045 00046 00047 00048 00049 void assert_gl_m(int line, char *file, const bool do_exit /* =true */ ) 00050 { 00051 int tmp=glGetError(), known_error=1; 00052 00053 if (tmp==GL_NO_ERROR) 00054 return; 00055 00056 while (tmp!=GL_NO_ERROR) 00057 { 00058 printf("'glGetError' returned %d ", tmp); 00059 switch (tmp) 00060 { 00061 case GL_NO_ERROR: 00062 printf("(GL_NO_ERROR) "); 00063 break; 00064 case GL_INVALID_ENUM: 00065 printf("(GL_INVALID_ENUM) "); 00066 break; 00067 case GL_INVALID_VALUE: 00068 printf("(GL_INVALID_VALUE) "); 00069 break; 00070 case GL_INVALID_OPERATION: 00071 printf("(GL_INVALID_OPERATION) "); 00072 break; 00073 case GL_STACK_OVERFLOW: 00074 printf("(GL_STACK_OVERFLOW) "); 00075 break; 00076 case GL_STACK_UNDERFLOW: 00077 printf("(GL_STACK_UNDERFLOW) "); 00078 break; 00079 case GL_OUT_OF_MEMORY: 00080 printf("(GL_OUT_OF_MEMORY) "); 00081 break; 00082 default: 00083 known_error=0; 00084 printf("(UNKNOWN ERROR(?!)) "); 00085 } 00086 if (file!=NULL) 00087 printf(" at line %d in file '%s'.\n", line, file); 00088 00089 if (known_error) 00090 { 00091 printf("The man page has this to say about this error:\n\n"); 00092 switch (tmp) 00093 { 00094 case GL_INVALID_ENUM: 00095 printf("An unacceptable value is\n"); 00096 printf("specified for an enumerated\n"); 00097 printf("argument. The offending\n"); 00098 printf("command is ignored, and has no\n"); 00099 printf("other side effect than to set\n"); 00100 printf("the error flag.\n"); 00101 break; 00102 case GL_INVALID_VALUE: 00103 printf("A numeric argument is out of\n"); 00104 printf("range. The offending command\n"); 00105 printf("is ignored, and has no other\n"); 00106 printf("side effect than to set the\n"); 00107 printf("error flag.\n"); 00108 break; 00109 case GL_INVALID_OPERATION: 00110 printf("The specified operation is not\n"); 00111 printf("allowed in the current state.\n"); 00112 printf("The offending command is\n"); 00113 printf("ignored, and has no other side\n"); 00114 printf("effect than to set the error\n"); 00115 printf("flag.\n"); 00116 break; 00117 case GL_STACK_OVERFLOW: 00118 printf("This command would cause a\n"); 00119 printf("stack overflow. The offending\n"); 00120 printf("command is ignored, and has no\n"); 00121 printf("other side effect than to set\n"); 00122 printf("the error flag.\n"); 00123 break; 00124 case GL_STACK_UNDERFLOW: 00125 printf("This command would cause a\n"); 00126 printf("stack underflow. The\n"); 00127 printf("offending command is ignored,\n"); 00128 printf("and has no other side effect\n"); 00129 printf("than to set the error flag.\n"); 00130 break; 00131 case GL_OUT_OF_MEMORY: 00132 printf("There is not enough memory\n"); 00133 printf("left to execute the command.\n"); 00134 printf("The state of the GL is\n"); 00135 printf("undefined, except for the\n"); 00136 printf("state of the error flags,\n"); 00137 printf("after this error is recorded.\n"); 00138 break; 00139 } 00140 } 00141 tmp=glGetError(); 00142 } 00143 00144 if (do_exit) 00145 exit(-1); 00146 else 00147 puts("\n\n\nOpenGL error!!!! \n\n\n"); 00148 } 00149 00150 00151 00152 00153 00154 00155 void assert_gl_dummy_and_empty(void) 00156 { 00157 return; 00158 } 00159 00160 00161 00162 00163 00164 00165 #ifndef MICROSOFT 00166 00167 //---------------------------------------------------------------------- 00168 // 00169 // 040229: A small routine to list out the properties of a list of 00170 // GLXFBConfigs. (There *may* be properties not listed, I don't 00171 // remember exactly how complete this list is...) 00172 // 00173 //---------------------------------------------------------------------- 00174 00175 void list_FBConfigs(GLXFBConfig *config, int nelements) 00176 { 00177 int attr_list[]= 00178 { 00179 GLX_FBCONFIG_ID, 00180 GLX_VISUAL_ID , 00181 GLX_BUFFER_SIZE, 00182 GLX_LEVEL , 00183 GLX_DOUBLEBUFFER , 00184 GLX_STEREO , 00185 GLX_AUX_BUFFERS , 00186 GLX_RENDER_TYPE , 00187 GLX_RED_SIZE , 00188 GLX_GREEN_SIZE , 00189 GLX_BLUE_SIZE , 00190 GLX_ALPHA_SIZE , 00191 GLX_DEPTH_SIZE , 00192 GLX_STENCIL_SIZE , 00193 GLX_ACCUM_RED_SIZE , 00194 GLX_ACCUM_GREEN_SIZE , 00195 GLX_ACCUM_BLUE_SIZE , 00196 GLX_ACCUM_ALPHA_SIZE , 00197 GLX_DRAWABLE_TYPE , 00198 GLX_X_RENDERABLE , 00199 GLX_X_VISUAL_TYPE , 00200 GLX_CONFIG_CAVEAT , 00201 GLX_TRANSPARENT_TYPE, 00202 GLX_TRANSPARENT_INDEX_VALUE , 00203 GLX_TRANSPARENT_RED_VALUE , 00204 GLX_TRANSPARENT_GREEN_VALUE , 00205 GLX_TRANSPARENT_BLUE_VALUE , 00206 GLX_TRANSPARENT_ALPHA_VALUE , 00207 GLX_MAX_PBUFFER_WIDTH , 00208 GLX_MAX_PBUFFER_HEIGHT , 00209 GLX_MAX_PBUFFER_PIXELS 00210 }; 00211 char *attr_name[]= 00212 { 00213 "GLX_FBCONFIG_ID", 00214 "GLX_VISUAL_ID", 00215 "GLX_BUFFER_SIZE", 00216 "GLX_LEVEL", 00217 "GLX_DOUBLEBUFFER", 00218 "GLX_STEREO", 00219 "GLX_AUX_BUFFERS", 00220 "GLX_RENDER_TYPE", 00221 "GLX_RED_SIZE", 00222 "GLX_GREEN_SIZE", 00223 "GLX_BLUE_SIZE", 00224 "GLX_ALPHA_SIZE", 00225 "GLX_DEPTH_SIZE", 00226 "GLX_STENCIL_SIZE", 00227 "GLX_ACCUM_RED_SIZE", 00228 "GLX_ACCUM_GREEN_SIZE", 00229 "GLX_ACCUM_BLUE_SIZE", 00230 "GLX_ACCUM_ALPHA_SIZE", 00231 "GLX_DRAWABLE_TYPE", 00232 "GLX_X_RENDERABLE", 00233 "GLX_X_VISUAL_TYPE", 00234 "GLX_CONFIG_CAVEAT", 00235 "GLX_TRANSPARENT_TYPE", 00236 "GLX_TRANSPARENT_INDEX_VALUE", 00237 "GLX_TRANSPARENT_RED_VALUE", 00238 "GLX_TRANSPARENT_GREEN_VALUE", 00239 "GLX_TRANSPARENT_BLUE_VALUE", 00240 "GLX_TRANSPARENT_ALPHA_VALUE", 00241 "GLX_MAX_PBUFFER_WIDTH", 00242 "GLX_MAX_PBUFFER_HEIGHT", 00243 "GLX_MAX_PBUFFER_PIXELS" 00244 }; 00245 #if 0 00246 char *attr_str[]= 00247 { 00248 "This attribute is the XID of the GLX FBConfig.", 00249 "This attribute is the XID of the X Visual associated with the GLX FBConfig.", 00250 "This attribute defines the number of bits per color buffer. For GLX FBConfigs that correspond to a PseudoColor or StaticColor visual, this is equal to the depth value reported in the X11 visual. For GLX FBConfigs that correspond to TrueColor or DirectColor visual, this is the sum of GLX_RED_SIZE, GLX_GREEN_SIZE, GLX_BLUE_SIZE, and GLX_ALPHA_SIZE.", 00251 "This attribute defines the frame buffer level of the visual. Level 0 is the default frame buffer. Positive levels correspond to frame buffers that overlay the default buffer; negative levels correspond to frame buffers that underlay the default buffer.", 00252 "This attribute is True if color buffers exist in front/back pairs that can be swapped. Otherwise, it is False.", 00253 "This attribute is True if color buffers exist in left/right pairs. Otherwise, it is False.", 00254 "This attribute defines the number of auxiliary color buffers available. Zero indicates that no auxiliary color buffers exist.", 00255 "This attribute indicates what type of GLX Context a drawable created with the corresponding GLX FBConfig can be bound to. The following bit settings can exist:", 00256 "This attribute defines the number of red bits stored in each color buffer. If the GLX_RGBA_BIT is not set in the GLX_RENDER_TYPE attribute, the GLX_RED_SIZE attribute is undefined.", 00257 "This attribute defines the number of green bits stored in each color buffer. If the GLX_RGBA_BIT is not set in the GLX_RENDER_TYPE attribute, the GLX_GREEN_SIZE attribute is undefined.", 00258 "This attribute defines the number of blue bits stored in each color buffer. If the GLX_RGBA_BIT is not set in the GLX_RENDER_TYPE attribute, the GLX_BLUE_SIZE attribute is undefined.", 00259 "This attribute defines the number of alpha bits stored in each color buffer. If the GLX_RGBA_BIT is not set in the GLX_RENDER_TYPE attribute, the GLX_ALPHA_SIZE attribute is undefined.", 00260 "This attribute defines the number of bits in the depth buffer.", 00261 "This attribute defines the number of bits in the stencil buffer.", 00262 "This attribute defines the number of red bits stored in the accumulation buffer.", 00263 "This attribute defines the number of green bits stored in the accumulation buffer.", 00264 "This attribute defines the number of blue bits stored in the accumulation buffer.", 00265 "This attribute defines the number of alpha bits stored in the accumulation buffer.", 00266 "This attribute defines which GLX drawables are supported by the GLX FBConfig. The following bit settings can exist:", 00267 "This attribute indicates whether X can be used to render into a drawable created with the GLX FBConfig. This attribute is True is the GLX FBConfig supports GLX windows and/or pixmaps, otherwise it is False.", 00268 "This attribute defines the X visual type of the X visual associated with the GLX FBConfig. It can have one of the following values:", 00269 "This attribute defines any problems that the GLX FBConfig may have:", 00270 "This attribute defines the type of transparency (if any) supported by the FBConfig. It can have the following values:", 00271 "This attribute defines the index value of the transparent pixel when the transparency type is GLX_TRANSPARENT_INDEX.", 00272 "This attribute defines the red value of the transparent pixel when the transparency type is GLX_TRANSPARENT_RGB.", 00273 "This attribute defines the green value of the transparent pixel when the transparency type is GLX_TRANSPARENT_RGB", 00274 "This attribute defines the blue value of the transparent pixel when the transparency type is GLX_TRANSPARENT_RGB.", 00275 "This attribute defines the alpha value of the transparent pixel when the transparency type is GLX_TRANSPARENT_RGB.", 00276 "This attribute defines the maximum width value that can be passed into glXCreatePbuffer.", 00277 "This attribute defines the maximum height value that can be passed into glXCreatePbuffer.", 00278 "This attribute defines the maximum number of pixels (width times height) for a GLX Pbuffer. It can have a value that is less than the maximum width times the maximum height. Also, the value is static and assumes that no other pbuffers or X resources are contending for the framebuffer memory. Therefore, it may not be possible to allocate a pbuffer of the size given by this attribute." 00279 }; 00280 #endif 00281 int i, j; 00282 Display *dpy=glXGetCurrentDisplay(); 00283 00284 for (i=0; i<nelements; i++) 00285 { 00286 printf("FBConfig %d:\n", i); 00287 for (j=0; j<31; j++) 00288 { 00289 int val; 00290 int tmp=glXGetFBConfigAttrib(dpy, config[i], attr_list[j], &val); 00291 printf(" %2d, %5d = %s: %d, tmp=%d\n", 00292 j, attr_list[j], attr_name[j], val, tmp); 00293 } 00294 } 00295 00296 } 00297 00298 #endif // of if not microsoft 00299 00300 00301 00302 00303 00304 00305 //====================================================================== 00306 // 00307 // 050123: Moving this out of sfviewer1b, for re-use. 00308 // 00309 // There are a set of spheres stored here, indexed by 'slot', 00310 // starting from 1 and onwards. 00311 // If 'slot' > existing number of spheres, a new one is 00312 // tesselated and stored, then drawn. 00313 // 00314 //====================================================================== 00315 00316 void draw_sphere(const vector3t<float> &pos, const float r, 00317 const int n, const int slot, 00318 const vector3t<float> &col, 00319 const bool wiremode) 00320 { 00321 // const int n=20; // gir 1520 triangler 00322 // const int n=15; // gir 840 triangler 00323 // const int n=29; // 3248 triangler, max som passer i grafikkortet?! 00324 // const int n=10; // gir 360 triangler 00325 //const int n=25; 00326 // const int n=4; 00327 00328 static vector< vector< vector3t<float> > > all_vert1, all_norm1; 00329 static vector< vector<int> > all_tri; 00330 00331 if (slot>(int)all_vert1.size()) 00332 { 00333 vector< vector3t<float> > vert1, norm1; 00334 vector<int> tri; 00335 00336 vert1.push_back(pos+vector3t<float>(0, 0, r)); 00337 vert1.push_back(pos+vector3t<float>(0, 0, -r)); 00338 norm1.push_back(vector3t<float>(0.0, 0.0, 1.0)); 00339 norm1.push_back(vector3t<float>(0.0, 0.0, -1.0)); 00340 00341 int i, j; 00342 for (i=1; i<=n; i++) 00343 { 00344 double ph=(double)i/n*M_PI-M_PI*0.5; 00345 00346 for (j=0; j<2*n; j++) 00347 { 00348 double th=(double)j/(2*n)*M_PI*2.0; 00349 00350 // sphere 00351 double x=cos(th)*cos(ph); 00352 double y=sin(th)*cos(ph); 00353 double z=sin(ph); 00354 if (i<n) 00355 { 00356 vert1.push_back(pos+r*vector3t<float>(x, y, z)); 00357 norm1.push_back(vector3t<float>(x, y, z)); 00358 } 00359 00360 00361 // shall not make vertices for the top pole, but we need 00362 // i=n to make the last ring of triangles! 00363 00364 int k=vert1.size()-1; 00365 if (j>0) 00366 if (i==1) { 00367 tri.push_back(1); tri.push_back(k); tri.push_back(k-1); 00368 } else { 00369 if (i==n) { 00370 tri.push_back(0); tri.push_back(k-(2*n-1)+j-1); 00371 tri.push_back(k-(2*n-1)+j); 00372 } else { 00373 tri.push_back(k-2*n-1); tri.push_back(k); 00374 tri.push_back(k-1); tri.push_back(k-2*n-1); 00375 tri.push_back(k-2*n); tri.push_back(k); 00376 } 00377 } 00378 else 00379 if (i==1) { 00380 tri.push_back(1); tri.push_back(k); tri.push_back(k-1+2*n); 00381 } else 00382 if (i==n) { 00383 tri.push_back(0); tri.push_back(k); 00384 tri.push_back(k-(2*n-1)); 00385 } else { 00386 tri.push_back(k+2*n-1); tri.push_back(k-1); 00387 tri.push_back(k); tri.push_back(k); 00388 tri.push_back(k-1); tri.push_back(k-2*n); 00389 } 00390 } 00391 } 00392 00393 all_vert1.push_back(vert1); 00394 all_norm1.push_back(norm1); 00395 all_tri.push_back(tri); 00396 } 00397 00398 if (!wiremode) 00399 { 00400 glBegin(GL_TRIANGLES); 00401 glColor3fv(col.raw()); 00402 int i; 00403 for (i=0; i<(int)all_tri[slot-1].size(); i++) 00404 { 00405 glNormal3fv(all_norm1[slot-1][all_tri[slot-1][i]].raw()); 00406 glVertex3fv(all_vert1[slot-1][all_tri[slot-1][i]].raw()); 00407 } 00408 glEnd(); 00409 } 00410 else 00411 { 00412 GLboolean light_temp; 00413 glGetBooleanv(GL_LIGHTING, &light_temp); 00414 glDisable(GL_LIGHTING); 00415 glColor3fv(col.raw()); 00416 int i; 00417 for (i=0; i<(int)all_tri[slot-1].size(); i+=3) 00418 { 00419 glBegin(GL_LINE_STRIP); 00420 glVertex3fv(all_vert1[slot-1][all_tri[slot-1][i ]].raw()); 00421 glVertex3fv(all_vert1[slot-1][all_tri[slot-1][i+1]].raw()); 00422 glVertex3fv(all_vert1[slot-1][all_tri[slot-1][i+2]].raw()); 00423 glVertex3fv(all_vert1[slot-1][all_tri[slot-1][i ]].raw()); 00424 glEnd(); 00425 } 00426 if (light_temp) 00427 glEnable(GL_LIGHTING); 00428 } 00429 }
1.6.3