Done the rendering end of the red/green BFC view

Thu, 21 Mar 2013 00:37:15 +0200

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Thu, 21 Mar 2013 00:37:15 +0200
changeset 54
60f328f352c9
parent 53
170cdffe1056
child 55
b08f10e668e5

Done the rendering end of the red/green BFC view

cfgdef.h file | annotate | diff | comparison | revisions
gldraw.cpp file | annotate | diff | comparison | revisions
gldraw.h file | annotate | diff | comparison | revisions
icons/help.png file | annotate | diff | comparison | revisions
zz_configDialog.cpp file | annotate | diff | comparison | revisions
zz_configDialog.h file | annotate | diff | comparison | revisions
--- a/cfgdef.h	Wed Mar 20 23:46:37 2013 +0200
+++ b/cfgdef.h	Thu Mar 21 00:37:15 2013 +0200
@@ -26,7 +26,8 @@
 SECT (gl, GLRenderer)
 CFG (str, gl, bgcolor, "Background color", "#CCCCD9")
 CFG (str, gl, maincolor, "Main color", "#707078")
-CFG (int, gl, linethickness, "Line thickness", 1)
+CFG (int, gl, linethickness, "Line thickness", 2)
+CFG (bool, gl, colorbfc, "Green-red BFC view", true)
 
 SECT (lv, ListView)
 CFG (bool, lv, colorize, "Show colorized polygons in their color in the list view", true)
\ No newline at end of file
--- a/gldraw.cpp	Wed Mar 20 23:46:37 2013 +0200
+++ b/gldraw.cpp	Thu Mar 21 00:37:15 2013 +0200
@@ -86,7 +86,18 @@
 		1.0f);
 }
 
-void renderer::setObjectColor (LDObject* obj) {
+void renderer::setObjectColor (LDObject* obj, bool bBack) {
+	if (gl_colorbfc &&
+		obj->getType () != OBJ_Line &&
+		obj->getType () != OBJ_CondLine)
+	{
+		if (bBack)
+			glColor4f (0.9f, 0.0f, 0.0f, 1.0f);
+		else
+			glColor4f (0.0f, 0.8f, 0.0f, 1.0f);
+		return;
+	}
+	
 	if (obj->dColor == dMainColor)
 		setColor (gl_maincolor, glColor4f);
 	else {
@@ -146,7 +157,18 @@
 		glRotatef (fRotY, 0.0f, 1.0f, 0.0f);
 		glRotatef (fRotZ, 0.0f, 0.0f, 1.0f);
 		
-		glCallList (uObjList);
+		if (gl_colorbfc) {
+			glEnable (GL_CULL_FACE);
+			
+			glCullFace (GL_FRONT);
+			glCallList (uObjList);
+			
+			glCullFace (GL_BACK);
+			glCallList (uObjListBack);
+			
+			glDisable (GL_CULL_FACE);
+		} else
+			glCallList (uObjList);
 	glPopMatrix ();
 }
 
@@ -154,8 +176,6 @@
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
 void renderer::compileObjects () {
-	uObjList = glGenLists (1);
-	glNewList (uObjList, GL_COMPILE);
 	
 	g_faObjectOffset[0] = -(g_BBox.v0.x + g_BBox.v1.x) / 2;
 	g_faObjectOffset[1] = -(g_BBox.v0.y + g_BBox.v1.y) / 2;
@@ -166,23 +186,36 @@
 		return;
 	}
 	
-	for (ulong i = 0; i < g_CurrentFile->objects.size(); i++)
-		compileOneObject (g_CurrentFile->objects[i]);
+	GLuint* upaLists[2] = {
+		&uObjList,
+		&uObjListBack,
+	};
 	
-	glEndList ();
+	for (uchar j = 0; j < 2; ++j) {
+		if (j && !gl_colorbfc)
+			continue;
+		
+		*upaLists[j] = glGenLists (1);
+		glNewList (*upaLists[j], GL_COMPILE);
+		
+		for (ulong i = 0; i < g_CurrentFile->objects.size(); i++)
+			compileOneObject (g_CurrentFile->objects[i], j);
+		
+		glEndList ();
+	}
 }
 
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-void renderer::compileOneObject (LDObject* obj) {
+void renderer::compileOneObject (LDObject* obj, bool bBack) {
 	if (!obj)
 		return;
 	
 	switch (obj->getType ()) {
 	case OBJ_Line:
 		{
-			setObjectColor (obj);
+			setObjectColor (obj, bBack);
 			
 			// draw lines
 			LDLine* line = static_cast<LDLine*> (obj);
@@ -198,7 +231,7 @@
 			glLineStipple (1, 0x6666);
 			glEnable (GL_LINE_STIPPLE);
 			
-			setObjectColor (obj);
+			setObjectColor (obj, bBack);
 			LDCondLine* line = static_cast<LDCondLine*> (obj);
 			
 			glBegin (GL_LINES);
@@ -213,7 +246,7 @@
 	case OBJ_Triangle:
 		{
 			LDTriangle* tri = static_cast<LDTriangle*> (obj);
-			setObjectColor (obj);
+			setObjectColor (obj, bBack);
 			glBegin (GL_TRIANGLES);
 			for (short i = 0; i < 3; ++i)
 				GL_VERTEX (tri->vaCoords[i])
@@ -224,7 +257,7 @@
 	case OBJ_Quad:
 		{
 			LDQuad* quad = static_cast<LDQuad*> (obj);
-			setObjectColor (obj);
+			setObjectColor (obj, bBack);
 			glBegin (GL_QUADS);
 			for (short i = 0; i < 4; ++i)
 				GL_VERTEX (quad->vaCoords[i])
--- a/gldraw.h	Wed Mar 20 23:46:37 2013 +0200
+++ b/gldraw.h	Thu Mar 21 00:37:15 2013 +0200
@@ -44,10 +44,10 @@
 	void mouseMoveEvent (QMouseEvent *event);
 
 private:
-	GLuint uObjList;
-	void compileOneObject (LDObject* obj);
+	GLuint uObjList, uObjListBack;
+	void compileOneObject (LDObject* obj, bool bBack);
 	void clampAngle (double& fAngle);
-	void setObjectColor (LDObject* obj);
+	void setObjectColor (LDObject* obj, bool bBack);
 };
 
 #endif // __GLDRAW_H__
\ No newline at end of file
Binary file icons/help.png has changed
--- a/zz_configDialog.cpp	Wed Mar 20 23:46:37 2013 +0200
+++ b/zz_configDialog.cpp	Thu Mar 21 00:37:15 2013 +0200
@@ -25,6 +25,12 @@
 
 ConfigDialog* g_ConfigDialog = nullptr;
 
+#define INIT_CHECKBOX(BOX, CFG) \
+	BOX->setCheckState (CFG ? Qt::Checked : Qt::Unchecked);
+
+#define APPLY_CHECKBOX(BTN, CFG) \
+	CFG = BTN->checkState() == Qt::Checked;
+
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
@@ -61,7 +67,10 @@
 	qGLLineThickness->setTickInterval (1);
 	
 	qLVColorize = new QCheckBox ("Colorize polygons in list view");
-	qLVColorize->setCheckState (lv_colorize ? Qt::Checked : Qt::Unchecked);
+	INIT_CHECKBOX (qLVColorize, lv_colorize)
+	
+	qGLColorBFC = new QCheckBox ("Red/green BFC view");
+	INIT_CHECKBOX (qGLColorBFC, gl_colorbfc)
 	
 	IMPLEMENT_DIALOG_BUTTONS
 	
@@ -79,6 +88,7 @@
 	layout->addWidget (qGLLineThickness, 2, 1);
 	
 	layout->addWidget (qLVColorize, 3, 0, 1, 2);
+	layout->addWidget (qGLColorBFC, 3, 2, 1, 2);
 	
 	layout->addWidget (qButtons, 4, 2, 1, 2);
 	setLayout (layout);
@@ -148,7 +158,9 @@
 	
 	if (dlg.exec ()) {
 		io_ldpath = dlg.qLDrawPath->text();
-		lv_colorize = dlg.qLVColorize->checkState() == Qt::Checked;
+		
+		APPLY_CHECKBOX (dlg.qLVColorize, lv_colorize)
+		APPLY_CHECKBOX (dlg.qGLColorBFC, gl_colorbfc)
 		
 		gl_linethickness = dlg.qGLLineThickness->value ();
 		
--- a/zz_configDialog.h	Wed Mar 20 23:46:37 2013 +0200
+++ b/zz_configDialog.h	Thu Mar 21 00:37:15 2013 +0200
@@ -33,7 +33,7 @@
 	QLineEdit* qLDrawPath;
 	QPushButton* qLDrawPathFindButton;
 	QPushButton* qGLBackgroundButton, *qGLForegroundButton;
-	QCheckBox* qLVColorize;
+	QCheckBox* qLVColorize, *qGLColorBFC;
 	QSlider* qGLLineThickness;
 	
 	QDialogButtonBox* qButtons;

mercurial