Ejemplo n.º 1
0
void DrawGeometry(bool shadowPass)
{
	CMatrix44 rot;
	rot.Rotate(45,1,0,0);

	transform.Push();
	if(shadowPass == false)
		shadow_transform.Push();

	transforms.mvp = transforms.proj * transform.GetCurrentMatrix();
	WRender::UpdateBuffer(WRender::UNIFORM, WRender::DYNAMIC, ubo, sizeof(Transforms), (void*)&transforms, 0);				
	if(shadowPass == false)
		program.SetMtx44(uShadowMtx, shadow_transform.GetCurrentMatrix().data);
	//Plane
	WRender::BindVertexArrayObject(vaoPlane);
	WRender::DrawArray(WRender::TRIANGLES, 4*3, 0);

	transform.Pop();
	if(shadowPass == false)
		shadow_transform.Pop();
	
	transform.Push();
	if(shadowPass == false)
		shadow_transform.Push();
	
	transform.ApplyTransform(rot);
	transform.Translate(0, 5.0f, 0);
	if(shadowPass == false)
	{
		shadow_transform.ApplyTransform(rot);
		shadow_transform.Translate(0, 5.0f, 0);
	}
	transforms.mvp = transforms.proj * transform.GetCurrentMatrix();
	WRender::UpdateBuffer(WRender::UNIFORM, WRender::DYNAMIC, ubo, sizeof(Transforms), (void*)&transforms, 0);				
	if(shadowPass == false)
		program.SetMtx44(uShadowMtx, shadow_transform.GetCurrentMatrix().data);
	//Torus
	WRender::BindVertexArrayObject(vaoTorus);
	WRender::DrawArray(WRender::TRIANGLES, nTorusVertices, 0);

	transform.Pop();
	if(shadowPass == false)
		shadow_transform.Pop();
}
Ejemplo n.º 2
0
void MainLoop(CPlatform * const  pPlatform)
{	
	//update the main application
	pPlatform->Tick();	
	WRender::ClearScreenBuffer(COLOR_BIT | DEPTH_BIT); //not really needed 		
	WRender::EnableDepthTest(true);
	transform.Push();			
	{
		CMatrix44 rotLat,rotLong;
		rotLat.Rotate(latitude, 1, 0, 0);
		rotLong.Rotate(longitude, 0, 1, 0);

		transform.Translate(cameraPosition);
		transform.ApplyTransform(rotLat);
		transform.ApplyTransform(rotLong);			

		transform.Push();					
		{
			transforms.mvp = transforms.proj * transform.GetCurrentMatrix();
			//program.SetMtx44(uMVP, transforms.mvp.data);
			WRender::UpdateBuffer(WRender::UNIFORM, WRender::DYNAMIC, ubo, sizeof(Transforms), (void*)&transforms, 0);				
				
			program[0].Start();
			WRender::Draw(WRender::LINES, WRender::U_BYTE, sizeof(indices)/sizeof(unsigned char), 0);
			WRender::Draw(WRender::POINTS, WRender::U_BYTE, 1, 5);

			program[1].Start();				
			WRender::Draw(WRender::LINES, WRender::U_BYTE, sizeof(indices)/sizeof(unsigned char), 0);
			WRender::Draw(WRender::POINTS, WRender::U_BYTE, 1, 5);
		}
		transform.Pop();
	}
	transform.Pop();		
	pPlatform->UpdateBuffers();
	if(pPlatform->GetKeyboard().keys[KB_UP].IsPressed())
		latitude += 90.0f * pPlatform->GetDT();
	if(pPlatform->GetKeyboard().keys[KB_DOWN].IsPressed())
		latitude -= 90.0f * pPlatform->GetDT();
		
	if(pPlatform->GetKeyboard().keys[KB_LEFT].IsPressed())
		longitude += 90.0f * pPlatform->GetDT();
	if(pPlatform->GetKeyboard().keys[KB_RIGHT].IsPressed())
		longitude -= 90.0f * pPlatform->GetDT();
}
Ejemplo n.º 3
0
void MainLoop(CPlatform * const  pPlatform)
{
	float tranD[3] = {0.0f, -1.0f, 0};				
	//update the main application
	pPlatform->Tick();	
	WRender::ClearScreenBuffer(COLOR_BIT | DEPTH_BIT);
	WRender::EnableDepthTest(true);		
	program.Start();

	//Draw from light perspective
	//glPolygonOffset( 2.5f, 25.0f );
	//glEnable( GL_POLYGON_OFFSET_FILL);
	transform.Push();			
	{
		WRender::SetupViewport(0, 0, TEX_DIMENSIONS, TEX_DIMENSIONS);	//adjust viewport
		WRender::BindFrameBuffer(WRender::FrameBuffer::DRAW, fbo);		//set fbo 
		WRender::ClearScreenBuffer(COLOR_BIT | DEPTH_BIT);				//clear draw buffers (must be called after we set the fbo)

		rotLat.Identity();	rotLat.Rotate(lightLatitude, 1, 0, 0);
		rotLong.Identity();	rotLong.Rotate(lightLongitude, 0, 1, 0);

		transform.Translate(cameraPosition);			
		transform.ApplyTransform(rotLat);
		transform.ApplyTransform(rotLong);

		//setup shadow mvp
			
		shadow_transform.Identity();
		shadow_transform.Translate(0.5f, 0.5f, 0.5f);
		shadow_transform.Scale(0.5f,0.5f,0.5f);
		shadow_transform.ApplyTransform(transforms.proj);
		shadow_transform.ApplyTransform(transform.GetCurrentMatrix());
		DrawGeometry(true);

		WRender::UnbindFrameBuffer(WRender::FrameBuffer::DRAW); //reset draw buffer
		WRender::SetupViewport(0, 0, 640, 640);	//reset viewport			
	}
	//glDisable( GL_POLYGON_OFFSET_FILL);
	transform.Pop();		

	//draw scene
	transform.Push();			
	{
		rotLat.Identity();	rotLat.Rotate(latitude, 1, 0, 0);
		rotLong.Identity();	rotLong.Rotate(longitude, 0, 1, 0);

		transform.Translate(cameraPosition);
		transform.ApplyTransform(rotLat);
		transform.ApplyTransform(rotLong);
		DrawGeometry(false);			
	}
	transform.Pop();		

	//render depth texture to screen
	textureShader.Start();
	WRender::BindVertexArrayObject(sqVao);					
	textureShader.SetVec3("translate",tranD);		
	WRender::Draw(WRender::TRIANGLE_STRIP, WRender::U_BYTE, sizeof(sqIndices)/sizeof(unsigned char), 0);		
		
	//update Keyboard
	pPlatform->UpdateBuffers();
	if(!pPlatform->GetKeyboard().keys[KB_LEFTSHIFT].IsPressed())
	{	pLat = &latitude; pLong = &longitude;}
	else
	{	pLat = &lightLatitude; pLong = &lightLongitude;}

	if(pPlatform->GetKeyboard().keys[KB_UP].IsPressed())
		*pLat += 90.0f * pPlatform->GetDT();
	if(pPlatform->GetKeyboard().keys[KB_DOWN].IsPressed())
		*pLat -= 90.0f * pPlatform->GetDT();
	if(pPlatform->GetKeyboard().keys[KB_LEFT].IsPressed())//l
		*pLong += 90.0f * pPlatform->GetDT();
	if(pPlatform->GetKeyboard().keys[KB_RIGHT].IsPressed())//r
		*pLong -= 90.0f * pPlatform->GetDT();		

}
Ejemplo n.º 4
0
void MainLoop(CPlatform * const  pPlatform)
{	//update the main application
	CVec3df cameraPosition( 0.0f, 0.0f, distance );

	pPlatform->Tick();	
	WRender::ClearScreenBuffer(COLOR_BIT | DEPTH_BIT);
	WRender::EnableDepthTest(true);

	WRender::ActiveTexture(WRender::Texture::UNIT_0);
	WRender::BindTexture(cubemap_tex);

	transform.Push();			
	{
		CMatrix44 rotLat,rotLong,inverse_camera, model_matrix;

		rotLat.Rotate(latitude, 1, 0, 0);
		rotLong.Rotate(longitude, 0, 1, 0);

		transform.Translate(cameraPosition);
		transform.ApplyTransform(rotLat);
		transform.ApplyTransform(rotLong);			
		
		transform.Push();					
		{
			transform.Scale(10.0f,10.0f,10.0f);
			transforms.mv = transform.GetCurrentMatrix();
			transforms.mvp = transforms.proj * transforms.mv;
			CMatrix33 normal;

			normal = transforms.mv;
			normal = normal.Invert();
			normal = normal.Transpose();			
			transforms.nrm[ 0] = normal.x.x;			transforms.nrm[ 1] = normal.x.y;			transforms.nrm[ 2] = normal.x.z;
			transforms.nrm[ 4] = normal.y.x;			transforms.nrm[ 5] = normal.y.y;			transforms.nrm[ 6] = normal.y.z;
			transforms.nrm[ 8] = normal.z.x;			transforms.nrm[ 9] = normal.z.y;			transforms.nrm[10] = normal.z.z;

			WRender::UpdateBuffer(WRender::UNIFORM, WRender::DYNAMIC, ubo, sizeof(Transforms), (void*)&transforms, 0);				
			WRender::EnableCulling(true);
			WRender::CullMode(WRender::FRONT_FACE);
			program_cube.Start();			
			DrawShape(box);
		}
		transform.Pop();


		transform.Push();					
		{
			transform.Translate(0.0f, 0, 0);
			transforms.mv = transform.GetCurrentMatrix();
			transforms.mvp = transforms.proj * transforms.mv;
			CMatrix33 normal;

			normal = transforms.mv;
			normal = normal.Invert();
			normal = normal.Transpose();			
			transforms.nrm[ 0] = normal.x.x;			transforms.nrm[ 1] = normal.x.y;			transforms.nrm[ 2] = normal.x.z;
			transforms.nrm[ 4] = normal.y.x;			transforms.nrm[ 5] = normal.y.y;			transforms.nrm[ 6] = normal.y.z;
			transforms.nrm[ 8] = normal.z.x;			transforms.nrm[ 9] = normal.z.y;			transforms.nrm[10] = normal.z.z;

			WRender::UpdateBuffer(WRender::UNIFORM, WRender::DYNAMIC, ubo, sizeof(Transforms), (void*)&transforms, 0);				
			WRender::EnableCulling(true);			
			WRender::CullMode(WRender::BACK_FACE);
			program_cube.Start();
			DrawShape(sphere);
		}
		transform.Pop();		
		
	}
	transform.Pop();		

	pPlatform->UpdateBuffers();
	if (pPlatform->GetKeyboard().keys[KB_LEFTSHIFT].IsPressed()){
		if(pPlatform->GetKeyboard().keys[KB_UP].IsPressed())
			distance += 1.0f * pPlatform->GetDT();
		if(pPlatform->GetKeyboard().keys[KB_DOWN].IsPressed())
			distance -= 1.0f * pPlatform->GetDT();
	}else{
		if(pPlatform->GetKeyboard().keys[KB_UP].IsPressed())
			latitude += 90.0f * pPlatform->GetDT();
		if(pPlatform->GetKeyboard().keys[KB_DOWN].IsPressed())
			latitude -= 90.0f * pPlatform->GetDT();
		
		if(pPlatform->GetKeyboard().keys[KB_LEFT].IsPressed())//l
			longitude += 90.0f * pPlatform->GetDT();
		if(pPlatform->GetKeyboard().keys[KB_RIGHT].IsPressed())//r
			longitude -= 90.0f * pPlatform->GetDT();
	}
}
Ejemplo n.º 5
0
void MainLoop(CPlatform * const  pPlatform)
{	//update the main application
	CVec3df cameraPosition(0, 0.0f, -2.1f);
	pPlatform->Tick();	

	if(pPlatform->GetKeyboard().keys[KB_B].IsToggledPress())
	{
		brightness += 0.1f;
		if(brightness > 1.0)
			brightness = -1.0f;
		printf("brightness : %f", brightness);
	}
	if(pPlatform->GetKeyboard().keys[KB_G].IsToggledPress())
	{
		gamma += 0.2f;
		if(gamma > 4.0)
			gamma = 0.2f;
		printf("gamma : %f", gamma);
	}
	if(pPlatform->GetKeyboard().keys[KB_C].IsToggledPress())
	{
		contrast += 0.1f;
		if(contrast > 2.0)
			contrast = -1.0f;
		printf("contrast : %f", contrast);
	}
	

	//first pass to texture
	program[0].Start();
	WRender::SetClearColour(0.0,0,0,0);
	WRender::BindFrameBuffer(WRender::FrameBuffer::DRAW, fbo);
	WRender::SetupViewport(0, 0, WIDTH_HEIGHT, WIDTH_HEIGHT);
	WRender::ClearScreenBuffer(COLOR_BIT | DEPTH_BIT);
	WRender::EnableDepthTest(true);
	transform.Push();			
	{
		CMatrix44 rotLat,rotLong;
		rotLat.Rotate(latitude, 1, 0, 0);
		rotLong.Rotate(longitude, 0, 1, 0);

		transform.Translate(cameraPosition);
		transform.ApplyTransform(rotLat);
		transform.ApplyTransform(rotLong);			
			
		transform.Push();					
		{
			transforms.mvp = transforms.proj * transform.GetCurrentMatrix();
			WRender::UpdateBuffer(WRender::UNIFORM, WRender::DYNAMIC, ubo, sizeof(Transforms), (void*)&transforms, 0);				
			//Sphere
			WRender::BindVertexArrayObject(vaoSphere);
			WRender::DrawArray(WRender::TRIANGLES, nSphereVertices, 0);
		}
		transform.Pop();
	}
	transform.Pop();		
	WRender::UnbindFrameBuffer(WRender::FrameBuffer::DRAW);
	WRender::SetDrawBuffer(WRender::DB_BACK);

	//second pass
	//texture to screen
	WRender::SetClearColour(1.0,0,0,0);
	WRender::SetupViewport(0, 0, 640, 640);
	WRender::ClearScreenBuffer(COLOR_BIT | DEPTH_BIT);
	WRender::BindVertexArrayObject(sqVao);		
	program[1].Start();
	if(pPlatform->GetKeyboard().keys[KB_SPACE].IsPressed())
	{
		program[1].SetFloat("brightness", 0.0f);
		program[1].SetFloat("inverse_gamma", 1.0f);
		program[1].SetFloat("contrast",	1.0f);
	}
	else
	{
		program[1].SetFloat("brightness",brightness);
		program[1].SetFloat("inverse_gamma",1.0f/gamma);
		program[1].SetFloat("contrast",contrast);
	}
	//float tranR[3] = {0.0f, -1.0f, 0};	
	WRender::BindTexture(texR,WRender::Texture::UNIT_0);
	//program[1].SetVec3("translate",tranR);		
	WRender::Draw(WRender::TRIANGLE_STRIP, WRender::U_BYTE, sizeof(sqIndices)/sizeof(unsigned char), 0);

	pPlatform->UpdateBuffers();
	if(pPlatform->GetKeyboard().keys[KB_UP].IsPressed())
		latitude += 90.0f * pPlatform->GetDT();
	if(pPlatform->GetKeyboard().keys[KB_DOWN].IsPressed())
		latitude -= 90.0f * pPlatform->GetDT();
		
	if(pPlatform->GetKeyboard().keys[KB_LEFT].IsPressed())//l
		longitude += 90.0f * pPlatform->GetDT();
	if(pPlatform->GetKeyboard().keys[KB_RIGHT].IsPressed())//r
		longitude -= 90.0f * pPlatform->GetDT();
}
Ejemplo n.º 6
0
void DrawGeometry(bool shadowPass)
{
	CMatrix44 rot;
	rot.Rotate(45,1,0,0);
#ifdef ANIM_TORUS
	static float angle = 0;
	CMatrix44 anim;
	anim.Rotate(angle,0,1,0);
	angle += 0.1f;
#endif

	transform.Push();
	if(shadowPass == false)
		for(unsigned int i=0;i<NUM_SHADOWS; i++)
			shadow_transform[i].Push();

	transforms.mvp = transforms.proj * transform.GetCurrentMatrix();
	WRender::UpdateBuffer(WRender::UNIFORM, WRender::DYNAMIC, ubo, sizeof(Transforms), (void*)&transforms, 0);				
	if(shadowPass == false)
	{
		for(unsigned int i=0;i<NUM_SHADOWS; i++)
			shadowMtx[i] = shadow_transform[i].GetCurrentMatrix();
		WRender::UpdateBuffer(WRender::UNIFORM, WRender::DYNAMIC, shadowUBO, sizeof(CMatrix44)*NUM_SHADOWS, (void*)shadowMtx, 0);
		//WRender::UpdateBuffer(WRender::UNIFORM, WRender::DYNAMIC, shadowUBO, sizeof(CMatrix44)*NUM_SHADOWS, (void*)shadowMtx, sizeof(CMatrix44));
	}
	//Plane
	WRender::BindVertexArrayObject(vaoPlane);
	WRender::DrawArray(WRender::TRIANGLES, 4*3, 0);

	transform.Pop();
	if(shadowPass == false)
		for(unsigned int i=0;i<NUM_SHADOWS; i++)
			shadow_transform[i].Pop();
	
	transform.Push();
	if(shadowPass == false)
		for(unsigned int i=0;i<NUM_SHADOWS; i++)
			shadow_transform[i].Push();
	
	#ifdef ANIM_TORUS
	transform.ApplyTransform(anim);
	#endif
	transform.Translate(0, 3.0f, 5.0f);
	transform.ApplyTransform(rot);	

	if(shadowPass == false)
	{
		for(unsigned int i=0;i<NUM_SHADOWS; i++)
		{
			#ifdef ANIM_TORUS
			shadow_transform[i].ApplyTransform(anim);
			#endif
			shadow_transform[i].Translate(0, 3.0f, 5.0f);
			shadow_transform[i].ApplyTransform(rot);			
		}
	}
	transforms.mvp = transforms.proj * transform.GetCurrentMatrix();
	WRender::UpdateBuffer(WRender::UNIFORM, WRender::DYNAMIC, ubo, sizeof(Transforms), (void*)&transforms, 0);				
	if(shadowPass == false)
	{
		for(unsigned int i=0;i<NUM_SHADOWS; i++)
			shadowMtx[i] = shadow_transform[i].GetCurrentMatrix();
		WRender::UpdateBuffer(WRender::UNIFORM, WRender::DYNAMIC, shadowUBO, sizeof(CMatrix44)*NUM_SHADOWS, (void*)shadowMtx, sizeof(CMatrix44));
	}
	//Torus
	WRender::BindVertexArrayObject(vaoTorus);
	WRender::DrawArray(WRender::TRIANGLES, nTorusVertices, 0);

	transform.Pop();
	if(shadowPass == false)
	{
		for(unsigned int i=0;i<NUM_SHADOWS; i++)
			shadow_transform[i].Pop();
	}
}