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

key_line.C

Go to the documentation of this file.
00001 /**********************************************************************
00002  * key_line.C
00003  **********************************************************************/
00004 #include "disp/colors.H"
00005 #include "geom/gl_view.H"
00006 #include "mesh/patch.H"
00007 
00008 #include "key_line.H"
00009 #include "solid_color.H"
00010 #include "toon_texture_1D.H"
00011 #include "sil_frame.H"
00012 
00013 bool KeyLineTexture::_show_hidden = false;
00014 
00015 inline COLOR
00016 patch_color(Patch* p, CCOLOR& default_color = Color::white)
00017 {
00018    return (p && p->has_color()) ? p->color() : default_color;
00019 }
00020 
00021 /**********************************************************************
00022  * KeyLineTexture:
00023  **********************************************************************/
00024 KeyLineTexture::KeyLineTexture(Patch* patch) :
00025    OGLTexture(patch),
00026    _solid(new SolidColorTexture(patch, patch_color(patch))),
00027    _toon(new ToonTexture_1D(patch)), //using the old toon texture shader V1.3
00028    _sil_frame(new SilFrameTexture(patch))
00029 {
00030    _toon->set_tex_name("nprdata/toon_textures/clear-gray-keyline.png");
00031 
00032 
00033    float w = (float)Config::get_var_dbl("KEYLINE_SIL_WIDTH", 3.0,true);
00034    _sil_frame->set_sil_width(w);
00035 }
00036 
00037 KeyLineTexture::~KeyLineTexture()
00038 {
00039    gtextures().delete_all();
00040 }
00041 
00042 int
00043 KeyLineTexture::set_color(CCOLOR& c)
00044 {
00045    // create a lighter shade for the base coat,
00046    // and a darker shade for the toon shading:
00047    _solid->set_color(interp(c, Color::white, 0.5));
00048    _toon->set_color(interp(c, Color::black, 0.5));  //test should be black
00049 
00050    return 1;
00051 }
00052 
00053 int
00054 KeyLineTexture::set_sil_color(CCOLOR& c)
00055 {
00056    _sil_frame->set_color(c);
00057    return 1;
00058 }
00059 
00060 int
00061 KeyLineTexture::draw(CVIEWptr& v)
00062 {
00063    if (_ctrl)
00064       return _ctrl->draw(v);
00065 
00066    glPushAttrib(GL_ENABLE_BIT | GL_DEPTH_BUFFER_BIT);
00067    glDepthFunc(GL_LEQUAL);
00068 
00069    if (_patch->has_color())
00070       set_color(_patch->color());
00071 
00072    _solid->draw(v);
00073    _toon->draw(v);
00074 
00075    if (_show_hidden)
00076       draw_hidden(v);
00077 
00078    _sil_frame->draw(v);
00079 
00080    glPopAttrib();
00081 
00082    return _patch->num_faces();
00083 }
00084 
00085 int
00086 KeyLineTexture::draw_hidden(CVIEWptr& v)
00087 {
00088    // Save OpenGL state:
00089    glPushAttrib(GL_ENABLE_BIT | GL_LINE_BIT | GL_CURRENT_BIT);
00090 
00091    // Set new OpenGL state:
00092    glLineStipple(1,0x00ff);     // GL_LINE_BIT
00093    glEnable(GL_LINE_STIPPLE);   // GL_ENABLE_BIT
00094    glDisable(GL_DEPTH_TEST);    // GL_ENABLE_BIT
00095 
00096    // Find current line widths and colors...
00097    COLOR s_col = _sil_frame->sil_color();
00098    COLOR c_col = _sil_frame->crease_color();
00099    GLfloat s_width = _sil_frame->sil_width();
00100    GLfloat c_width = _sil_frame->crease_width();
00101 
00102    // Draw thinner, lighter lines:
00103    _sil_frame->set_sil_width(GLfloat(s_width * 0.75));
00104    _sil_frame->set_crease_width(GLfloat(c_width * 0.75));
00105    _sil_frame->set_sil_color(interp(s_col, COLOR::white, 0.3));
00106    _sil_frame->set_crease_color(interp(c_col, COLOR::white, 0.3));
00107 
00108    // Draw silhouettes and creases in dotted style, no depth testing:
00109    _sil_frame->draw(v);
00110 
00111    // Restore line widths and colors:
00112    _sil_frame->set_sil_width(s_width);
00113    _sil_frame->set_crease_width(c_width);
00114    _sil_frame->set_sil_color(s_col);
00115    _sil_frame->set_crease_color(c_col);
00116 
00117    // Restore old OpenGL state:
00118    glPopAttrib();
00119 
00120    return _patch->num_faces();
00121 }
00122 
00123 void 
00124 KeyLineTexture::draw_filled_tris(double alpha) 
00125 {
00126    _solid->draw_with_alpha(alpha);
00127    _toon->draw_with_alpha(alpha);
00128 }
00129 
00130 void 
00131 KeyLineTexture::draw_non_filled_tris(double alpha) 
00132 {
00133    _sil_frame->draw_with_alpha(alpha);
00134 }
00135 
00136 // end of file key_line.C

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