Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

zxsils_texture.C

Go to the documentation of this file.
00001 /**********************************************************************
00002  * sils_texture.C
00003  **********************************************************************/
00004 
00005 #include "std/config.H"
00006 #include "geom/gl_view.H"
00007 #include "zxsils_texture.H"
00008 
00009 using mlib::Wpt;
00010 
00011 /**********************************************************************
00012  * ZcrossTexture:
00013  **********************************************************************/
00014 int
00015 ZcrossTexture::draw(CVIEWptr& v)
00016 {
00017    if (_ctrl)
00018       return _ctrl->draw(v);
00019 
00020    // Ensure zcross strips are current, and get them
00021    _patch->mesh()->build_zcross_strips();
00022 
00023    // Get a reference for low-overhead:
00024    //const ZcrossPath& zx_sils = _patch->zx_sils();
00025 
00026    //needs to have a current sils (simon)
00027    const ZcrossPath& zx_sils = _patch->cur_zx_sils();
00028    // Stop now, before making partial GL calls, if nothing is going on
00029    if (zx_sils.empty())
00030       return 1;
00031 
00032    // Set line width, (optionally) enable antialiasing, and save GL state
00033    GLfloat w = float(v->line_scale()*_width);
00034    static bool antialias = Config::get_var_bool("ANTIALIAS_SILS",true,true);
00035    static bool drawback = Config::get_var_bool("DRAW_BACKFACING",false,true);
00036    if (antialias) {
00037       // push attributes, enable line smoothing, and set line width
00038       GL_VIEW::init_line_smooth(w, GL_CURRENT_BIT);
00039    } else {
00040       // push state, set line width
00041       glPushAttrib(GL_LINE_BIT | GL_ENABLE_BIT | GL_CURRENT_BIT);
00042       glLineWidth(w); // GL_LINE_BIT
00043    }
00044 
00045    glDisable(GL_BLEND);
00046    glDisable(GL_LIGHTING);      // GL_ENABLE_BIT
00047    GL_COL(_color, alpha());     // GL_CURRENT_BIT
00048 
00049 
00050    // right now we're only doing OpenGL, ignoring CB
00051    int n = zx_sils.num();
00052    bool started = false;
00053    bool lvis = false;
00054    bool vis = false;
00055 
00056    static bool nodots = Config::get_var_bool("ZX_NO_DOTS",false,true);
00057    static bool nocolor = Config::get_var_bool("ZX_NO_COLOR",false,true);
00058    //XXX - Hack. Not good when a loop isn't closed.
00059    // But I'm in a hurry to close proper loops...
00060    static bool closed = Config::get_var_bool("ZX_CLOSED",false,true);
00061 
00062    srand48(0);
00063    if (!nocolor)
00064       glColor3d ( drand48(), drand48(), drand48() );
00065    else
00066       glColor3d ( 0.0, 0.0, 0.0 );
00067 
00068    Wpt wp;
00069 
00070    if (!nodots) {
00071       glPointSize(5.0);
00072       glBegin ( GL_POINTS ) ;
00073       for ( int k =0 ; k < n; k++ ) {
00074          glColor3d ( 0.0 , 0.0 , 1.0 );
00075          if ( zx_sils.face(k) == NULL )
00076             glColor3d ( 1.0, 0, 0 );
00077          glVertex3dv ( zx_sils.point(k).data() );
00078       }
00079       glEnd();
00080    }
00081    if ( !drawback ) {
00082       for (int i=0; i < n; i++) {
00083 
00084          vis = zx_sils.grad(i);
00085 
00086          // start new line strip if needed:
00087          if ( vis ) {
00088             //we are in a visible section of the curve
00089             if (!started ) {
00090                if ( zx_sils.face(i) ) {
00091                   glBegin(GL_LINE_STRIP);
00092                   zx_sils.face(i)->bc2pos ( zx_sils.bc(i) , wp );
00093                   glVertex3dv( wp.data());
00094                   started = true;
00095                }
00096             } else {
00097                if ( zx_sils.face(i) && i < n-1 ) {
00098                   zx_sils.face(i)->bc2pos ( zx_sils.bc(i) , wp );
00099                   glVertex3dv( wp.data());
00100                } else {
00101                   zx_sils.face(i-1)->bc2pos ( zx_sils.bc(i) , wp );
00102                   glVertex3dv( wp.data());
00103                   glEnd();
00104                   started = false;
00105                }
00106             }
00107          } else if ( lvis && started ) {
00108             //this point is not visible, but the last one was.
00109             zx_sils.face(i-1)->bc2pos ( zx_sils.bc(i-1) , wp );
00110             glVertex3dv( wp.data());
00111             glEnd();
00112             started=false;
00113          }
00114          lvis = vis;
00115          //if the face was null, we started a new loop
00116          if ( !zx_sils.face(i) ) {
00117             if (!nocolor)
00118                glColor3d ( drand48(), drand48(), drand48() );
00119             else
00120                glColor3d ( 0.0, 0.0, 0.0);
00121          }
00122       }
00123    } else {  //draw using barycentric values
00124       Wpt first;
00125       for (int i=0; i < n; i++) {
00126          vis = true;
00127          if ( vis ) {
00128             //we are in a visible section of the curve
00129             if (!started ) {
00130                if ( zx_sils.face(i) ) {
00131                   glBegin(GL_LINE_STRIP);
00132                   zx_sils.face(i)->bc2pos ( zx_sils.bc(i) , wp );
00133                   if (!nocolor) {
00134                      if ( !zx_sils.grad(i) )
00135                         glColor3d( 1.0, 0.0 ,0.0 );
00136                      else
00137                         glColor3d( 0.0 , 0.0, 1.0 );
00138                   } else {
00139                      glColor3d( 0.0 , 0.0, 0.0 );
00140                   }
00141                   first = wp;
00142                   glVertex3dv( wp.data());
00143                   started = true;
00144                }
00145             } else {
00146                if (!nocolor) {
00147                   if ( !zx_sils.grad(i) )
00148                      glColor3d( 1.0, 0.0 ,0.0 );
00149                   else
00150                      glColor3d( 0.0 , 0.0, 1.0 );
00151                } else
00152                   glColor3d( 0.0 , 0.0, 0.0 );
00153 
00154                if ( zx_sils.face(i) && i < n-1 ) {
00155                   zx_sils.face(i)->bc2pos ( zx_sils.bc(i) , wp );
00156                   glVertex3dv( zx_sils.point(i).data());
00157                } else {
00158                   zx_sils.face(i-1)->bc2pos ( zx_sils.bc(i) , wp );
00159                   glVertex3dv( zx_sils.point(i-1).data());
00160                   if (closed)
00161                      glVertex3dv( first.data());
00162                   glEnd();
00163                   started = false;
00164                }
00165             }
00166          } else if ( lvis && started ) {
00167             //this point is not visible, but the last one was.
00168             zx_sils.face(i-1)->bc2pos ( zx_sils.bc(i-1) , wp );
00169             glVertex3dv( zx_sils.point(i-1).data());
00170             glEnd();
00171             started=false;
00172          }
00173          lvis = vis;
00174       }
00175    }
00176 
00177    // Restore GL state:
00178    if (antialias)
00179       GL_VIEW::end_line_smooth();
00180    else
00181       glPopAttrib();
00182 
00183    return 1;
00184 }
00185 
00186 // end of file sils_texture.C

Generated on Mon Sep 18 11:39:34 2006 for jot by  doxygen 1.4.4