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

smooth_shade.C

Go to the documentation of this file.
00001 /*!
00002  *  \file smooth_shade.C
00003  *  \brief Contains the implementation of the SmoothShadeTexture GTexture and
00004  *  related classes.
00005  *
00006  *  \sa smooth_shade.H
00007  *
00008  */
00009 
00010 #include "geom/texturegl.H"
00011 #include "mesh/uv_data.H"
00012 
00013 #include "smooth_shade.H"
00014 
00015 /**********************************************************************
00016  * SmoothShadeStripCB:
00017  **********************************************************************/
00018 void 
00019 SmoothShadeStripCB::faceCB(CBvert* v, CBface* f) 
00020 {
00021    using mlib::Wvec;
00022    // normal
00023    Wvec n;
00024    glNormal3dv(f->vert_normal(v,n).data());
00025 
00026    if (v->has_color())
00027       GL_COL(v->color(), alpha*v->alpha());
00028 
00029    // texture coords
00030    if (do_texcoords) {
00031       // the patch has a texture... try to find
00032       // appropriate texture coordinates...
00033 
00034       // use patch's TexCoordGen if possible,
00035       // otherwise use the texture coordinates stored
00036       // on the face (if any):
00037       TexCoordGen* tg = f->patch()->tex_coord_gen();
00038       if (tg)
00039          glTexCoord2dv(tg->uv_from_vert(v,f).data());
00040       else if (UVdata::lookup(f))
00041          glTexCoord2dv(UVdata::get_uv(v,f).data());
00042    }
00043 
00044    // vertex coords
00045    glVertex3dv(v->loc().data());
00046 }
00047 
00048 /**********************************************************************
00049  * SmoothShadeTexture:
00050  **********************************************************************/
00051 int
00052 SmoothShadeTexture::draw(CVIEWptr& v)
00053 {
00054    if (_ctrl)
00055       return _ctrl->draw(v);
00056    _cb->alpha = alpha();
00057 
00058    // XXX - dumb hack
00059    check_patch_texture_map();
00060 
00061    // this is a no-op unless needed:
00062    // (don't put it inside display list creation):
00063    _patch->apply_texture();
00064 
00065    // set gl state (lighting, shade model)
00066    glPushAttrib(GL_LIGHTING_BIT | GL_ENABLE_BIT | GL_CURRENT_BIT);
00067 
00068    glEnable(GL_LIGHTING);                       // GL_LIGHTING_BIT
00069    glShadeModel(GL_SMOOTH);                     // GL_LIGHTING_BIT
00070 
00071 //    // XXX - for debugging
00072 //    glEnable(GL_DEPTH_TEST);
00073 
00074    // set color (affects GL_CURRENT_BIT):
00075    GL_COL(_patch->color(), alpha()); // GL_CURRENT_BIT
00076    
00077    // set material:
00078    GL_MAT_COLOR(GL_FRONT_AND_BACK, GL_AMBIENT, _patch->ambient_color(), alpha());
00079    GL_MAT_COLOR(GL_FRONT_AND_BACK, GL_DIFFUSE, _patch->color(), alpha());
00080    GL_MAT_COLOR(GL_FRONT_AND_BACK, GL_SPECULAR, _patch->specular_color(), alpha());
00081    glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, static_cast<GLfloat>(_patch->shininess()));
00082 
00083    // execute display list if it's valid:
00084    if (BasicTexture::dl_valid(v)) {
00085       BasicTexture::draw(v);
00086 
00087       // restore gl state:
00088       glPopAttrib();
00089 
00090       return _patch->num_faces();
00091    }
00092 
00093 
00094    // try to generate a display list
00095    int dl = _dl.get_dl(v, 1, _patch->stamp());
00096    if (dl)
00097       glNewList(dl, GL_COMPILE);
00098 
00099    // set up face culling for closed surfaces
00100    if (!set_face_culling()) 
00101       glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);  // GL_LIGHTING_BIT
00102    
00103    SmoothShadeStripCB *smooth_cb = dynamic_cast<SmoothShadeStripCB*>(_cb);
00104 
00105    // turn on texturing if any
00106    if (_patch->has_texture()){
00107       if (smooth_cb) smooth_cb->enable_texcoords();
00108    } else {
00109       if(smooth_cb) smooth_cb->disable_texcoords();
00110    }
00111 
00112    // draw the triangle strips
00113    _patch->draw_tri_strips(_cb);
00114 
00115    // end the display list here
00116    if (_dl.dl(v)) {
00117       _dl.close_dl(v);
00118 
00119       // the display list is built; now execute it
00120       BasicTexture::draw(v);
00121    }
00122 
00123    // restore gl state:
00124    glPopAttrib();
00125 
00126    return _patch->num_faces();
00127 }
00128 
00129 /* end of file smooth_shade.C */

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