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

color_id_texture.C

Go to the documentation of this file.
00001 /**********************************************************************
00002  * color_id_texture.C
00003  **********************************************************************/
00004 
00005 
00006 #include "color_id_texture.H"
00007 #include "ref_image.H"
00008 
00009 /**********************************************************************
00010  * ColorIDStripCB:
00011  **********************************************************************/
00012 void 
00013 ColorIDStripCB::vertCB(CBvert* v)
00014 {
00015    uint rgba = IDRefImage::key_to_rgba(v->key());
00016    glColor4ubv((GLubyte*)&rgba);
00017 
00018    glVertex3dv(v->loc().data());
00019 }
00020 
00021 void
00022 ColorIDStripCB::edgeCB(CBvert* v, CBedge* e)
00023 {
00024    uint rgba = IDRefImage::key_to_rgba(e->key());
00025    glColor4ubv((GLubyte*)&rgba);
00026 
00027    glVertex3dv(v->loc().data());
00028 }
00029 
00030 void 
00031 ColorIDStripCB::faceCB(CBvert* v, CBface* f)
00032 {
00033    uint rgba = IDRefImage::key_to_rgba(f->key());
00034    glColor4ubv((GLubyte*)&rgba);
00035 
00036    glVertex3dv(v->loc().data());
00037 }
00038 
00039 /*****************************************************************
00040  * ColorIDTexture
00041  *****************************************************************/
00042 ColorIDTexture::ColorIDTexture(Patch* patch, GLenum pmode) :
00043    BasicTexture(patch, new ColorIDStripCB),
00044    _width(5),
00045    _polygon_mode(pmode),
00046    _black(new SolidColorTexture(patch, COLOR::black))
00047 {
00048    _black->set_alpha(0);
00049 }
00050 
00051 void 
00052 ColorIDTexture::push_gl_state(GLbitfield mask)
00053 {
00054    // set attributes for this mode
00055    glPushAttrib(mask |
00056                 GL_LIGHTING_BIT |       // shade model
00057                 GL_CURRENT_BIT |        // current color
00058                 GL_ENABLE_BIT);         // lighting, culling, blending
00059 
00060    glShadeModel(GL_FLAT);               // GL_LIGHTING_BIT
00061    glDisable(GL_LIGHTING);              // GL_ENABLE_BIT
00062    glDisable(GL_BLEND);                 // GL_ENABLE_BIT
00063 }
00064 
00065 int
00066 ColorIDTexture::draw(CVIEWptr& v)
00067 {
00068    switch (_polygon_mode) {
00069     case GL_FILL:
00070       // filled triangles -- regular state
00071       // do backface culling for closed meshes
00072       push_gl_state(0);
00073       set_face_culling();                               // GL_ENABLE_BIT
00074     brcase GL_LINE:
00075       // wireframe triangles
00076       push_gl_state(GL_LINE_BIT | GL_POLYGON_BIT);
00077       glLineWidth(_width);                              // GL_LINE_BIT
00078       glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);        // GL_POLYGON_BIT
00079       glDisable(GL_CULL_FACE);                          // GL_ENABLE_BIT
00080     brcase GL_POINT:
00081       // drawing points for some strange reason
00082       push_gl_state(GL_POINT_BIT | GL_POLYGON_BIT);
00083       glPointSize(_width);                              // GL_POINT_BIT
00084       glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);       // GL_POLYGON_BIT
00085       glDisable(GL_CULL_FACE);                          // GL_ENABLE_BIT
00086     brdefault:
00087       err_msg( "ColorIDTexture::draw: error: unknown mode: %d", _polygon_mode);
00088       push_gl_state(0);
00089    }
00090 
00091    // draw triangles and/or polyline strips
00092    // use a display list if it's valid:
00093    if (!BasicTexture::draw(v)) {
00094 
00095       int dl = _dl.get_dl(v, 1, _patch->stamp());
00096       if (dl)
00097          glNewList(dl, GL_COMPILE);
00098 
00099       _patch->draw_tri_strips(_cb); 
00100 
00101       // restore gl state:
00102       glPopAttrib();
00103 
00104       // end the display list here
00105       if (_dl.dl(v)) {
00106          _dl.close_dl(v);
00107 
00108          // the display list is built; now execute it
00109          BasicTexture::draw(v);
00110       }
00111    }
00112 
00113    return _patch->num_faces();
00114 }
00115 
00116 int
00117 ColorIDTexture::draw_edges(EdgeStrip* edges, GLfloat width, bool z_test)
00118 {
00119    if (!edges)
00120       return 0;
00121 
00122    // need one of these for this static method:
00123    ColorIDStripCB  cb;
00124 
00125    // set regular state plus line width:
00126    push_gl_state(GL_LINE_BIT);
00127    if (!z_test)
00128       glDisable(GL_DEPTH_TEST); // GL_ENABLE_BIT
00129    glLineWidth(width);          // GL_LINE_BIT
00130 
00131    // draw edge strip
00132    edges->draw(&cb);
00133 
00134    // restore state
00135    glPopAttrib();
00136 
00137    // what do they want us to return?
00138    return edges->num();
00139 }
00140 
00141 int
00142 ColorIDTexture::draw_verts(VertStrip* verts, GLfloat width, bool z_test)
00143 {
00144    if (!verts)
00145       return 0;
00146 
00147    // need one of these for this static method:
00148    ColorIDStripCB  cb;
00149 
00150    // set regular state plus point size:
00151    push_gl_state(GL_POINT_BIT);
00152    if (!z_test)
00153       glDisable(GL_DEPTH_TEST); // GL_ENABLE_BIT
00154    glPointSize(width);          // GL_POINT_BIT
00155 
00156    // draw vert strip
00157    verts->draw(&cb);
00158 
00159    // restore state
00160    glPopAttrib();
00161 
00162    // what do they want us to return?
00163    return verts->num();
00164 }
00165 
00166 /* end of file color_id_texture.C */
00167 

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