00001
00002
00003
00004
00005
00006 #include "color_id_texture.H"
00007 #include "ref_image.H"
00008
00009
00010
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
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
00055 glPushAttrib(mask |
00056 GL_LIGHTING_BIT |
00057 GL_CURRENT_BIT |
00058 GL_ENABLE_BIT);
00059
00060 glShadeModel(GL_FLAT);
00061 glDisable(GL_LIGHTING);
00062 glDisable(GL_BLEND);
00063 }
00064
00065 int
00066 ColorIDTexture::draw(CVIEWptr& v)
00067 {
00068 switch (_polygon_mode) {
00069 case GL_FILL:
00070
00071
00072 push_gl_state(0);
00073 set_face_culling();
00074 brcase GL_LINE:
00075
00076 push_gl_state(GL_LINE_BIT | GL_POLYGON_BIT);
00077 glLineWidth(_width);
00078 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
00079 glDisable(GL_CULL_FACE);
00080 brcase GL_POINT:
00081
00082 push_gl_state(GL_POINT_BIT | GL_POLYGON_BIT);
00083 glPointSize(_width);
00084 glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
00085 glDisable(GL_CULL_FACE);
00086 brdefault:
00087 err_msg( "ColorIDTexture::draw: error: unknown mode: %d", _polygon_mode);
00088 push_gl_state(0);
00089 }
00090
00091
00092
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
00102 glPopAttrib();
00103
00104
00105 if (_dl.dl(v)) {
00106 _dl.close_dl(v);
00107
00108
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
00123 ColorIDStripCB cb;
00124
00125
00126 push_gl_state(GL_LINE_BIT);
00127 if (!z_test)
00128 glDisable(GL_DEPTH_TEST);
00129 glLineWidth(width);
00130
00131
00132 edges->draw(&cb);
00133
00134
00135 glPopAttrib();
00136
00137
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
00148 ColorIDStripCB cb;
00149
00150
00151 push_gl_state(GL_POINT_BIT);
00152 if (!z_test)
00153 glDisable(GL_DEPTH_TEST);
00154 glPointSize(width);
00155
00156
00157 verts->draw(&cb);
00158
00159
00160 glPopAttrib();
00161
00162
00163 return verts->num();
00164 }
00165
00166
00167