Index: GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp	(revision 2667)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp	(revision 2669)
@@ -31,6 +31,6 @@
 #include <QVBoxLayout>
 
-namespace GtpVisibilityPreprocessor {
-
+namespace GtpVisibilityPreprocessor 
+{
 
   
@@ -41,6 +41,4 @@
 static CGprofile sCgFragmentProfile;
 
-
-//static vector<OcclusionQuery *> sQueries;
 
 QtGlRendererWidget *rendererWidget = NULL;
@@ -88,5 +86,10 @@
 									   ViewCellsManager *viewcells,
 									   KdTree *tree):
-QGLPixelBuffer(QSize(w, h), QGLFormat(QGL::StencilBuffer | QGL::DirectRendering | QGL::DepthBuffer | QGL::Rgba)),
+QGLPixelBuffer(QSize(w, h), 
+			   QGLFormat(QGL::StencilBuffer | 
+						 QGL::DepthBuffer | 
+						 QGL::DoubleBuffer |
+						 QGL::Rgba
+						 )),
 GlRendererBuffer(sceneGraph, viewcells, tree)
 {
@@ -125,8 +128,9 @@
 	MakeCurrent();
 	
-/*
-SetupCamera();
-RenderScene();
-*/
+	cout << "stencil: " << format().stencil() << endl;
+	cout << "depth: " << format().depth() << endl;
+	cout << "rgba: " << format().rgba() << endl;
+	cout << "double: " << format().doubleBuffer() << endl;
+
 	float pErrorPixels = -1.0f;
 
@@ -134,9 +138,12 @@
 	unsigned int pixelCount = 0;
 
-
+	
 	ViewCell *viewcell = mViewCellsManager->GetViewCell(mViewPoint);
 
 	if (viewcell == NULL)
 		return -1.0f;
+
+	KdNode::NewMail2();
+	Intersectable::NewMail();
 
 	ObjectPvs pvs;
@@ -150,38 +157,71 @@
 		mViewCellsManager->ApplyFilter2(viewcell, false, mViewCellsManager->GetFilterWidth(), pvs);
 
-
-	mUseForcedColors = true;
-
-	SetupCamera();
-
-	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
-	glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_FALSE);
-	glColor3f(0,1,0);
-	glDepthFunc(GL_LESS );
-	glEnable(GL_DEPTH_TEST);
-
-	glDisable(GL_STENCIL_TEST);
-
 	pvsSize = pvs.GetSize();
-
-	Intersectable::NewMail();
 	
 	if (pvsSize == 0)
 		return 0.0f;
 
-	RenderPvs(pvs);
-
-	//glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE);
+	mUseForcedColors = true;
+
+	SetupCamera();
+
+	// use shading
+	if (mSnapErrorFrames)
+	{
+
+		GLfloat light_ambient[] = {0.3, 0.3, 0.3, 1.0};
+		GLfloat light_diffuse[] = {0.6, 0.6, 0.6, 1.0};
+		GLfloat light_specular[] = {1.0, 1.0, 1.0, 1.0};
+
+		GLfloat light_position[] =  //{278.0f, 548.8f,279.0f, 1.0f};
+		{0.f,0.f,0.f, 1.0f};
+
+		glEnable(GL_LIGHT0); 
+
+		// a light
+		glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
+		glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
+		glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
+
+		glEnable(GL_LIGHTING);
+		glLightfv (GL_LIGHT0, GL_POSITION, light_position);
+
+		glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
+		glEnable(GL_COLOR_MATERIAL);
+
+		glShadeModel(GL_SMOOTH);
+	}
+
+	glDisable(GL_ALPHA_TEST);
+		
 	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
+
+	//glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_TRUE);
+	glColor3f(0, 1, 0);
+
+	glDepthFunc(GL_LESS);
+	glDepthMask(GL_TRUE);
+	glEnable(GL_DEPTH_TEST);
 
 	glStencilFunc(GL_EQUAL, 0x0, 0x1);
 	glStencilOp(GL_KEEP, GL_KEEP, GL_INCR); 
+
+	
+	// render pvs once
+	RenderPvs(pvs);
+
+	//glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE);
+	//glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);
+	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+
 	glEnable(GL_STENCIL_TEST); 
-
 	glColor3f(1,0,0);
 
 
-	OcclusionQuery *query = mOcclusionQueries[1];
-
+	// render scene, record differences
+	OcclusionQuery *query = mOcclusionQueries[0];
+
+	KdNode::NewMail2();
 	Intersectable::NewMail();
 
@@ -236,15 +276,25 @@
 				}
 		}
-
+		
+
+#if 0
 		mUseFalseColors = false;
+
 		glPushAttrib(GL_CURRENT_BIT);
-		glColor3f(0,1,0);
+		glColor3f(0, 1, 0);
+		
 		glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
 		//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
 
+		KdNode::NewMail2();
+		Intersectable::NewMail();
+
 		RenderPvs(pvs);
 
+		glFinish();
+
 		mUseForcedColors = false;
+
 		im = toImage();
 		sprintf(filename, "error-frame-%04d-%0.5f-pvs.png", mFrame, pErrorPixels);
@@ -252,5 +302,7 @@
 		qstr = str.c_str();
 		im.save(qstr, "PNG");
+		
 		glPopAttrib();
+#endif
 	}
 
@@ -449,4 +501,5 @@
 	int indexBufferSize = 0;
 	
+	// super hack: mal not working with multiple threads
 	KdNode::NewMail2();
 	//Intersectable::NewMail();
@@ -503,6 +556,5 @@
 
 	EnableDrawArrays();
-	//Intersectable::NewMail();
-	
+		
 	if (mDetectEmptyViewSpace) 
 		glEnable(GL_CULL_FACE);
