diff options
| -rw-r--r-- | glview.cc | 44 | ||||
| -rw-r--r-- | mainwin.cc | 67 | ||||
| -rw-r--r-- | openscad.h | 7 | ||||
| -rw-r--r-- | polyset.cc | 9 | 
4 files changed, 49 insertions, 78 deletions
| @@ -41,8 +41,6 @@ GLView::GLView(QWidget *parent) : QGLWidget(parent)  	for (int i = 0; i < 10; i++)  		shaderinfo[i] = 0; -	useLights = false; -  	setMouseTracking(true);  } @@ -70,6 +68,7 @@ void GLView::initializeGL()  			"attribute vec3 pos_b, pos_c;\n"  			"attribute vec3 trig, mask;\n"  			"varying vec3 tp, tr;\n" +			"varying float shading;\n"  			"void main() {\n"  			"  vec4 p0 = gl_ModelViewProjectionMatrix * gl_Vertex;\n"  			"  vec4 p1 = gl_ModelViewProjectionMatrix * vec4(pos_b, 1.0);\n" @@ -83,13 +82,18 @@ void GLView::initializeGL()  			"  gl_Position = p0;\n"  			"  tp = mask * ha;\n"  			"  tr = trig;\n" +			"  vec3 normal, lightDir;\n" +			"  normal = normalize(gl_NormalMatrix * gl_Normal);\n" +			"  lightDir = normalize(vec3(gl_LightSource[0].position));\n" +			"  shading = abs(dot(normal, lightDir));\n"  			"}\n";  		const char *fs_source =  			"uniform vec4 color1, color2;\n"  			"varying vec3 tp, tr, tmp;\n" +			"varying float shading;\n"  			"void main() {\n" -			"  gl_FragColor = color1;\n" +			"  gl_FragColor = vec4(color1.r * shading, color1.g * shading, color1.b * shading, color1.a);\n"  			"  if (tp.x < tr.x || tp.y < tr.y || tp.z < tr.z)\n"  			"    gl_FragColor = color2;\n"  			"}\n"; @@ -170,25 +174,21 @@ void GLView::paintGL()  	glMatrixMode(GL_MODELVIEW);  	glLoadIdentity(); -	if (useLights) -	{ -		GLfloat light_diffuse[] = {1.0, 1.0, 1.0, 1.0}; -		GLfloat light_position0[] = {-1.0, -1.0, +1.0, 0.0}; -		GLfloat light_position1[] = {+1.0, +1.0, -1.0, 0.0}; - -		glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); -		glLightfv(GL_LIGHT0, GL_POSITION, light_position0); -		glEnable(GL_LIGHT0); -		glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse); -		glLightfv(GL_LIGHT1, GL_POSITION, light_position1); -		glEnable(GL_LIGHT1); -		glEnable(GL_LIGHTING); -		glEnable(GL_NORMALIZE); -	} -	else -	{ -		glDisable(GL_LIGHTING); -	} +	GLfloat light_diffuse[] = {1.0, 1.0, 1.0, 1.0}; +	GLfloat light_position0[] = {-1.0, -1.0, +1.0, 0.0}; +	GLfloat light_position1[] = {+1.0, +1.0, -1.0, 0.0}; + +	glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); +	glLightfv(GL_LIGHT0, GL_POSITION, light_position0); +	glEnable(GL_LIGHT0); +	glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse); +	glLightfv(GL_LIGHT1, GL_POSITION, light_position1); +	glEnable(GL_LIGHT1); +	glEnable(GL_LIGHTING); +	glEnable(GL_NORMALIZE); + +	glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); +	glEnable(GL_COLOR_MATERIAL);  	glRotated(object_rot_y, 1.0, 0.0, 0.0);  	glRotated(object_rot_z, 0.0, 0.0, 1.0); @@ -114,13 +114,9 @@ MainWindow::MainWindow(const char *filename)  #endif  		actViewModeThrownTogether = menu->addAction("Thrown Together", this, SLOT(viewModeThrownTogether()));  		actViewModeThrownTogether->setCheckable(true); -  		menu->addSeparator(); - -		actViewModeWireframe = menu->addAction("Wireframe", this, SLOT(viewModeWireframe())); -		actViewModeWireframe->setCheckable(true); -		actViewModeShaded = menu->addAction("Shaded", this, SLOT(viewModeShaded())); -		actViewModeShaded->setCheckable(true); +		actViewModeShowEdges = menu->addAction("Show Edges", this, SLOT(viewModeShowEdges())); +		actViewModeShowEdges->setCheckable(true);  		menu->addSeparator();  		menu->addAction("Top"); @@ -162,7 +158,6 @@ MainWindow::MainWindow(const char *filename)  #else  	viewModeThrownTogether();  #endif -	viewModeShaded();  	setCentralWidget(s1);  	current_win = NULL; @@ -705,9 +700,11 @@ static void renderGLviaOpenCSG(void *vp)  		GLint *shaderinfo = m->screen->shaderinfo;  		if (!shaderinfo[0])  			shaderinfo = NULL; -		renderCSGChainviaOpenCSG(m->root_chain, m->screen->useLights ? NULL : shaderinfo, false); -		if (m->highlights_chain) +		renderCSGChainviaOpenCSG(m->root_chain, m->actViewModeShowEdges->isChecked() ? shaderinfo : NULL, false); +		if (m->highlights_chain) { +			glDisable(GL_LIGHTING);  			renderCSGChainviaOpenCSG(m->highlights_chain, shaderinfo, true); +		}  	}  } @@ -750,17 +747,20 @@ static void renderGLviaCGAL(void *vp)  			P.set_style(CGAL::OGL::SNC_BOUNDARY);  		if (m->actViewModeCGALGrid->isChecked())  			P.set_style(CGAL::OGL::SNC_SKELETON); -		glDisable(GL_LIGHTING);  #if 0  		P.draw();  #else  		if (P.style == CGAL::OGL::SNC_BOUNDARY) { -		  glCallList(P.object_list_+2); -		} -		glCallList(P.object_list_+1); -		glCallList(P.object_list_); -		if (P.switches[CGAL::OGL::SNC_AXES]) { -			glCallList(P.object_list_+3); +			glCallList(P.object_list_+2); +			if (m->actViewModeShowEdges->isChecked()) { +				glDisable(GL_LIGHTING); +				glCallList(P.object_list_+1); +				glCallList(P.object_list_); +			} +		} else { +			glDisable(GL_LIGHTING); +			glCallList(P.object_list_+1); +			glCallList(P.object_list_);  		}  #endif  	} @@ -791,29 +791,23 @@ static void renderGLThrownTogether(void *vp)  	MainWindow *m = (MainWindow*)vp;  	if (m->root_chain) {  		glDepthFunc(GL_LEQUAL); -#if 0 -		glUseProgram(m->screen->shaderinfo[0]);  		for (int i = 0; i < m->root_chain->polysets.size(); i++) {  			if (m->root_chain->types[i] == CSGTerm::DIFFERENCE) { -				m->root_chain->polysets[i]->render_surface(PolySet::COLOR_CUTOUT, m->screen->shaderinfo); +				m->root_chain->polysets[i]->render_surface(PolySet::COLOR_CUTOUT);  			} else { -				m->root_chain->polysets[i]->render_surface(PolySet::COLOR_MATERIAL, m->screen->shaderinfo); +				m->root_chain->polysets[i]->render_surface(PolySet::COLOR_MATERIAL);  			}  		} -		glUseProgram(0); -#else -		for (int i = 0; i < m->root_chain->polysets.size(); i++) { -			if (m->root_chain->types[i] == CSGTerm::DIFFERENCE) { -				m->root_chain->polysets[i]->render_surface(PolySet::COLOR_CUTOUT); -				if (!m->screen->useLights) +		if (m->actViewModeShowEdges->isChecked()) { +			glDisable(GL_LIGHTING); +			for (int i = 0; i < m->root_chain->polysets.size(); i++) { +				if (m->root_chain->types[i] == CSGTerm::DIFFERENCE) {  					m->root_chain->polysets[i]->render_edges(PolySet::COLOR_CUTOUT); -			} else { -				m->root_chain->polysets[i]->render_surface(PolySet::COLOR_MATERIAL); -				if (!m->screen->useLights) +				} else {  					m->root_chain->polysets[i]->render_edges(PolySet::COLOR_MATERIAL); +				}  			}  		} -#endif  	}  } @@ -826,19 +820,8 @@ void MainWindow::viewModeThrownTogether()  	screen->updateGL();  } -void MainWindow::viewModeWireframe() -{ -	screen->useLights = false; -	actViewModeWireframe->setChecked(true); -	actViewModeShaded->setChecked(false); -	screen->updateGL(); -} - -void MainWindow::viewModeShaded() +void MainWindow::viewModeShowEdges()  { -	screen->useLights = true; -	actViewModeWireframe->setChecked(false); -	actViewModeShaded->setChecked(true);  	screen->updateGL();  } @@ -458,7 +458,6 @@ public:  	double w_h_ratio;  	GLint shaderinfo[11]; -	bool useLights;  	GLView(QWidget *parent = NULL); @@ -544,8 +543,7 @@ public:  	QAction *actViewModeCGALGrid;  #endif  	QAction *actViewModeThrownTogether; -	QAction *actViewModeWireframe; -	QAction *actViewModeShaded; +	QAction *actViewModeShowEdges;  	void viewModeActionsUncheck();  private slots: @@ -557,8 +555,7 @@ private slots:  	void viewModeCGALGrid();  #endif  	void viewModeThrownTogether(); -	void viewModeWireframe(); -	void viewModeShaded(); +	void viewModeShowEdges();  };  extern AbstractModule *parse(const char *text, int debug); @@ -95,9 +95,6 @@ void PolySet::render_surface(colormode_e colormode, GLint *shaderinfo) const  	glMultMatrixd(m);  	if (colormode == COLOR_MATERIAL) {  		glColor3ub(249, 215, 44); -		GLfloat light_diffuse[] = {255 / 255.0, 236 / 255.0, 94 / 255.0, 1.0}; -		glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); -		glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);  #ifdef ENABLE_OPENCSG  		if (shaderinfo) {  			glUniform4f(shaderinfo[1], 249 / 255.0, 215 / 255.0, 44 / 255.0, 1.0); @@ -107,9 +104,6 @@ void PolySet::render_surface(colormode_e colormode, GLint *shaderinfo) const  	}  	if (colormode == COLOR_CUTOUT) {  		glColor3ub(157, 203, 81); -		GLfloat light_diffuse[] = {171 / 255.0, 216 / 255.0, 86 / 255.0, 1.0}; -		glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); -		glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);  #ifdef ENABLE_OPENCSG  		if (shaderinfo) {  			glUniform4f(shaderinfo[1], 157 / 255.0, 203 / 255.0, 81 / 255.0, 1.0); @@ -119,9 +113,6 @@ void PolySet::render_surface(colormode_e colormode, GLint *shaderinfo) const  	}  	if (colormode == COLOR_HIGHLIGHT) {  		glColor3ub(255, 157, 81); -		GLfloat light_diffuse[] = {255 / 255.0, 171 / 255.0, 86 / 255.0, 0.5}; -		glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); -		glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);  #ifdef ENABLE_OPENCSG  		if (shaderinfo) {  			glUniform4f(shaderinfo[1], 255 / 255.0, 157 / 255.0, 81 / 255.0, 0.5); | 
