From fcde390416e9c3e44e1d60bf8aeeb4add62f828b Mon Sep 17 00:00:00 2001 From: clifford Date: Fri, 24 Jul 2009 08:22:05 +0000 Subject: Clifford Wolf: Improved background and highlights rendering git-svn-id: http://svn.clifford.at/openscad/trunk@71 b57f626f-c46c-0410-a088-ec61d464b74c diff --git a/csgops.cc b/csgops.cc index a5f82e0..451c4c4 100644 --- a/csgops.cc +++ b/csgops.cc @@ -72,6 +72,8 @@ CGAL_Nef_polyhedron CsgNode::render_cgal_nef_polyhedron() const bool first = true; CGAL_Nef_polyhedron N; foreach (AbstractNode *v, children) { + if (v->modinst->tag_background) + continue; if (first) { N = v->render_cgal_nef_polyhedron(); first = false; diff --git a/mainwin.cc b/mainwin.cc index 26723d3..8032ff5 100644 --- a/mainwin.cc +++ b/mainwin.cc @@ -864,11 +864,10 @@ static void renderGLviaOpenCSG(void *vp) shaderinfo = NULL; renderCSGChainviaOpenCSG(m->root_chain, m->actViewModeShowEdges->isChecked() ? shaderinfo : NULL, false, false); if (m->background_chain) { - renderCSGChainviaOpenCSG(m->background_chain, shaderinfo, false, true); + renderCSGChainviaOpenCSG(m->background_chain, m->actViewModeShowEdges->isChecked() ? shaderinfo : NULL, false, true); } if (m->highlights_chain) { - glDisable(GL_LIGHTING); - renderCSGChainviaOpenCSG(m->highlights_chain, shaderinfo, true, false); + renderCSGChainviaOpenCSG(m->highlights_chain, m->actViewModeShowEdges->isChecked() ? shaderinfo : NULL, true, false); } } } @@ -951,35 +950,58 @@ void MainWindow::viewModeCGALGrid() #endif /* ENABLE_CGAL */ -static void renderGLThrownTogether(void *vp) -{ - MainWindow *m = (MainWindow*)vp; - if (m->root_chain) { - glDepthFunc(GL_LEQUAL); - QHash polySetVisitMark; - bool showEdges = m->actViewModeShowEdges->isChecked(); - for (int i = 0; i < m->root_chain->polysets.size(); i++) { - if (polySetVisitMark[m->root_chain->polysets[i]]++ > 0) - continue; - if (m->root_chain->types[i] == CSGTerm::DIFFERENCE) { - m->root_chain->polysets[i]->render_surface(PolySet::COLOR_CUTOUT); - if (showEdges) { - glDisable(GL_LIGHTING); - m->root_chain->polysets[i]->render_edges(PolySet::COLOR_CUTOUT); - glEnable(GL_LIGHTING); - } - } else { - m->root_chain->polysets[i]->render_surface(PolySet::COLOR_MATERIAL); - if (showEdges) { - glDisable(GL_LIGHTING); - m->root_chain->polysets[i]->render_edges(PolySet::COLOR_MATERIAL); - glEnable(GL_LIGHTING); - } +static void renderGLThrownTogetherChain(MainWindow *m, CSGChain *chain, bool highlight, bool background) +{ + glDepthFunc(GL_LEQUAL); + QHash polySetVisitMark; + bool showEdges = m->actViewModeShowEdges->isChecked(); + for (int i = 0; i < chain->polysets.size(); i++) { + if (polySetVisitMark[chain->polysets[i]]++ > 0) + continue; + if (highlight) { + chain->polysets[i]->render_surface(PolySet::COLOR_HIGHLIGHT); + if (showEdges) { + glDisable(GL_LIGHTING); + chain->polysets[i]->render_edges(PolySet::COLOR_HIGHLIGHT); + glEnable(GL_LIGHTING); + } + } else if (background) { + chain->polysets[i]->render_surface(PolySet::COLOR_BACKGROUND); + if (showEdges) { + glDisable(GL_LIGHTING); + chain->polysets[i]->render_edges(PolySet::COLOR_BACKGROUND); + glEnable(GL_LIGHTING); + } + } else if (chain->types[i] == CSGTerm::DIFFERENCE) { + chain->polysets[i]->render_surface(PolySet::COLOR_CUTOUT); + if (showEdges) { + glDisable(GL_LIGHTING); + chain->polysets[i]->render_edges(PolySet::COLOR_CUTOUT); + glEnable(GL_LIGHTING); + } + } else { + chain->polysets[i]->render_surface(PolySet::COLOR_MATERIAL); + if (showEdges) { + glDisable(GL_LIGHTING); + chain->polysets[i]->render_edges(PolySet::COLOR_MATERIAL); + glEnable(GL_LIGHTING); } } } } + +static void renderGLThrownTogether(void *vp) +{ + MainWindow *m = (MainWindow*)vp; + if (m->root_chain) + renderGLThrownTogetherChain(m, m->root_chain, false, false); + if (m->background_chain) + renderGLThrownTogetherChain(m, m->background_chain, false, true); + if (m->highlights_chain) + renderGLThrownTogetherChain(m, m->highlights_chain, true, false); +} + void MainWindow::viewModeThrownTogether() { viewModeActionsUncheck(); diff --git a/module.cc b/module.cc index a28dd39..f7e744d 100644 --- a/module.cc +++ b/module.cc @@ -239,8 +239,11 @@ CGAL_Nef_polyhedron AbstractNode::render_cgal_nef_polyhedron() const } CGAL_Nef_polyhedron N; - foreach (AbstractNode *v, children) + foreach (AbstractNode *v, children) { + if (v->modinst->tag_background) + continue; N += v->render_cgal_nef_polyhedron(); + } cgal_nef_cache.insert(cache_id, new CGAL_Nef_polyhedron(N), N.number_of_vertices()); progress_report(); diff --git a/polyset.cc b/polyset.cc index b00e80c..b6509e3 100644 --- a/polyset.cc +++ b/polyset.cc @@ -115,7 +115,7 @@ void PolySet::render_surface(colormode_e colormode, GLint *shaderinfo) const #endif /* ENABLE_OPENCSG */ } if (colormode == COLOR_HIGHLIGHT) { - glColor3ub(255, 157, 81); + glColor4ub(255, 157, 81, 128); #ifdef ENABLE_OPENCSG if (shaderinfo) { glUniform4f(shaderinfo[1], 255 / 255.0, 157 / 255.0, 81 / 255.0, 0.5); @@ -124,7 +124,7 @@ void PolySet::render_surface(colormode_e colormode, GLint *shaderinfo) const #endif /* ENABLE_OPENCSG */ } if (colormode == COLOR_BACKGROUND) { - glColor3ub(180, 180, 180); + glColor4ub(180, 180, 180, 128); #ifdef ENABLE_OPENCSG if (shaderinfo) { glUniform4f(shaderinfo[1], 180 / 255.0, 180 / 255.0, 180 / 255.0, 0.5); @@ -176,9 +176,9 @@ void PolySet::render_edges(colormode_e colormode) const if (colormode == COLOR_CUTOUT) glColor3ub(171, 216, 86); if (colormode == COLOR_HIGHLIGHT) - glColor3ub(255, 171, 86); + glColor4ub(255, 171, 86, 128); if (colormode == COLOR_BACKGROUND) - glColor3ub(150, 150, 150); + glColor4ub(150, 150, 150, 128); for (int i = 0; i < polygons.size(); i++) { const Polygon *poly = &polygons[i]; glBegin(GL_LINE_STRIP); diff --git a/render.cc b/render.cc index 69945fb..8463172 100644 --- a/render.cc +++ b/render.cc @@ -86,6 +86,8 @@ CGAL_Nef_polyhedron RenderNode::render_cgal_nef_polyhedron() const CGAL_Nef_polyhedron N; foreach(AbstractNode * v, children) { + if (v->modinst->tag_background) + continue; if (first) { N = v->render_cgal_nef_polyhedron(); first = false; diff --git a/transform.cc b/transform.cc index ac6017d..bb25d41 100644 --- a/transform.cc +++ b/transform.cc @@ -153,8 +153,12 @@ CGAL_Nef_polyhedron TransformNode::render_cgal_nef_polyhedron() const } CGAL_Nef_polyhedron N; - foreach (AbstractNode *v, children) + foreach (AbstractNode *v, children) { + if (v->modinst->tag_background) + continue; N += v->render_cgal_nef_polyhedron(); + } + CGAL_Aff_transformation t( m[0], m[4], m[ 8], m[12], m[1], m[5], m[ 9], m[13], -- cgit v0.10.1