Allink  v0.1
DrawFile.cpp
00001 #include "../../include/Draw.h"
00002 #include <unistd.h>
00003 #include <setjmp.h>
00004 
00005 #ifdef __glut_h__
00006 void Draw::ReadConf(){
00007   Shout("ReadConf");
00008   FILE *ConfFile;
00009   char cLine[256];
00010   double Val[9];
00011   if( (ConfFile = fopen("Draw.conf","r")) == 0 ){return;}
00012   for(int k=0;!(fgets(cLine,256,ConfFile)==NULL);k++){
00013     if(1 == sscanf(cLine,"Pre %lf",Val) )
00014       pr = (int) Val[0];
00015     else if(1 ==  sscanf(cLine,"Passo %lf",Val))
00016       GridStep = (int)Val[0];
00017     else if(1 == sscanf(cLine,"Box %lf",Val))
00018       la = (int) Val[0];
00019     else if(1 == sscanf(cLine,"Grid %lf",Val))
00020       gr = (int) Val[0];
00021     else if(3 == sscanf(cLine,"Offset %lf %lf %lf",Val,Val+1,Val+2)){
00022       xp = Val[0];yp = Val[1];zp = Val[2];
00023     }
00024     else if(3 == sscanf(cLine,"Rotate %lf %lf %lf",Val,Val+1,Val+2)){
00025       xa = Val[0];ya = Val[1];za = Val[2];
00026   }
00027     else if(3 == sscanf(cLine,"Sun %lf %lf %lf",Val,Val+1,Val+2)){
00028       xf = Val[0];yf = Val[1];zf = Val[2];
00029     }
00030     else if(3 == sscanf(cLine,"Info %lf %lf %lf",Val,Val+1,Val+2)){
00031       xi = Val[0];yi = Val[1];zi = Val[2];
00032     }
00033     else if(5 == sscanf(cLine,"Legend %lf %lf %lf %lf %lf",Val,Val+1,Val+2,Val+3,Val+4)){
00034       xLeg = Val[0];yLeg = Val[1];zLeg = Val[2];dxLeg = Val[3];dyLeg = Val[4];
00035     }
00036     else if(3 == sscanf(cLine,"Background %lf %lf %lf",Val,Val+1,Val+2)){
00037       Rback = Val[0];Gback = Val[1];Bback = Val[2];
00038     }
00039     else if(1 == sscanf(cLine,"Wheel %lf",Val)){
00040       zw = Val[0];
00041     }
00042     else if(3 == sscanf(cLine,"GridEdge %lf %lf %lf",Val,Val+1,Val+2)){
00043       GridEdge[0] = Val[0];GridEdge[1] = Val[1];GridEdge[2] = Val[2];
00044     }
00045   }
00046   fclose(ConfFile);
00047 }
00048 #ifdef USE_TIFF
00049 #include <tiff.h>
00050 #include <tiffio.h>
00051 int Draw::OpenImage(const char *FileName){
00052   Shout("OpenImage");
00053 //   pixel = (GLubyte *)realloc(pixel,4*width*height*sizeof(*pixel));
00054 //   glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE,pixel);
00055 //   return 0;
00056   TIFF *image;
00057   uint16 photo=0, bps=0, spp=0, fillorder=0,resUnit=0;
00058   uint32 ImWidth1=0,ImHeight1=0;
00059   tsize_t stripSize;
00060   int imageOffset=0, result=0;
00061   int stripMax=0, stripCount=0;
00062   float xRes=0,yRes=0;
00063   // char *buffer, tempbyte;
00064   uint32 *buffer=NULL;
00065   int bufferSize=0, count=0;
00066   int NPixel=0,Level=4;
00067   if((image = TIFFOpen(FileName, "r")) == NULL){
00068     fprintf(stderr, "Could not open incoming image\n");
00069     return 0;
00070   }
00071   TIFFGetField(image, TIFFTAG_IMAGELENGTH, &ImHeight1);
00072   TIFFGetField(image, TIFFTAG_IMAGEWIDTH, &ImWidth1);
00073   TIFFGetField(image, TIFFTAG_PHOTOMETRIC, &photo);
00074   TIFFGetField(image, TIFFTAG_FILLORDER, &fillorder);
00075   TIFFGetField(image, TIFFTAG_XRESOLUTION, &xRes);
00076   TIFFGetField(image, TIFFTAG_YRESOLUTION, &yRes);
00077   TIFFGetField(image, TIFFTAG_RESOLUTIONUNIT, &resUnit);
00078   TIFFGetField(image, TIFFTAG_BITSPERSAMPLE, &bps);
00079   TIFFGetField(image, TIFFTAG_SAMPLESPERPIXEL, &spp);
00080   stripSize = TIFFStripSize (image);
00081   stripMax = TIFFNumberOfStrips (image);
00082   imageOffset = 0;
00083   bufferSize = TIFFNumberOfStrips (image) * stripSize;
00084   ImHeight = (GLuint)ImHeight1;
00085   ImWidth  = (GLuint) ImWidth1;
00086   NPixel = ImWidth*ImHeight*Level;
00087   //sprintf(info,"width %d height %d photo %d fillorder %d Res (%lf %lf) ResUnit %d bit/sample %d sample/pixel %d stripSize %d stripMax %d bufferSize %d NPixel %d\n",ImWidth,ImHeight,photo,fillorder,xRes,yRes,resUnit,bps,spp,stripSize,stripMax,bufferSize,NPixel);
00088   //buffer = (uint32 *) malloc(bufferSize);
00089   buffer = (uint32 *)_TIFFmalloc(ImHeight1 * ImWidth1 * sizeof (uint32));
00090   if(buffer == NULL){
00091     fprintf(stderr, "Could not allocate enough memory for the uncompressed image\n");
00092     return 0;
00093   }
00094   free(pixel);
00095   pixel = NULL;
00096   pixel = (GLubyte *)calloc(4*ImWidth*ImHeight,sizeof(*pixel));
00097   if(!TIFFReadRGBAImage(image,ImWidth1,ImHeight1,buffer,1)){
00098   //if(!TIFFReadRGBAImageOriented(image,ImWidth1,ImHeight1,buffer,ORIENTATION_TOPLEFT,0)){
00099     _TIFFfree(buffer);
00100     printf("The immage was not read\n");
00101     throw "Corrupted TIFF file!";
00102   }
00103   for(int h=0; h<ImHeight; h++) {
00104     for(int w=0; w<ImWidth; w++) {
00105       pixel[(h*ImWidth+w)*4+0] = buffer[(h*ImWidth+w)] & 0x000000ff;
00106       pixel[(h*ImWidth+w)*4+1] = ((buffer[(h*ImWidth+w)] >> 8  ) & 0x0000ff);
00107       pixel[(h*ImWidth+w)*4+2] = ((buffer[(h*ImWidth+w)] >> 16 ) & 0x00ff);
00108       pixel[(h*ImWidth+w)*4+3] = ((buffer[(h*ImWidth+w)] >> 24 ) & 0xff);
00109     }
00110   }
00111   TIFFClose(image);
00112   _TIFFfree(buffer);
00113    return 1;
00114 }
00115 int Draw::WritePixel(){
00116   Shout("WritePixel");
00117   char cImage[160];
00118   sprintf(cImage,"Image%05u.tif",Step);
00119   TIFF *tif = TIFFOpen( cImage, "w");
00120   if(tif) {
00121     TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, ImWidth);
00122     TIFFSetField(tif, TIFFTAG_IMAGELENGTH, ImHeight);
00123     TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
00124     TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_BOTLEFT);
00125     TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
00126     TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
00127     TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 4);
00128   }
00129   TIFFWriteEncodedStrip(tif, 0, pixel, ImWidth * ImHeight *4);
00130   TIFFClose(tif);
00131   return 0;
00132 }
00133 int Draw::Picture(){
00134   Shout("Picture");
00135   //       mkOpenGLJPEGImage jpgScreen;
00136   //       jpgScreen.SetDebugMode(true);
00137   //       jpgScreen.GetOpenGLScreenImage(imageWidth, imageHeight);
00138   //       jpgScreen.SaveToFile("ScreenShot.jpg");
00139   //GLubyte pixel[Resx][Resy][3];
00140   //  GLubyte *pixel=new GLubyte [Resx * Resy];
00141   glutPostRedisplay();
00142   char cImage[160];
00143   sprintf(cImage,"Image%05u.tif",Step);
00144   TIFF *tif = TIFFOpen( cImage, "w");
00145   if(tif) {
00146     TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, WinWidth);
00147     TIFFSetField(tif, TIFFTAG_IMAGELENGTH, WinHeight);
00148     TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
00149     //TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_BOTLEFT);
00150     TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
00151     TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
00152     TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 4);
00153   }
00154   char * data = (char *) calloc(WinWidth * WinHeight*4,sizeof(char));
00155   //  pixel = (GLubyte *)realloc(pixel,3*width*height*sizeof(*pixel));
00156   //  glPixelStorei(GL_UNPACK_ALIGNMENT,1);
00157   //  glRasterPos3i(0,0,0);
00158   //  //glutUseLayer(GLUT_NORMAL);
00159   //  glReadPixels(-1,-1,width,height,GL_RGBA,GL_UNSIGNED_BYTE,pixel);
00160   //         glReadBuffer(GL_BACK);
00161   //         //glPixelStorei(GL_PACK_ALIGNMENT, 1);
00162   glReadPixels(0, 0, WinWidth, WinHeight, GL_RGBA, GL_UNSIGNED_BYTE, data);
00163   char * MonaSoMare = (char *) calloc(WinWidth * WinHeight*4,sizeof(char));
00164   for(int l=0;l<4;l++)
00165     for(int w = 0;w<WinWidth;w++)
00166       for(int h=0;h<WinHeight;h++)
00167    MonaSoMare[(h*WinWidth+w)*4+l] = data[( (WinHeight-h)*WinWidth+w)*4 + l];
00168   TIFFWriteEncodedStrip(tif, 0,MonaSoMare, WinWidth * WinHeight *4);
00169   TIFFClose(tif);
00170   free(data);
00171   free(MonaSoMare);
00172   //       //UINT *pixels=new UINT[nWidth * nHeight];
00173   //glReadBuffer(GL_BACK_LEFT); 
00174   //       //glReadPixels(0,0,width,height,GL_RGB,GL_UNSIGNED_BYTE,image);
00175   //GL_COLOR_INDEX, GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_RED, GL_GREEN, GL_BLUE, 
00176   //GL_ALPHA, GL_RGB, GL_RGBA, GL_LUMINANCE, and GL_LUMINANCE_ALPHA. 
00177   //GL_UNSIGNED_BYTE, GL_BYTE, GL_BITMAP, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT, or GL_FLOAT.    
00178 }
00179 #else
00180 int Draw::OpenImage(const char *FileName){
00181   printf("libtiff not supported\n");
00182 }
00183 int Draw::Picture(){
00184   printf("libtiff not supported\n");
00185 }
00186 int Draw::WritePixel(){
00187   printf("libtiff not supported\n");
00188 }
00189 #endif //USE_TIFF
00190 #ifdef USE_PNG
00191 #include <png.h>
00192 #include <pngwriter.h>
00193 int Draw::WritePngwriter(){
00194   char cImage[160];
00195   sprintf(cImage,"Image%05u.png",Step);
00196   pngwriter Image(ImWidth,ImHeight,1.0,cImage);
00197   double Norm = 1./256.;
00198   for(int w = 0;w<ImWidth;w++)
00199     for(int h=0;h<ImHeight;h++){
00200       double Color[3];
00201       for(int l=0;l<3;l++){
00202    Color[l] = Norm*pixel[(h*ImWidth+w)*4+l];
00203       }
00204       Image.plot(w,h,Color[0],Color[1],Color[2]);
00205     }
00206   Image.close();
00207 }
00208 int Draw::WritePng(){
00209   Shout("WritePng");
00210   int NLevel = 4;
00211   png_byte color_type;
00212   png_byte bit_depth;
00213   png_structp png_ptr;
00214   png_infop info_ptr;
00215   int number_of_passes;
00216   png_byte header[8];   // 8 is the maximum size that can be checked
00217   char cImage[160];
00218   sprintf(cImage,"Image%05u.png",Step);
00219   png_bytep *  row_pointers = (png_bytep*) malloc(sizeof(png_bytep) * ImHeight);
00220   for (int y=0; y<ImHeight; y++)
00221     row_pointers[y] = (png_byte*) malloc(ImWidth);//info_ptr->rowbytes);
00222   for (int y=0; y<ImHeight; y++) {
00223     png_byte* row = row_pointers[y];
00224     for (int x=0; x<ImWidth; x++) {
00225       png_byte* ptr = &(row[x*4]);
00226       for(int l=0;l<NLevel;l++)
00227    ptr[l] = pixel[(y*ImWidth+x)*NLevel+l];
00228     }
00229   }
00230   /* initialize stuff */
00231   png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
00232   SigErr(!png_ptr,"[write_png_file] png_create_write_struct failed");
00233   info_ptr = png_create_info_struct(png_ptr);
00234   SigErr(!info_ptr,"[write_png_file] png_create_info_struct failed");
00235   SigErr(setjmp(png_jmpbuf(png_ptr)),"[read_png_file] Error during init_io");
00236   png_set_sig_bytes(png_ptr, 8);
00237   //  png_read_info(png_ptr, info_ptr);
00238   color_type = 6;//info_ptr->color_type;
00239   bit_depth = 8;//info_ptr->bit_depth;
00240   //  number_of_passes = png_set_interlace_handling(png_ptr);
00241   //png_read_update_info(png_ptr, info_ptr);
00242   FILE *fp = fopen(cImage, "wb");
00243   SigErr(!fp,"[write_png_file] File %s could not be opened for writing",cImage);
00244   SigErr(setjmp(png_jmpbuf(png_ptr)),"[write_png_file] Error during init_io");
00245  /* setup libpng for using standard C fread() function
00246      with our FILE pointer */
00247   png_init_io(png_ptr, fp);
00248   /* convert index color images to RGB images */
00249    //  if (color_type == PNG_COLOR_TYPE_PALETTE)
00250    //png_set_palette_to_rgb (png_ptr);
00251  /* convert 1-2-4 bits grayscale images to 8 bits
00252      grayscale. */
00253 //   if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
00254 //     png_set_gray_1_2_4_to_8 (png_ptr);
00255 
00256 //   if (png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS))
00257 //     png_set_tRNS_to_alpha (png_ptr);
00258   /* write header */
00259   SigErr(setjmp(png_jmpbuf(png_ptr)),"[write_png_file] Error during writing header");
00260   png_set_IHDR(png_ptr, info_ptr, ImWidth, ImHeight,
00261           bit_depth, color_type, PNG_INTERLACE_NONE,
00262           PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
00263   png_write_info(png_ptr, info_ptr);
00264   /* write bytes */
00265   SigErr(setjmp(png_jmpbuf(png_ptr)),"[write_png_file] Error during writing bytes");
00266   png_write_image(png_ptr, row_pointers);
00267   /* end write */
00268   SigErr(setjmp(png_jmpbuf(png_ptr)),"[write_png_file] Error during end of write");
00269   png_write_end(png_ptr, NULL);
00270   /* cleanup heap allocation */
00271   for (int y=0; y<ImHeight; y++) free(row_pointers[y]);
00272   free(row_pointers);
00273   fclose(fp);
00274   return 0;
00275 }
00276 #else //USE_PNG
00277 int Draw::WritePngwriter(){
00278   printf("Pngwriter not installed\n");
00279 }
00280 int Draw::WritePng(){
00281   printf("Pngwriter not installed\n");
00282 }
00283 #endif
00284 
00285 void Draw::ReadScript(){
00286   Shout("ReadScript");
00287   FILE *File2Read;
00288   if((File2Read = fopen("DrawScript.dr","r"))==0){
00289     return ;
00290   }
00291   glDeleteLists(ScriptList,1);
00292   ScriptList = glGenLists(1);
00293   glNewList(ScriptList,GL_COMPILE);
00294   double Expand[3] = {Edge[0]*InvScaleUn,Edge[1]*InvScaleUn,Edge[2]*InvScaleUn};
00295   double *From = (double *)calloc(3,sizeof(double));
00296   double *To = (double *)calloc(3,sizeof(double));
00297   double *Hue = (double *)calloc(5,sizeof(double));
00298   char *cLine = (char *)calloc(265,sizeof(char));
00299   for(int k=0;!(fgets(cLine,256,File2Read)==NULL);k++){
00300     if(strncmp(cLine,"Line",4)==0){
00301       fgets(cLine,256,File2Read);
00302       sscanf(cLine,"%lf %lf %lf %lf\n",Hue,Hue+1,Hue+2,Hue+3,Hue+4);
00303       fgets(cLine,256,File2Read);
00304       sscanf(cLine,"%lf %lf %lf %lf %lf %lf\n",From,From+1,From+2,To,To+1,To+2);
00305       glPushMatrix();
00306       glColor4f(Hue[0],Hue[1],Hue[2],Hue[3]);
00307       glLineWidth(Hue[4]);
00308       glBegin(GL_LINES);
00309       glNormal3f(0.,0.,1.);
00310       glVertex3d(From[0]*Expand[0],From[1]*Expand[1],From[2]*Expand[2]);
00311       glVertex3d(To[0]*Expand[0],To[1]*Expand[1],To[2]*Expand[2]);
00312       glEnd();
00313       glPopMatrix();
00314     }
00315     else if(strncmp(cLine,"Curve",4)==0){
00316       glPushMatrix();
00317       glBegin(GL_LINE_STRIP);
00318       fgets(cLine,256,File2Read);
00319       sscanf(cLine,"%lf %lf %lf %lf\n",Hue,Hue+1,Hue+2,Hue+3);
00320       glColor4f(Hue[0],Hue[1],Hue[2],Hue[3]);
00321       glNormal3f(0.,0.,1.);
00322       while(1==1) {
00323    fpos_t FPos;
00324    fgetpos(File2Read,&FPos);
00325    if(fgets(cLine,256,File2Read)==0) break;
00326    if(sscanf(cLine,"%lf %lf %lf\n",From,From+1,From+2)!=3){
00327      fsetpos(File2Read,&FPos);
00328      break;
00329    }
00330    glVertex3d(From[0]*Expand[0],From[1]*Expand[1],From[2]*Expand[2]);
00331       }
00332       glEnd();
00333       glPopMatrix();
00334     }
00335     else if(strncmp(cLine,"Polygon",4)==0){
00336       glPushMatrix();
00337       glBegin(GL_POLYGON);
00338       fgets(cLine,256,File2Read);
00339       sscanf(cLine,"%lf %lf %lf %lf\n",Hue,Hue+1,Hue+2,Hue+3);
00340       glColor4f(Hue[0],Hue[1],Hue[2],Hue[3]);
00341       glNormal3f(0.,0.,1.);
00342       while(1==1) {
00343    fpos_t FPos;
00344    fgetpos(File2Read,&FPos);
00345    if(fgets(cLine,256,File2Read)==0) break;
00346    if(sscanf(cLine,"%lf %lf %lf\n",From,From+1,From+2)!=3){
00347      fsetpos(File2Read,&FPos);
00348      break;
00349    }
00350    glVertex3d(From[0]*Expand[0],From[1]*Expand[1],From[2]*Expand[2]);
00351       }
00352       glEnd();
00353       glPopMatrix();
00354     }
00355     else if(strncmp(cLine,"Arrow",4)==0){
00356       fgets(cLine,256,File2Read);
00357       sscanf(cLine,"%lf %lf %lf %lf\n",Hue,Hue+1,Hue+2,Hue+3,Hue+4);
00358       fgets(cLine,256,File2Read);
00359       sscanf(cLine,"%lf %lf %lf %lf %lf %lf\n",From,From+1,From+2,To,To+1,To+2);
00360       glLineWidth(Hue[4]);
00361       glColor4f(Hue[0],Hue[1],Hue[2],Hue[3]);
00362       glPushMatrix();//Arrow
00363       double Dist[3];
00364       double Freccia[3] = {Expand[0],0.,0.};
00365       double Axis[3];
00366       for(int d=0;d<3;d++){
00367    Dist[d] = (To[d] - From[d])*Expand[d];
00368       }      
00369       double Length1 = sqrt( QUAD(Dist[0]) + QUAD(Dist[1]) + QUAD(Dist[2]) );
00370       double Length2 = sqrt( QUAD(Expand[0]) );
00371       for(int d=0;d<3;d++){
00372    Axis[d] = .5*(Dist[d]/Length1 + Freccia[d]/Length2);
00373       }
00374       glTranslated(From[0]*Expand[0],From[1]*Expand[1],From[2]*Expand[2]);
00375       glRotatef(180.,Axis[0],Axis[1],Axis[2]);
00376       glScaled(Length1/Length2,1.0,1.0);
00377       glNormal3f(Dist[0],Dist[1],Dist[2]);
00378       glCallList(Arrow);
00379       glPopMatrix();//Arrow
00380     }
00381     else if(strncmp(cLine,"Sphere",6)==0){
00382       fgets(cLine,256,File2Read);
00383       sscanf(cLine,"%lf %lf %lf %lf\n",Hue,Hue+1,Hue+2,Hue+3);
00384       fgets(cLine,256,File2Read);
00385       sscanf(cLine,"%lf %lf %lf %lf %lf %lf\n",From,From+1,From+2,To,To+1,To+2);
00386       glPushMatrix();
00387       glTranslated(From[0]*Expand[0],From[1]*Expand[1],From[2]*Expand[2]);
00388       glColor4f(Hue[0],Hue[1],Hue[2],Hue[3]);
00389       glutSolidSphere(To[0]*Expand[0],(int)To[1],(int)To[2]);
00390       glPopMatrix();
00391     }
00392      else if(strncmp(cLine,"Cylinder",7)==0){
00393       fgets(cLine,256,File2Read);
00394       sscanf(cLine,"%lf %lf %lf %lf\n",Hue,Hue+1,Hue+2,Hue+3);
00395       fgets(cLine,256,File2Read);
00396       sscanf(cLine,"%lf %lf %lf %lf %lf %lf\n",From,From+1,From+2,To,To+1,To+2);
00397       glPushMatrix();
00398       glTranslated(From[0]*Expand[0],From[1]*Expand[1],From[2]*Expand[2]);
00399       glColor4f(Hue[0],Hue[1],Hue[2],Hue[3]);
00400       glutSolidSphere(To[0]*Expand[0],(int)To[1],(int)To[2]);
00401       glPopMatrix();
00402     }
00403    else if(strncmp(cLine,"Text",4)==0){
00404       char *String = (char *)calloc(265,sizeof(char));
00405       fgets(cLine,256,File2Read);
00406       for(int c=0;c<strlen(cLine);c++)
00407    String[c] = cLine[c];
00408       //      sscanf(cLine,"%s\n",String);
00409       fgets(cLine,256,File2Read);
00410       sscanf(cLine,"%lf %lf %lf %lf\n",Hue,Hue+1,Hue+2,Hue+3);
00411       fgets(cLine,256,File2Read);
00412       sscanf(cLine,"%lf %lf %lf %lf %lf %lf\n",From,From+1,From+2,To,To+1,To+2);
00413       glPushMatrix();
00414       glNormal3f(0.,0.,-1.);
00415       glColor4f(Hue[0],Hue[1],Hue[2],Hue[3]);
00416       glRasterPos3f(From[0]*Expand[0],From[1]*Expand[1],From[2]*Expand[2]);
00417       for(int i=0;i<strlen(String);i++)
00418    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,String[i]);
00419       glCallList(Point);
00420       glPopMatrix();
00421       free(String);
00422     }
00423     else if(strncmp(cLine,"Fog",3)==0){
00424       GLuint filter;
00425       GLuint fogMode[]= { GL_EXP, GL_EXP2, GL_LINEAR };
00426       fgets(cLine,256,File2Read);
00427       sscanf(cLine,"%lf %lf %lf %lf\n",Hue,Hue+1,Hue+2,Hue+3);
00428       fgets(cLine,256,File2Read);
00429       sscanf(cLine,"%lf %lf %lf %lf %lf %lf\n",From,From+1,From+2,To,To+1,To+2);
00430       GLuint fogfilter = From[0] > 2. ? 0 : (int) From[0];
00431       GLfloat fogColor[4]= {Hue[0], Hue[1], Hue[2], Hue[3]};
00432       glFogi(GL_FOG_MODE, fogMode[fogfilter]);
00433       glFogfv(GL_FOG_COLOR, fogColor);
00434       glFogf(GL_FOG_DENSITY, From[1]);
00435       glHint(GL_FOG_HINT, GL_DONT_CARE);
00436       glFogf(GL_FOG_START, From[2]*Expand[2]);
00437       glFogf(GL_FOG_END, To[2]*Expand[2]);
00438       glEnable(GL_FOG);
00439     }
00440     else if(strncmp(cLine,"Background",10)==0){
00441       fgets(cLine,256,File2Read);
00442       sscanf(cLine,"%lf %lf %lf %lf\n",Hue,Hue+1,Hue+2,Hue+3);
00443       glClearColor(Hue[0],Hue[1],Hue[2],Hue[3]);
00444     }
00445   }
00446   glEndList();
00447   fclose(File2Read);
00448   free(From);
00449   free(To);
00450   free(Hue);
00451   free(cLine);
00452 }
00453 #endif