void TEXT2D::draw_debug(const char* str, Wpt &pos, CVIEWptr& view) { if (view->rendering() == RCOLOR_ID || view->grabbing_screen()) return; if (!_dl.valid(view)) initialize(view); // GL initialization glPushAttrib(GL_ENABLE_BIT); // (GL_ENABLE_BIT) // No lighting glDisable(GL_LIGHTING); // Color //glColor3dv(COLOR::white.data()); glRasterPos3dv(pos.data()); glPushAttrib (GL_LIST_BIT); // (GL_LIST_BIT) glListBase(_dl.dl(view)); glCallLists(strlen(str), GL_UNSIGNED_BYTE, (GLubyte *) str); glPopAttrib (); // (GL_LIST_BIT) glEnable(GL_LIGHTING); glPopAttrib(); // (GL_ENABLE_BIT) glFlush(); }
/********************************************************************** * SilsTexture: **********************************************************************/ int SilsTexture::draw(CVIEWptr& v) { if (_ctrl) return _ctrl->draw(v); if (!_patch) return 0; static bool antialias = Config::get_var_bool("ANTIALIAS_SILS",true); if (antialias) { // push attributes, enable line smoothing, and set line width GL_VIEW::init_line_smooth(GLfloat(v->line_scale()*_width), GL_CURRENT_BIT); } else { // push attributes and set line width glPushAttrib(GL_LINE_BIT | GL_ENABLE_BIT | GL_CURRENT_BIT); glLineWidth(float(v->line_scale()*_width)); // GL_LINE_BIT } glDisable(GL_LIGHTING); // GL_ENABLE_BIT GL_COL(_color, alpha()); // GL_CURRENT_BIT if (_draw_borders) _patch->cur_sils().draw(_cb); else _patch->cur_sils().get_filtered(!BorderEdgeFilter()).draw(_cb); // restore gl state: glPopAttrib(); return 1; }
int INFLATE::draw(CVIEWptr& v) { int ret=0; // If needed, draw the boundary curve if (!_boundary.empty()) { // antialiased, 2 pixels wide GL_VIEW::init_line_smooth(GLfloat(v->line_scale()*2.0), GL_CURRENT_BIT); glDisable(GL_LIGHTING); // GL_ENABLE_BIT GL_COL(Color::orange, alpha()); // GL_CURRENT_BIT GLStripCB cb; _boundary.draw(&cb); // Draw the preview boundary build_lines(); GL_VIEW::end_line_smooth(); } // When all faded away, undraw if (alpha() == 0) WORLD::undisplay(this, false); return ret; }
int Bpoint::draw(CVIEWptr& v) { // draw to the screen: // XXX - should use some kind of stroke? update(); // draw if on-screen if (should_draw()) { // turn on antialiased and set point size GLfloat w = GLfloat(BPOINT_SIZE * v->line_scale()); GL_VIEW::init_point_smooth(w); glDisable(GL_LIGHTING); // GL_ENABLE_BIT glColor3dv(draw_color().data()); // GL_CURRENT_BIT // draw with a simple strip callback object: GLStripCB cb; _strip.draw(&cb); GL_VIEW::end_point_smooth(); // draw shadow if (is_selected()) draw_axes(); draw_debug(); } return 1; }
/********************************************************************** * CreasesTexture: **********************************************************************/ int CreasesTexture::draw(CVIEWptr& v) { if (_ctrl) return _ctrl->draw(v); // set line width, init line smoothing, and push attributes: GL_VIEW::init_line_smooth(GLfloat(v->line_scale()*_width), GL_CURRENT_BIT); GL_COL(_color, alpha()); // GL_CURRENT_BIT glDisable(GL_LIGHTING); // GL_ENABLE_BIT // draw creases (not view-dependent) if (!BasicTexture::draw(v)) { int dl = _dl.get_dl(v, 1, _patch->stamp()); if (dl) glNewList(dl, GL_COMPILE); _patch->draw_crease_strips(_cb); // restore gl state: GL_VIEW::end_line_smooth(); // end the display list here if (_dl.dl(v)) { _dl.close_dl(v); // the display list is built; now execute it BasicTexture::draw(v); } } return 1; }
/*********************************************************************** * Method : DLhandler::valid * Params : * Returns: bool * Effects: ***********************************************************************/ bool DLhandler::valid(CVIEWptr &v, int cmp_stamp) const { const int view_id = dl_per_view ? v->view_id() : 0; ((DLhandler *) this)->make_dl_stamp_big_enough(view_id); return ((_dl_stamp_array[view_id] != -1) && (_dl_stamp_array[view_id] >= cmp_stamp)); }
inline void add_render_styles(CVIEWptr& view, MoveMenu* menu) { str_list rend_modes = view->rend_list(); for (int i=0; i<rend_modes.num(); i++) { menu->items() += new RenderSet(view, rend_modes[i]); } }
void FFSControlFrameTexture::draw_level(CVIEWptr& v, int k) { // Draw the control curves for the Patch at level k, // which is relative to the control Patch. // Get the level-k edge strip: if (!build_strip(k)) return; assert(_strip != NULL); // Set line thickness and color // Get a scale factor s used to control line width and color. // s drops toward 0 exponentially with increasing level: double r = Config::get_var_dbl("CONTROL_FRAME_RATIO", 0.6,true); assert(r > 0 && r < 1); double s = pow(r, _strip->mesh()->subdiv_level()); // Default top-level line thickness is 1.0: double top_w = 1.0; double w = top_w*s; glLineWidth(GLfloat(v->line_scale()*w)); // GL_LINE_BIT // choose a lightest color: //COLOR l = interp(_color, COLOR::white, 0.75); // With white lines get too light in FFSTexture //l = interp(_color, COLOR(.659,.576,.467), 0.75); // line color drifts toward the light color as level k increases: //COLOR c = interp(l, _color, s); //GL_COL(c, alpha()); // GL_CURRENT_BIT GL_COL(_color, s/3); //paper //str_ptr tf = Config::JOT_ROOT() + "nprdata/paper_textures/simon.png"; //str_ptr ret_tf; //TEXTUREptr paper; //paper = PaperEffect::get_texture(tf, ret_tf); //PaperEffect::begin_paper_effect(paper); //PaperEffect::begin_paper_effect(VIEW::peek()->get_use_paper()); //for(int i=0; i < _strip->num(); i++){ // PaperEffect::paper_coord(NDCZpt(_strip->vert(i)->loc()).data()); // glTexCoord2dv(NDCZpt(_strip->vert(i)->loc()).data()); //} //paper _strip->draw(_cb); //PaperEffect::end_paper_effect(paper); }
//! Draw the special "fold points" of the curve, where it //! turns around WRT the sweep direction: int SWEEP_DISK::draw(CVIEWptr& v) { GL_VIEW::draw_pts( get_fold_pts(), Color::red_pencil, alpha(), v->line_scale()*10.0 ); if (!_profile.empty()) { GL_VIEW::draw_wpt_list(_profile, Color::red1, alpha(), v->line_scale()*5.0, false); } return SWEEP_BASE::draw(v); }
int FFSTexture::draw(CVIEWptr& v) { if(!_got_ffs_file){ get_ffs_data_file (); _got_ffs_file = true; } NPRTexture::draw(v); if(v->rendering() != "FFSTexture2") _controlframe->draw(v); return 0; }
/*********************************************************************** * Method : DLhandler::delete_dl * Params : * Returns: void * Effects: ***********************************************************************/ void DLhandler::delete_dl(CVIEWptr &v) { const int view_id = dl_per_view ? v->view_id() : 0; if (_dl_array.valid_index(view_id)) { if (_dl_array[view_id]) { glDeleteLists(_dl_array[view_id], 1); _dl_array[view_id] = 0; } _dl_stamp_array[view_id] = -1; } return; }
//********************** DRAWING ********************** int Patch::draw(CVIEWptr& v) { GTexture* cur = cur_tex(v); if (!cur) return 0; // if we just switched GTextures then setup a fade from // the old one to the new one: static const double FADE_DUR = Config::get_var_dbl("FADE_DUR", 0.5,true); if (_prev_tex && _prev_tex != cur && _init_fade) (*_init_fade)(cur, _prev_tex, v->frame_time(), FADE_DUR); _prev_tex = cur; int ret = cur->draw(v); _pixels.clear(); return ret; }
/********************************************************************** * FaderTexture: * * Fades from one texture to another over a given time interval. **********************************************************************/ int FaderTexture::draw(CVIEWptr& v) { // get the opacity of the fading texture: double a = fade(v->frame_time()); // put the base GTexture in charge of itself: _base->set_ctrl(nullptr); // are we done? if (a <= 0) { // our job is done int ret = _base->draw(v); // draw normally delete this; // kill ourselves return ret; } // If the fading-out texture doesn't draw the patch // triangles in filled mode, then all parts of the // fading-in texture need to use alpha = 1 - a. // // Otherwise, the fading-in texture can draw its filled // triangles (if any) with alpha = 1. In any case, // those parts of the fading-in texture that don't // correspond to filled triangles of the patch should // use alpha = 1 - a. // set GL state for blending the two glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT); glEnable(GL_BLEND); // GL_ENABLE_BIT glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // GL_COLOR_BUFFER_BIT // draw the base with alpha = 1 - a (where needed): _base->draw_filled_tris(_fader->draws_filled() ? 1.0 : 1-a); _fader->draw_with_alpha(a); _base->draw_non_filled_tris(1-a); // re-assert control of the base texture for next time: _base->set_ctrl(this); // restore state: glPopAttrib(); return _patch->num_faces(); }
/*********************************************************************** * Method : DLhandler::get_dl * Params : * Returns: int * Effects: Gets a display list - if one doesn't already exist, one * is created ***********************************************************************/ int DLhandler::get_dl(CVIEWptr &v, int num_dls, int set_stamp) { const int view_id = dl_per_view ? v->view_id() : 0; // If we're all set, don't panic: if (valid(v, set_stamp)) return _dl_array[view_id]; // Not all set, create a display list: make_dl_big_enough(view_id); if (_dl_array[view_id] == 0) { _dl_array[view_id] = glGenLists(num_dls); } make_dl_stamp_big_enough(view_id); _dl_stamp_array[view_id] = _dl_array[view_id] == 0 ? 0 : set_stamp; return _dl_array[view_id]; }
void GesturePathDrawer::draw_skeleton(const GESTURE* gest, CVIEWptr& v) { // load identity for model matrix glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); // set up to draw in PIXEL coords: glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadMatrixd(VIEW::peek()->pix_proj().transpose().matrix()); // Set up line drawing attributes glPushAttrib(GL_ENABLE_BIT | GL_LINE_BIT | GL_CURRENT_BIT); glDisable(GL_LIGHTING); // GL_ENABLE_BIT // turn on antialiasing for width-2 lines: GL_VIEW::init_line_smooth(GLfloat(v->line_scale()*2)); double grey = 0.3f; glColor3d(grey, grey, grey); // GL_CURRENT_BIT // draw the line strip const PIXEL_list& pts = gest->pts(); glBegin(GL_LINE_STRIP); for (PIXEL_list::size_type k=0; k<pts.size(); k++) { glVertex2dv(pts[k].data()); } glEnd(); // I tried to implement some code for corner getting highlighted // it is on the gesture.cpp version on Unnameable GL_VIEW::end_line_smooth(); glPopAttrib(); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); }
///////////////////////////////////// // init_camera() ///////////////////////////////////// void BaseJOTapp::init_camera(CVIEWptr &view) { // Set up the camera CAMptr cam(view->cam()); cam->data()->set_focal(0.1); cam->data()->set_width(0.1); cam->data()->set_height(0.1); cam->data()->set_from(Wpt(20, 30, 50)); cam->data()->set_at (Wpt::Origin()); cam->data()->set_up (Wpt(20, 31, 50)); if (Config::get_var_bool("BIRD_CAM",false,true)) { cam->data()->set_from(Wpt(0,0,0)); cam->data()->set_at (Wpt(0,0,-1)); cam->data()->set_up (Wpt(0,1,0)); } if (Config::get_var_bool("ORTHO_CAM",false,true)) { cam->data()->set_width(50); cam->data()->set_height(50); cam->data()->set_persp(false); } }
///////////////////////////////////// // draw() ///////////////////////////////////// int NPRSolidTexture::draw(CVIEWptr& v) { GL_VIEW_PRINT_GL_ERRORS("- Begin"); int dl; if (_ctrl) return _ctrl->draw(v); nst_paper_flag = (_use_paper==1)?(true):(false); if (!nst_is_init_vertex_program) nst_init_vertex_program(); if (nst_paper_flag) { // The enclosing NPRTexture will have already // rendered the mesh in 'background' mode. // We should enable blending and draw with // z <= mode... } update_tex(); glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT | GL_LIGHTING_BIT | GL_TEXTURE_BIT | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); GL_COL(_color, _alpha*alpha()); //GL_CURRENT_BIT /* if (_use_lighting) { GLboolean glbool; GLint glint; glEnable(GL_LIGHTING); //GL_ENABLE_BIT glShadeModel(GL_SMOOTH); //GL_LIGHTING_BIT GLfloat me[4], mad[4], ms[4], msh; // XXX - ATI barfs on this. It will light things // correctly using the fixed pipeline, but manual // queries of the material state (here, or in // vertex programs) fail to return the right // values when GL_COLOR_MATERIAL is enabled. // So, we'll just manually kil that mode, and // set the materials ourselves... // Used to be AMBIENT_AND_DIFFUSE tracking... right? glGetBooleanv(GL_COLOR_MATERIAL,&glbool); assert(glbool == GL_TRUE); glGetIntegerv(GL_COLOR_MATERIAL_FACE,&glint); assert(glint == GL_FRONT_AND_BACK); glGetIntegerv(GL_COLOR_MATERIAL_PARAMETER,&glint); assert(glint == GL_AMBIENT_AND_DIFFUSE); glDisable(GL_COLOR_MATERIAL); //GL_ENABLE_BIT glGetMaterialfv(GL_FRONT, GL_EMISSION, me); glGetFloatv( GL_CURRENT_COLOR, mad); glGetMaterialfv(GL_FRONT, GL_SHININESS, &msh); if (_light_specular) { ms[0] = ms[1] = ms[2] = ms[3] = 1.0f; } else { ms[0] = ms[1] = ms[2] = ms[3] = 0.0f; } glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, me); //GL_LIGHTING_BIT glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mad); //GL_LIGHTING_BIT glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mad); //GL_LIGHTING_BIT glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, ms); //GL_LIGHTING_BIT glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, msh); //GL_LIGHTING_BIT } */ if (_use_lighting) { glEnable(GL_LIGHTING); //GL_ENABLE_BIT glShadeModel(GL_SMOOTH); //GL_LIGHTING_BIT GLfloat ms[4]; if (_light_specular) { ms[0] = ms[1] = ms[2] = ms[3] = 1.0f; } else { ms[0] = ms[1] = ms[2] = ms[3] = 0.0f; } glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, ms); //GL_LIGHTING_BIT } else { glDisable(GL_LIGHTING); //GL_ENABLE_BIT } if (_tex) { _tex->apply_texture(); //GL_TEXTURE_BIT } //XXX - Just always blend, there may be alpha //in the texture... static bool OPAQUE_COMPOSITE = Config::get_var_bool("OPAQUE_COMPOSITE",false,true); if ((v->get_render_mode() == VIEW::TRANSPARENT_MODE) && (OPAQUE_COMPOSITE)) { glDisable(GL_BLEND); glBlendFunc(GL_ONE, GL_ZERO); } else { glEnable(GL_BLEND); //GL_ENABLE_BIT if (PaperEffect::is_alpha_premult()) glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); //GL_COLOR_BUFFER_BIT else glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //GL_COLOR_BUFFER_BIT } //Don't write depth if not using the background texture if (!_transparent) { glDepthMask(GL_FALSE); //GL_DEPTH_BUFFER_BIT } NDCZpt origin(0,0,0); if (nst_paper_flag && _travel_paper) { Wpt_list wbox; NDCZpt_list nbox; (_patch->xform() * _patch->mesh()->get_bb()).points(wbox); while (wbox.size() > 0) { nbox.push_back(wbox.back()); wbox.pop_back(); } static bool SCREEN_BOX = Config::get_var_bool("SCREEN_BOX",false,true); if (SCREEN_BOX) { double minx = nbox[0][0]; double maxx = nbox[0][0]; double miny = nbox[0][1]; double maxy = nbox[0][1]; for (NDCZpt_list::size_type i=1; i<nbox.size(); i++) { if (nbox[i][0] < minx) minx = nbox[i][0]; if (nbox[i][0] > maxx) maxx = nbox[i][0]; if (nbox[i][1] < miny) miny = nbox[i][1]; if (nbox[i][1] > maxy) maxy = nbox[i][1]; origin[0] = (minx + maxx)/2.0; origin[1] = (miny + maxy)/2.0; } } else { origin = nbox.average(); } } PaperEffect::begin_paper_effect(nst_paper_flag, origin[0], origin[1]); if (nst_use_vertex_program) { // Try it with the display list if ((_uv_in_dl == nst_tex_flag) && BasicTexture::dl_valid(v)) { nst_setup_vertex_program(_use_lighting==1); // GL_ENABLE_BIT, ??? BasicTexture::draw(v); nst_done_vertex_program(); PaperEffect::end_paper_effect(nst_paper_flag); glPopAttrib(); return _patch->num_faces(); } // Failed. Create it. dl = _dl.get_dl(v, 1, _patch->stamp()); if (dl) { glNewList(dl, GL_COMPILE); _uv_in_dl = nst_tex_flag; } } set_face_culling(); // GL_ENABLE_BIT _patch->draw_tri_strips(_cb); if (nst_use_vertex_program) { // End the display list here if (_dl.dl(v)) { _dl.close_dl(v); // Built it, now execute it nst_setup_vertex_program(_use_lighting==1); // GL_ENABLE_BIT, ??? BasicTexture::draw(v); nst_done_vertex_program(); } } PaperEffect::end_paper_effect(nst_paper_flag); glPopAttrib(); GL_VIEW_PRINT_GL_ERRORS("End"); return _patch->num_faces(); }
void GesturePathDrawer::draw_path(const GESTURE* gest, CVIEWptr& v) { // load identity for model matrix glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); // set up to draw in PIXEL coords: glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadMatrixd(VIEW::peek()->pix_proj().transpose().matrix()); // Set up line drawing attributes glPushAttrib(GL_ENABLE_BIT | GL_LINE_BIT | GL_CURRENT_BIT); glDisable(GL_LIGHTING); // GL_ENABLE_BIT // turn on antialiasing for width-2 lines: GL_VIEW::init_line_smooth(GLfloat(v->line_scale()*2)); double grey = 0.3f; glColor3d(grey, grey, grey); // GL_CURRENT_BIT // compute the thickness of the path if (gest->pts().size()<2) return; double thickness = 0.5 * gest->endpoint_dist(); const PIXEL_list& pts = _path_gesture->pts(); PIXEL_list::size_type nb_pts = pts.size(); // draw the upper line strip glBegin(GL_LINE_STRIP); for (PIXEL_list::size_type k=0; k<pts.size(); k++) { PIXEL rect_pt; compute_path_pt(pts, k, thickness, rect_pt); glVertex2dv(rect_pt.data()); } glEnd(); // draw the lower line strip glBegin(GL_LINE_STRIP); for (PIXEL_list::size_type k=0; k<pts.size(); k++) { PIXEL rect_pt; compute_path_pt(pts, k, -thickness, rect_pt); glVertex2dv(rect_pt.data()); } glEnd(); // draw ends PIXEL path_pt; glBegin(GL_LINES); compute_path_pt(pts, 0, thickness, path_pt); glVertex2dv(path_pt.data()); compute_path_pt(pts, 0, -thickness, path_pt); glVertex2dv(path_pt.data()); compute_path_pt(pts, nb_pts-1, thickness, path_pt); glVertex2dv(path_pt.data()); compute_path_pt(pts, nb_pts-1, -thickness, path_pt); glVertex2dv(path_pt.data()); glEnd(); // draw handle double light_gray = 0.7; glColor3d(light_gray, light_gray, light_gray); glBegin(GL_LINES); glVertex2dv(gest->start().data()); glVertex2dv(gest->end().data()); glEnd(); GL_VIEW::end_line_smooth(); glPopAttrib(); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); }
/********************************************************************** * ZcrossTexture: **********************************************************************/ int ZcrossTexture::draw(CVIEWptr& v) { if (_ctrl) return _ctrl->draw(v); // Ensure zcross strips are current, and get them _patch->mesh()->build_zcross_strips(); // Get a reference for low-overhead: //const ZcrossPath& zx_sils = _patch->zx_sils(); //needs to have a current sils (simon) const ZcrossPath& zx_sils = _patch->cur_zx_sils(); // Stop now, before making partial GL calls, if nothing is going on if (zx_sils.empty()) return 1; // Set line width, (optionally) enable antialiasing, and save GL state GLfloat w = float(v->line_scale()*_width); static bool antialias = Config::get_var_bool("ANTIALIAS_SILS",true,true); static bool drawback = Config::get_var_bool("DRAW_BACKFACING",false,true); if (antialias) { // push attributes, enable line smoothing, and set line width GL_VIEW::init_line_smooth(w, GL_CURRENT_BIT); } else { // push state, set line width glPushAttrib(GL_LINE_BIT | GL_ENABLE_BIT | GL_CURRENT_BIT); glLineWidth(w); // GL_LINE_BIT } glDisable(GL_BLEND); glDisable(GL_LIGHTING); // GL_ENABLE_BIT GL_COL(_color, alpha()); // GL_CURRENT_BIT // right now we're only doing OpenGL, ignoring CB int n = zx_sils.num(); bool started = false; bool lvis = false; bool vis = false; static bool nodots = Config::get_var_bool("ZX_NO_DOTS",false,true); static bool nocolor = Config::get_var_bool("ZX_NO_COLOR",false,true); //XXX - Hack. Not good when a loop isn't closed. // But I'm in a hurry to close proper loops... static bool closed = Config::get_var_bool("ZX_CLOSED",false,true); srand48(0); if (!nocolor) glColor3d ( drand48(), drand48(), drand48() ); else glColor3d ( 0.0, 0.0, 0.0 ); Wpt wp; if (!nodots) { glPointSize(5.0); glBegin ( GL_POINTS ) ; for ( int k =0 ; k < n; k++ ) { glColor3d ( 0.0 , 0.0 , 1.0 ); if ( zx_sils.face(k) == NULL ) glColor3d ( 1.0, 0, 0 ); glVertex3dv ( zx_sils.point(k).data() ); } glEnd(); } if ( !drawback ) { for (int i=0; i < n; i++) { vis = zx_sils.grad(i); // start new line strip if needed: if ( vis ) { //we are in a visible section of the curve if (!started ) { if ( zx_sils.face(i) ) { glBegin(GL_LINE_STRIP); zx_sils.face(i)->bc2pos ( zx_sils.bc(i) , wp ); glVertex3dv( wp.data()); started = true; } } else { if ( zx_sils.face(i) && i < n-1 ) { zx_sils.face(i)->bc2pos ( zx_sils.bc(i) , wp ); glVertex3dv( wp.data()); } else { zx_sils.face(i-1)->bc2pos ( zx_sils.bc(i) , wp ); glVertex3dv( wp.data()); glEnd(); started = false; } } } else if ( lvis && started ) { //this point is not visible, but the last one was. zx_sils.face(i-1)->bc2pos ( zx_sils.bc(i-1) , wp ); glVertex3dv( wp.data()); glEnd(); started=false; } lvis = vis; //if the face was null, we started a new loop if ( !zx_sils.face(i) ) { if (!nocolor) glColor3d ( drand48(), drand48(), drand48() ); else glColor3d ( 0.0, 0.0, 0.0); } } } else { //draw using barycentric values Wpt first; for (int i=0; i < n; i++) { vis = true; if ( vis ) { //we are in a visible section of the curve if (!started ) { if ( zx_sils.face(i) ) { glBegin(GL_LINE_STRIP); zx_sils.face(i)->bc2pos ( zx_sils.bc(i) , wp ); if (!nocolor) { if ( !zx_sils.grad(i) ) glColor3d( 1.0, 0.0 ,0.0 ); else glColor3d( 0.0 , 0.0, 1.0 ); } else { glColor3d( 0.0 , 0.0, 0.0 ); } first = wp; glVertex3dv( wp.data()); started = true; } } else { if (!nocolor) { if ( !zx_sils.grad(i) ) glColor3d( 1.0, 0.0 ,0.0 ); else glColor3d( 0.0 , 0.0, 1.0 ); } else glColor3d( 0.0 , 0.0, 0.0 ); if ( zx_sils.face(i) && i < n-1 ) { zx_sils.face(i)->bc2pos ( zx_sils.bc(i) , wp ); glVertex3dv( zx_sils.point(i).data()); } else { zx_sils.face(i-1)->bc2pos ( zx_sils.bc(i) , wp ); glVertex3dv( zx_sils.point(i-1).data()); if (closed) glVertex3dv( first.data()); glEnd(); started = false; } } } else if ( lvis && started ) { //this point is not visible, but the last one was. zx_sils.face(i-1)->bc2pos ( zx_sils.bc(i-1) , wp ); glVertex3dv( zx_sils.point(i-1).data()); glEnd(); started=false; } lvis = vis; } } // Restore GL state: if (antialias) GL_VIEW::end_line_smooth(); else glPopAttrib(); return 1; }
int LINE3D::draw(CVIEWptr& v) { // See draw_vis_ref() for why you wouldn't always want these params: return _draw(_color, _alpha, v->line_scale()*_width, _do_stipple); }
/************************************************************************* * Function Name: TEXT2D::draw * Parameters: * Returns: int * Effects: *************************************************************************/ int TEXT2D::draw( CVIEWptr &view ) { // leave the ID reference image alone, // and don't draw text into screen grabs: if (_suppress_draw || view->grabbing_screen()) return 0; // Get string we are going to display const char *s = get_string(); // quit early if we aren't displaying anything if (!s || *s == '\0') return 0; // No triangles // GL initialization glPushAttrib(GL_ENABLE_BIT | GL_LIST_BIT | GL_CURRENT_BIT | GL_LINE_BIT); // No lighting glDisable(GL_LIGHTING); // GL_ENABLE_BIT // Color if (_has_color) { glColor3dv(_color.data()); // GL_CURRENT_BIT } else { // draw black if background is light, // draw white if background is dark. if (HSVCOLOR(view->color())[2] > 0.5 && view->get_alpha() > 0.5) glColor3dv(Color::black.data()); else glColor3dv(Color::white.data()); } // Setup projection for drawing in XY coords glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadMatrixd(view->xypt_proj().transpose().matrix()); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); int highlight(HIGHLIGHTED.get(this)); if (highlight || _center ) { const int border = (_show_boxes || highlight > 1) ? 9 : 5; BBOX2D bbox(bbox2d(border, s, true)); int w, h; view->get_size(w, h); XYvec pixel(2.0 / double(w), 2.0 / double(h)); XYpt ll(bbox.min()), tr(bbox.max()); XYpt lr(bbox.max()[0],bbox.min()[1]), tl(bbox.min()[0],bbox.max()[1]); BBOX2D bboxll(ll, ll + pixel * border); BBOX2D bboxlr(lr - XYvec(pixel[0],0) * border, lr + XYvec(0, pixel[1])* border); BBOX2D bboxtl(tl - XYvec(0,pixel[1]) * border, tl + XYvec(pixel[0],0) * border); BBOX2D bboxtr(tr - pixel * border, tr); if (highlight) { glLineWidth(float(view->line_scale()*2)); // GL_LINE_BIT glBegin(GL_LINE_LOOP); glVertex2d(bbox.min()[0], bbox.min()[1]); glVertex2d(bbox.max()[0], bbox.min()[1]); glVertex2d(bbox.max()[0], bbox.max()[1]); glVertex2d(bbox.min()[0], bbox.max()[1]); glEnd(); if (_show_boxes || highlight > 1) { if (highlight == 2) glBegin(GL_POLYGON); else glBegin(GL_LINE_LOOP); glVertex2d(bboxll.min()[0], bboxll.min()[1]); glVertex2d(bboxll.max()[0], bboxll.min()[1]); glVertex2d(bboxll.max()[0], bboxll.max()[1]); glVertex2d(bboxll.min()[0], bboxll.max()[1]); glEnd(); if (highlight == 3) glBegin(GL_POLYGON); else glBegin(GL_LINE_LOOP); glVertex2d(bboxlr.min()[0], bboxlr.min()[1]); glVertex2d(bboxlr.max()[0], bboxlr.min()[1]); glVertex2d(bboxlr.max()[0], bboxlr.max()[1]); glVertex2d(bboxlr.min()[0], bboxlr.max()[1]); glEnd(); if (highlight == 4) glBegin(GL_POLYGON); else glBegin(GL_LINE_LOOP); glVertex2d(bboxtl.min()[0], bboxtl.min()[1]); glVertex2d(bboxtl.max()[0], bboxtl.min()[1]); glVertex2d(bboxtl.max()[0], bboxtl.max()[1]); glVertex2d(bboxtl.min()[0], bboxtl.max()[1]); glEnd(); if (highlight == 5) glBegin(GL_POLYGON); else glBegin(GL_LINE_LOOP); glVertex2d(bboxtr.min()[0], bboxtr.min()[1]); glVertex2d(bboxtr.max()[0], bboxtr.min()[1]); glVertex2d(bboxtr.max()[0], bboxtr.max()[1]); glVertex2d(bboxtr.min()[0], bboxtr.max()[1]); glEnd(); } glLineWidth(float(view->line_scale()*1)); } } else { // If this text is attached to a 3D point, project it to screen space // If this text is 2D, the location is stored in the xform(), so // copy that into _pt2d recompute_xform(); } // Initialize bitmaps for the letters if (!_dl.valid(view)) initialize(view); // Actually draw the text glRasterPos2d(_pt2d[0], _pt2d[1]); glListBase(_dl.dl(view)); glCallLists(strlen(s), GL_UNSIGNED_BYTE, (GLubyte *) s); // Restore projection matrix glMatrixMode(GL_PROJECTION); glPopMatrix(); // Restore modelview matrix glMatrixMode(GL_MODELVIEW); glPopMatrix(); // Restore gl state glPopAttrib(); return 0; // No triangles }
///////////////////////////////////// // draw() ///////////////////////////////////// int NPRBkgTexture::draw(CVIEWptr& v) { static bool debug_vis = Config::get_var_bool("HATCHING_DEBUG_VIS",false,true); if (_ctrl) return _ctrl->draw(v); nbt_tex_flag = (v->get_bkg_tex() != NULL); nbt_paper_flag = v->get_use_paper(); if (!nbt_is_init_vertex_program) nbt_init_vertex_program(); if (nbt_paper_flag) { //Do anything special? } glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT | GL_HINT_BIT | GL_TEXTURE_BIT | GL_COLOR_BUFFER_BIT | GL_LIGHTING_BIT); GL_COL(v->color(), v->get_alpha()*alpha()); // GL_CURRENT_BIT glDisable(GL_LIGHTING); // GL_ENABLE_BIT if (debug_vis) glShadeModel(GL_FLAT); // GL_LIGHTING_BIT if (nbt_tex_flag) { TEXTUREptr tex = v->get_bkg_tex(); tex->apply_texture(&v->get_bkg_tf()); // GL_TEXTURE_BIT } glEnable(GL_BLEND); // GL_ENABLE_BIT if (PaperEffect::is_alpha_premult()) glBlendFunc(GL_ONE, GL_ZERO); // GL_COLOR_BUFFER_BIT else glBlendFunc(GL_SRC_ALPHA, GL_ZERO); // GL_COLOR_BUFFER_BIT PaperEffect::begin_paper_effect(nbt_paper_flag); int dl = 0; if (nbt_use_vertex_program) { // Try it with the display list if (BasicTexture::dl_valid(v)) { nbt_setup_vertex_program(); // GL_ENABLE_BIT, ??? BasicTexture::draw(v); nbt_done_vertex_program(); // GL_ENABLE_BIT, ??? PaperEffect::end_paper_effect(nbt_paper_flag); glPopAttrib(); return _patch->num_faces(); } // Failed. Create it. dl = _dl.get_dl(v, 1, _patch->stamp()); if (dl) glNewList(dl, GL_COMPILE); } set_face_culling(); // GL_ENABLE_BIT _patch->draw_tri_strips(_cb); if (nbt_use_vertex_program) { // End the display list here if (_dl.dl(v)) { _dl.close_dl(v); // Built it, now execute it nbt_setup_vertex_program(); // GL_ENABLE_BIT, ??? BasicTexture::draw(v); nbt_done_vertex_program(); // GL_ENABLE_BIT, ??? } } PaperEffect::end_paper_effect(nbt_paper_flag); glPopAttrib(); return _patch->num_faces(); }
/*********************************************************************** * Method : DLhandler::dl * Params : * Returns: int * Effects: ***********************************************************************/ int DLhandler::dl(CVIEWptr &v) const { const int view_id = dl_per_view ? v->view_id() : 0; return _dl_array[view_id]; }
/************************************************************************* * Function Name: ICON2D::draw * Parameters: * Returns: int * Effects: *************************************************************************/ int ICON2D::draw( CVIEWptr &view ) { // leave the ID reference image alone, // and don't draw ICON into screen grabs: if (_suppress_draw || view->grabbing_screen() || _hide) return 0; TEXTUREglptr tex = _texture[_currentTex]; if (!load_texture(tex)) { cerr << "ICON2D::draw: can't load texture, skipping..." << endl; return 0; } //set up needed attributes glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT); // Load identity for model view glMatrixMode(GL_MODELVIEW); // GL_TRANSFORM_BIT glPushMatrix(); glLoadIdentity(); // Setup projection for drawing in PIXEL coords glMatrixMode(GL_PROJECTION); // GL_TRANSFORM_BIT glPushMatrix(); glLoadMatrixd(view->pix_proj().transpose().matrix()); glDisable(GL_LIGHTING); // GL_ENABLE_BIT glDisable(GL_CULL_FACE); // GL_ENABLE_BIT glDisable(GL_DEPTH_TEST); // GL_ENABLE_BIT // XXX - probably don't need alpha blending, but it's on: glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // activate texture if (_toggle && _active) _act_tex->apply_texture(); // texture for active icon else _texture[_currentTex]->apply_texture(); // texture for normal icon // XXX - debug: color should be covered by the texture: glColor4fv(float4(Color::yellow,0.5)); // draw a textured quad in pixel space for the icon: glBegin(GL_QUAD_STRIP); glTexCoord2f(0.0, 1.0); glVertex2dv((_pix + VEXEL( 0,32)).data()); glTexCoord2f(0.0, 0.0); glVertex2dv((_pix + VEXEL( 0, 0)).data()); glTexCoord2f(1.0, 1.0); glVertex2dv((_pix + VEXEL(32,32)).data()); glTexCoord2f(1.0, 0.0); glVertex2dv((_pix + VEXEL(32, 0)).data()); glEnd(); // restore the matrix stacks: glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); //restore attributes glPopAttrib(); return 0; }
int SolidColorTexture::draw(CVIEWptr& v) { if (_ctrl) return _ctrl->draw(v); bool show_weights = debug_patch_blend; if (show_weights) { if (!dynamic_cast<PatchBlendStripCB*>(cb())) { set_cb(new PatchBlendStripCB(patch())); assert(dynamic_cast<PatchBlendStripCB*>(cb())); } } else if (dynamic_cast<PatchBlendStripCB*>(cb())) { dynamic_cast<PatchBlendStripCB*>(cb())->set_patch(0); } // push GL state before changing things glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT | GL_COLOR_BUFFER_BIT); // Set the color COLOR c = _color; double a = _alpha*alpha(); if (_track_view_color) c = v->color(); glColor4fv(float4(c,a)); // try it with the display list: if (BasicTexture::draw(v)) return _patch->num_faces(); // ensure this never happens again! get a display list: int dl = _dl.get_dl(v, 1, _patch->stamp()); if (dl) glNewList(dl, GL_COMPILE); glDisable(GL_LIGHTING); // GL_ENABLE_BIT // set up face culling for closed surfaces set_face_culling(); // GL_ENABLE_BIT // draw the triangle strips PatchBlendStripCB* pbcb = dynamic_cast<PatchBlendStripCB*>(cb()); if (show_weights) { glEnable(GL_BLEND); // GL_ENABLE_BIT glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // GL_COLOR_BUFFER_BIT if (Config::get_var_bool("DEBUG_PATCH_BLEND_WEIGHTS",false)) { cerr << "SolidColorTexture::draw: patch " << mesh()->patches().get_index(patch()) << ": drawing patch blend weights" << endl; } mesh()->update_patch_blend_weights(); assert(pbcb); pbcb->set_patch(patch()->cur_patch()); pbcb->set_color(c,a); _patch->draw_n_ring_triangles( mesh()->patch_blend_smooth_passes() + 1, pbcb, false ); // draw the boundary w/ given line width and color: EdgeStrip bdry = patch()->cur_faces().get_boundary(); GtexUtil::draw_strip(bdry, 2, Color::yellow); } else { if (pbcb) pbcb->set_patch(0); _patch->draw_tri_strips(_cb); } // restore gl state: glPopAttrib(); // end the display list here if (_dl.dl(v)) { _dl.close_dl(v); // the display list is built; now execute it BasicTexture::draw(v); } return _patch->num_faces(); }