00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "geom/texturegl.H"
00011 #include "mesh/uv_data.H"
00012
00013 #include "smooth_shade.H"
00014
00015
00016
00017
00018 void
00019 SmoothShadeStripCB::faceCB(CBvert* v, CBface* f)
00020 {
00021 using mlib::Wvec;
00022
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
00030 if (do_texcoords) {
00031
00032
00033
00034
00035
00036
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
00045 glVertex3dv(v->loc().data());
00046 }
00047
00048
00049
00050
00051 int
00052 SmoothShadeTexture::draw(CVIEWptr& v)
00053 {
00054 if (_ctrl)
00055 return _ctrl->draw(v);
00056 _cb->alpha = alpha();
00057
00058
00059 check_patch_texture_map();
00060
00061
00062
00063 _patch->apply_texture();
00064
00065
00066 glPushAttrib(GL_LIGHTING_BIT | GL_ENABLE_BIT | GL_CURRENT_BIT);
00067
00068 glEnable(GL_LIGHTING);
00069 glShadeModel(GL_SMOOTH);
00070
00071
00072
00073
00074
00075 GL_COL(_patch->color(), alpha());
00076
00077
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
00084 if (BasicTexture::dl_valid(v)) {
00085 BasicTexture::draw(v);
00086
00087
00088 glPopAttrib();
00089
00090 return _patch->num_faces();
00091 }
00092
00093
00094
00095 int dl = _dl.get_dl(v, 1, _patch->stamp());
00096 if (dl)
00097 glNewList(dl, GL_COMPILE);
00098
00099
00100 if (!set_face_culling())
00101 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
00102
00103 SmoothShadeStripCB *smooth_cb = dynamic_cast<SmoothShadeStripCB*>(_cb);
00104
00105
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
00113 _patch->draw_tri_strips(_cb);
00114
00115
00116 if (_dl.dl(v)) {
00117 _dl.close_dl(v);
00118
00119
00120 BasicTexture::draw(v);
00121 }
00122
00123
00124 glPopAttrib();
00125
00126 return _patch->num_faces();
00127 }
00128
00129