/********************************************************************** * FlatShadeStripCB: **********************************************************************/ void FlatShadeStripCB::faceCB(CBvert* v, CBface* f) { // normal glNormal3dv(f->norm().data()); if (v->has_color()) { GL_COL(v->color(), alpha*v->alpha()); } // texture coords if (_do_texcoords) { if (_use_auto) { //force automatic //use spherical text coord gen glTexCoord2dv(_auto_UV->uv_from_vert(v,f).data()); } else { // the patch has a texture... try to find // appropriate texture coordinates... // use patch's TexCoordGen if possible, // otherwise use the texture coordinates stored // on the face (if any): TexCoordGen* tg = f->patch()->tex_coord_gen(); if (tg) glTexCoord2dv(tg->uv_from_vert(v,f).data()); else if (UVdata::lookup(f)) glTexCoord2dv(UVdata::get_uv(v,f).data()); } } // vertex coords glVertex3dv(v->loc().data()); }
/********************************************************************** * 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; }
void HalftoneShaderEx::set_gl_state(GLbitfield mask) const { GLSLShader::set_gl_state(mask); // set the color from the VIEW background color: GL_COL(VIEW::peek()->color(), alpha()); // GL_CURRENT_BIT }
void BinaryImageShader::draw_start( TEXTUREglptr toon_tex, // the 1D toon texture CCOLOR& base_color, // base color for triangles double base_alpha, // base alpha for triangles bool do_culling // enable backface culling ) { // init program get_instance()->init(); // set toon texture on static instance: get_instance()->set_tex(toon_tex); // set gl state glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT); if (do_culling) glEnable (GL_CULL_FACE); // GL_ENABLE_BIT else glDisable(GL_CULL_FACE); GL_COL(base_color, base_alpha); // GL_CURRENT_BIT // activate texture get_instance()->activate_textures(); // activate program get_instance()->activate_program(); // set uniform variables get_instance()->set_uniform_variables(); }
/********************************************************************** * 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; }
void BasecoatShader::set_gl_state(GLbitfield mask) const { GLSLShader::set_gl_state(mask); // let's not use the patch color, ok? // (at least until after the deadline) GL_COL(COLOR::white, alpha()); // GL_CURRENT_BIT }
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); }
void SimpleImageLineShader::set_gl_state(GLbitfield mask) const { GLSLShader::set_gl_state(mask); // set the color from the VIEW background color: GL_COL(VIEW::peek()->color(), alpha()); // GL_CURRENT_BIT glEnable(GL_BLEND); // GL_ENABLE_BIT glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // GL_COLOR_BUFFER_BIT }
void Halftone_TX::set_gl_state(GLbitfield mask) const { GLSLShader::set_gl_state(mask | GL_CURRENT_BIT | GL_DEPTH_BUFFER_BIT); if (_solid) GL_COL(get_base_color(), 1.0); glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_SRC_ALPHA); glDepthFunc(GL_LEQUAL); }
//******** TRI STRIPS ******** virtual void faceCB(CBvert* v, CBface* f) { assert(v && f); glNormal3dv(f->norm().data()); if (v->has_color()) { GL_COL(v->color(), alpha*v->alpha()); } //pass texture coordinates to opengl glTexCoord2dv(att_function->get_attrib(v,f).data()); send_d(v,f); glVertex3dv(v->loc().data()); // vertex coordinates }
int FlatShadeTexture::draw(CVIEWptr& v) { if (_ctrl) return _ctrl->draw(v); _cb->alpha = alpha(); if (!_patch) return 0; // Don't draw w/ texture maps if there are no uv coords at all. // but don't check every frame whether there are uv coords: if (_check_uv_coords_stamp != _patch->stamp()) { _has_uv_coords = _patch->cur_faces().any_satisfy(HasUVFaceFilter()); _check_uv_coords_stamp = _patch->stamp(); } // Set gl state (lighting, shade model) glPushAttrib(GL_ENABLE_BIT | GL_LIGHTING_BIT | GL_CURRENT_BIT); glEnable(GL_LIGHTING); // GL_ENABLE_BIT glShadeModel(GL_FLAT); // GL_LIGHTING_BIT GL_COL(_patch->color(), alpha()); // GL_CURRENT_BIT if (debug_uv()) { //assign some texture coords if no tex_coord_gen is assigned if (!_patch->tex_coord_gen()) { _patch->set_tex_coord_gen(new GLSphirTexCoordGen); } // decide what image file to use to show the uv-coords: str_ptr debug_uv_tex_name = Config::get_var_str("DEBUG_UV_TEX_MAP", "checkerboard.png",true); static str_ptr pre_path = Config::JOT_ROOT() + "nprdata/other_textures/"; str_ptr path = pre_path + debug_uv_tex_name; // we only try a given pathname once. but if it fails // and they reset DEBUG_UV_TEX_MAP while running the // program we can pick up the change and try again. if (path != _debug_tex_path) { _debug_tex_path = path; TEXTUREglptr tex = new TEXTUREgl(_debug_tex_path); bool do_mipmap = Config::get_var_bool("DEBUG_TEX_USE_MIPMAP",false); tex->set_mipmap(do_mipmap); _debug_uv_tex = tex; _debug_uv_in_dl = false; if (debug) { cerr << "Loading debug uv texture " << **path << " ..." << endl; } if (!_debug_uv_tex->load_texture()) { cerr << "Can't load debug uv texture: " << **_debug_tex_path << endl << "Set environment variable DEBUG_UV_TEX_MAP " << "to an image file in " << **pre_path << " and try again." << endl; _debug_uv_tex = 0; } } // Apply the texture if any faces have uv coordinates: if (_debug_uv_tex /*&& _has_uv_coords*/) //<- using auto UV _debug_uv_tex->apply_texture(); // GL_ENABLE_BIT } else { // XXX - dumb hack check_patch_texture_map(); // if (_has_uv_coords) <- using auto UV _patch->apply_texture(); // GL_ENABLE_BIT } // Set material parameters for OGL: GtexUtil::setup_material(_patch); // Try for the display list if it's valid if (!(_debug_uv == _debug_uv_in_dl && BasicTexture::draw(v))) { // Try to generate a display list int dl = _dl.get_dl(v, 1, _patch->stamp()); if (dl) { glNewList(dl, GL_COMPILE); _debug_uv_in_dl = _debug_uv; } // Set up face culling for closed surfaces if (!set_face_culling()) glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); // GL_LIGHTING_BIT FlatShadeStripCB *flat_cb = dynamic_cast<FlatShadeStripCB*>(_cb); if (flat_cb) { // send texture coordinates? if ((_debug_uv && _debug_uv_tex) || (_has_uv_coords && _patch->has_texture())) { flat_cb->enable_texcoords(); } else { flat_cb->disable_texcoords(); } } err_adv(debug && _debug_uv, " drawing uvs in flat shade"); // draw the triangle strips _patch->draw_tri_strips(_cb); // end the display list here if (_dl.dl(v)) { _dl.close_dl(v); // the display list is built; now execute it BasicTexture::draw(v); } } // restore GL state glPopAttrib(); // Have to move this outside the display list and gl push/pop attrib // or else it's all: /* FlatShadeTexture::draw - End ***NOTE*** OpenGL Error: [500] 'Invalid Enumerator' FlatShadeTexture::draw - End ***NOTE*** OpenGL Error: [500] 'Invalid Enumerator' FlatShadeTexture::draw - End ***NOTE*** OpenGL Error: [500] 'Invalid Enumerator' FlatShadeTexture::draw - End ***NOTE*** OpenGL Error: [500] 'Invalid Enumerator' FlatShadeTexture::draw - End ***NOTE*** OpenGL Error: [500] 'Invalid Enumerator' FlatShadeTexture::draw - End ***NOTE*** OpenGL Error: [500] 'Invalid Enumerator' FlatShadeTexture::draw - End ***NOTE*** OpenGL Error: [500] 'Invalid Enumerator' FlatShadeTexture::draw - End ***NOTE*** OpenGL Error: [500] 'Invalid Enumerator' */ if (_debug_uv) { // Build the edge strip at the current subdivision level Bedge_list edges = _patch->cur_edges(); edges.clear_flags(); // If secondary edges shouldn't be drawn, set their flags // so they won't be drawn: if (!BMESH::show_secondary_faces()) edges.secondary_edges().set_flags(1); // Draw uv-discontinuity boundaries as yellow lines. // Construct filter that accepts unreached uv-discontinuous // edges of this patch: UnreachedSimplexFilter unreached; UVDiscontinuousEdgeFilter uvdisc; PatchEdgeFilter mine(_patch->cur_patch()); EdgeStrip disc_edges(edges, unreached + uvdisc + mine); if (!disc_edges.empty()) { GtexUtil::draw_strip(disc_edges, 3, Color::yellow, 0.8); } } GL_VIEW::print_gl_errors("FlatShadeTexture::draw - End"); return _patch->num_faces(); }