Source

gltut / Tut 05 Objects in Depth / DepthFighting.cpp

Diff from to

Tut 05 Objects in Depth/DepthFighting.cpp

+
+
 
 #include <string>
 #include <vector>
 const float vertexData[] = {
 	//Front face positions
 	-400.0f,		 400.0f,			0.0f,
-	 400.0f,		 400.0f,			0.0f,
-	 400.0f,		-400.0f,			0.0f,
+	400.0f,		 400.0f,			0.0f,
+	400.0f,		-400.0f,			0.0f,
 	-400.0f,		-400.0f,			0.0f,
 
 	//Rear face positions
 	-200.0f,		 600.0f,			-Z_OFFSET,
-	 600.0f,		 600.0f,			0.0f - Z_OFFSET,
-	 600.0f,		-200.0f,			0.0f - Z_OFFSET,
+	600.0f,		 600.0f,			0.0f - Z_OFFSET,
+	600.0f,		-200.0f,			0.0f - Z_OFFSET,
 	-200.0f,		-200.0f,			-Z_OFFSET,
 
 	//Front face colors.
 
 float CalcZOFfset()
 {
-	const float fLoopDuration = 50.0f;
+	const float fLoopDuration = 5.0f;
 	const float fScale = 3.14159f * 2.0f / fLoopDuration;
 
 	float fElapsedTime = glutGet(GLUT_ELAPSED_TIME) / 1000.0f;
 
 	float fCurrTimeThroughLoop = fmodf(fElapsedTime, fLoopDuration);
 
-	float fRet = cosf(fCurrTimeThroughLoop * fScale) * 100.0f - 2700.0f;
+	float fRet = cosf(fCurrTimeThroughLoop * fScale) * 500.0f - 2700.0f;
 	fRet = fDelta - 2700.0f;
 
 	return fRet;
 }
 
-volatile bool bReadDepthBuffer = false;
-
-
 //Called to update the display.
 //You should call glutSwapBuffers after all of your rendering to display what you rendered.
 //If you need continuous updates of the screen, call glutPostRedisplay() at the end of the function.
 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
 	glUseProgram(theProgram);
-
 	glBindVertexArray(vao);
 
-	float fOffset = CalcZOFfset();
-
-	glUniform3f(offsetUniform, 0.0f, 0.0f, fOffset);
+	glUniform3f(offsetUniform, 0.0f, 0.0f, CalcZOFfset());
 	glDrawElements(GL_TRIANGLES, ARRAY_COUNT(indexData), GL_UNSIGNED_SHORT, 0);
 
 	glBindVertexArray(0);
 	glUseProgram(0);
 
-	if(bReadDepthBuffer)
-	{
-		bReadDepthBuffer = false;
-
-		GLuint depthBuffer[500*500];
-		memset(depthBuffer, 0, sizeof(depthBuffer));
-
-		glReadPixels(0, 0, 500, 500, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, depthBuffer);
-
-		//Print the depth buffer to a file.
-		static int iFoo = 0;
-		iFoo++;
-	}
-
 	glutSwapBuffers();
 	glutPostRedisplay();
 }
 	glViewport(0, 0, (GLsizei) w, (GLsizei) h);
 }
 
+
 //Called whenever a key on the keyboard was pressed.
 //The key is given by the ''key'' parameter, which is in ASCII.
 //It's often a good idea to have the escape key (ASCII value 27) call glutLeaveMainLoop() to 
 		{
 			float fValue = CalcZOFfset();
 			printf("%f\n", fValue);
-			bReadDepthBuffer = true;
+//			bReadDepthBuffer = true;
 		}
 		break;
 		//Hundreds
 	printf("%f\n", fDelta);
 }
 
-