void Tutorial9_Animation::RenderFBXSceneResource(FBXFile *a_pScene, glm::mat4 a_view, glm::mat4 a_projection)
{
	// activate a shader
	glUseProgram(m_shader);

	// update the bones to include the bind pose
	// so that the offset is local
	FBXSkeleton* skeleton = m_fbx->getSkeletonByIndex(0);
	skeleton->updateBones();

	// get the location of uniforms on the shader
	GLint uDiffuseTexture = glGetUniformLocation(m_shader, "DiffuseTexture");
	GLint uDiffuseColor = glGetUniformLocation(m_shader, "DiffuseColor");

	GLint uProjectionView = glGetUniformLocation(m_shader, "projectionView");
	GLint uGlobal = glGetUniformLocation(m_shader, "global");
	GLint uLocation = glGetUniformLocation(m_shader, "bones");

	// for each mesh in the model...
	for (int i = 0; i<a_pScene->getMeshCount(); ++i)
	{
		// get the current mesh
		FBXMeshNode *mesh = a_pScene->getMeshByIndex(i);

		// get the render data attached to the m_userData pointer for this mesh
		OGL_FBXRenderData *ro = (OGL_FBXRenderData *)mesh->m_userData;

		// Bind the texture to one of the ActiveTextures
		// if your shader supported multiple textures, you would bind each texture to a new Active Texture ID here
		glActiveTexture(GL_TEXTURE1);
		glBindTexture(GL_TEXTURE_2D, mesh->m_material->textures[FBXMaterial::DiffuseTexture]->handle);


		// reset back to the default active texture
		glActiveTexture(GL_TEXTURE0);

		// tell the shader which texture to use
		glUniform1i(uDiffuseTexture, 1);

		m_projectionView = a_projection * a_view;

		// send the Model, View and Projection Matrices to the shader
		glUniformMatrix4fv(uProjectionView, 1, false, glm::value_ptr(m_projectionView));
		glUniformMatrix4fv(uGlobal, 1, false, glm::value_ptr(mesh->m_globalTransform));
		glUniformMatrix4fv(uLocation, skeleton->m_boneCount, GL_FALSE, (float*)skeleton->m_bones);

		// bind our vertex array object
		// remember in the initialise function, we bound the VAO and IBO to the VAO
		// so when we bind the VAO, openGL knows what what vertices,
		// indices and vertex attributes to send to the shader
		glBindVertexArray(ro->VAO);
		glDrawElements(GL_TRIANGLES, mesh->m_indices.size(), GL_UNSIGNED_INT, 0);

	}

	// finally, we have finished rendering the meshes
	// disable this shader
	glUseProgram(0);
}
Exemplo n.º 2
0
void FBXObject::Draw(glm::vec3 _lightDir, glm::vec3 _lightColour)
{
	glUseProgram(m_programID);

	unsigned int uiProjViewLocation = glGetUniformLocation(m_programID, "ProjectionView");
	glUniformMatrix4fv(uiProjViewLocation, 1, GL_FALSE, glm::value_ptr(m_camera->GetProjectionView()));

 	FBXSkeleton* skeleton = m_fbx->getSkeletonByIndex(0);
	skeleton->updateBones();
	
	int bones_location = glGetUniformLocation(m_programID, "bones");
	glUniformMatrix4fv(bones_location, skeleton->m_boneCount, GL_FALSE, (float*)skeleton->m_bones);

	for (unsigned int i = 0; i < m_fbx->getMeshCount(); ++i)
	{
		FBXMeshNode* mesh = m_fbx->getMeshByIndex(i);
		
		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, mesh->m_material->textures[FBXMaterial::DiffuseTexture]->handle);

		unsigned int* glData = (unsigned int*)mesh->m_userData;

		glBindVertexArray(glData[0]);

		// diffuse 
		// ambient colour uniform
		// diffuse colour uniform

		unsigned int diffuse = glGetUniformLocation(m_programID, "diffuse");
		glUniform1i(diffuse, 0);

		unsigned int normal = glGetUniformLocation(m_programID, "normal");
		glUniform1i(normal, 1);

		unsigned int uiLightPositionLocation = glGetUniformLocation(m_programID, "LightPos");
		glUniform3fv(uiLightPositionLocation, 1, glm::value_ptr(m_lightYPos));

		vec3 lightDir = glm::normalize(_lightDir);
		unsigned int uiLightDirectionLocation = glGetUniformLocation(m_programID, "LightDir");
		glUniform3f(uiLightDirectionLocation, lightDir.x, lightDir.y, lightDir.z);

		unsigned int uiLightColourLocation = glGetUniformLocation(m_programID, "LightColour");
		glUniform3f(uiLightColourLocation, _lightColour.x, _lightColour.y, _lightColour.z);

		unsigned int uiCameraLocation = glGetUniformLocation(m_programID, "CameraPos");
		glUniform3fv(uiCameraLocation, 0, glm::value_ptr(m_camera->GetPosition())); // 0.0f, 1.0f, 0.0f); // glm::value_ptr(m_lightYPos));

		unsigned int uiSpecPow = glGetUniformLocation(m_programID, "SpecPow");
		glUniform1f(uiSpecPow, 125.0f);

		glDrawElements(GL_TRIANGLES, (unsigned int)mesh->m_indices.size(), GL_UNSIGNED_INT, 0);

		glBindVertexArray(0);
	}

	
}
Exemplo n.º 3
0
void FBXObject::Draw(FlyCamera *camera)
{
	glUseProgram(m_programID);

	if(m_animated)
	{
		FBXSkeleton* skeleton = m_fbx->getSkeletonByIndex(0);
		skeleton->updateBones();

		int bones_location = glGetUniformLocation(m_programID, "bones");
		glUniformMatrix4fv(bones_location, skeleton->m_boneCount, GL_FALSE,	(float*)skeleton->m_bones);
			
		unsigned int projectionViewUniform = glGetUniformLocation(m_programID,"ProjectionView");
		unsigned int lightPosUniform = glGetUniformLocation(m_programID, "LightPos");
		unsigned int lightColourUniform = glGetUniformLocation(m_programID, "LightColour");
		unsigned int cameraPosUniform = glGetUniformLocation(m_programID, "CameraPos");
		unsigned int specPow = glGetUniformLocation(m_programID, "SpecPow");

		glm::vec3 camPos = camera->GetPosition();
		glm::vec3 clr = m_tweaks->m_lightColour;
		glm::vec3 pos = m_tweaks->m_lightPos;

		glUniformMatrix4fv(projectionViewUniform, 1, false, glm::value_ptr(camera->GetProjectionView()));
		glUniform3f(lightPosUniform, pos.x, pos.y, pos.z);
		glUniform3f(lightColourUniform, clr.r, clr.g, clr.b);
		glUniform3f(cameraPosUniform, camPos.x, camPos.y, camPos.z);
		glUniform1f(specPow, m_tweaks->m_specPower);


		for (unsigned int i = 0; i < m_fbx->getMeshCount(); ++i) 
		{	
			FBXMeshNode* mesh = m_fbx->getMeshByIndex(i);
			
			int m_global = glGetUniformLocation(m_programID, "global");
			glUniformMatrix4fv(m_global, 1, GL_FALSE,	&(mesh->m_globalTransform)[0][0]);
				
			if ( mesh->m_material->textures[FBXMaterial::DiffuseTexture] != nullptr )
			{
				glActiveTexture(GL_TEXTURE0);
				glBindTexture(GL_TEXTURE_2D, mesh->m_material->textures[FBXMaterial::DiffuseTexture]->handle);
			}

			

			if ( mesh->m_material->textures[FBXMaterial::NormalTexture] != nullptr )
			{
				glActiveTexture(GL_TEXTURE1);
				glBindTexture(GL_TEXTURE_2D, mesh->m_material->textures[FBXMaterial::NormalTexture]->handle);
			}

			if ( mesh->m_material->textures[FBXMaterial::SpecularTexture] != nullptr )
			{
				glActiveTexture(GL_TEXTURE2);
				glBindTexture(GL_TEXTURE_2D, mesh->m_material->textures[FBXMaterial::SpecularTexture]->handle);
			}

			unsigned int* glData = (unsigned int*)mesh->m_userData;
			glBindVertexArray(glData[0]);
			glDrawElements(GL_TRIANGLES, (unsigned int)mesh->m_indices.size(), GL_UNSIGNED_INT, 0);
		}
	}

	else 
	{
		unsigned int projectionViewUniform = glGetUniformLocation(m_programID,"ProjectionView");
		unsigned int lightPosUniform = glGetUniformLocation(m_programID, "LightPos");
		unsigned int lightColourUniform = glGetUniformLocation(m_programID, "LightColour");
		unsigned int cameraPosUniform = glGetUniformLocation(m_programID, "CameraPos");
		unsigned int specPow = glGetUniformLocation(m_programID, "SpecPow");

		glm::vec3 camPos = camera->GetPosition();
		glm::vec3 clr = m_tweaks->m_lightColour;
		glm::vec3 pos = m_tweaks->m_lightPos;

		glUniformMatrix4fv(projectionViewUniform, 1, false, glm::value_ptr(camera->GetProjectionView()));
		glUniform3f(lightPosUniform, pos.x, pos.y, pos.z);
		glUniform3f(lightColourUniform, clr.r, clr.g, clr.b);
		glUniform3f(cameraPosUniform, camPos.x, camPos.y, camPos.z);
		glUniform1f(specPow, m_tweaks->m_specPower);


		for (unsigned int i = 0; i < m_fbx->getMeshCount(); ++i) 
		{	
			FBXMeshNode* mesh = m_fbx->getMeshByIndex(i);
			
			int m_global = glGetUniformLocation(m_programID, "global");
			glUniformMatrix4fv(m_global, 1, GL_FALSE,	&(mesh->m_globalTransform)[0][0]);
				
			if ( mesh->m_material->textures[FBXMaterial::DiffuseTexture] != nullptr )
			{
				glActiveTexture(GL_TEXTURE0);
				glBindTexture(GL_TEXTURE_2D, mesh->m_material->textures[FBXMaterial::DiffuseTexture]->handle);
			}

			if ( mesh->m_material->textures[FBXMaterial::NormalTexture] != nullptr )
			{
				glActiveTexture(GL_TEXTURE1);
				glBindTexture(GL_TEXTURE_2D, mesh->m_material->textures[FBXMaterial::NormalTexture]->handle);
			}
			
			if ( mesh->m_material->textures[FBXMaterial::SpecularTexture] != nullptr )
			{
				glActiveTexture(GL_TEXTURE2);
				glBindTexture(GL_TEXTURE_2D, mesh->m_material->textures[FBXMaterial::SpecularTexture]->handle);
			}

			unsigned int* glData = (unsigned int*)mesh->m_userData;
			glBindVertexArray(glData[0]);
			glDrawElements(GL_TRIANGLES, (unsigned int)mesh->m_indices.size(), GL_UNSIGNED_INT, 0);
		}
	}
	
}
Exemplo n.º 4
0
void APP_Animation::Draw()
{
	Gizmos::clear();
	Gizmos::addTransform(glm::mat4(1));

	vec4 white(1);
	vec4 black(0, 0, 0, 1);

	//	draws the home grid
	for (int i = 0; i < 21; ++i) {
		Gizmos::addLine(vec3(-10 + i, 0, 10),
			vec3(-10 + i, 0, -10),
			i == 10 ? white : black);
		Gizmos::addLine(vec3(10, 0, -10 + i),
			vec3(-10, 0, -10 + i),
			i == 10 ? white : black);
	}

	Gizmos::draw(GameCam->GetProjectionView());

	glUseProgram(m_program);
	// bind the camera
	int loc = glGetUniformLocation(m_program, "ProjectionView");
	glUniformMatrix4fv(loc, 1, GL_FALSE, &(GameCam->GetProjectionView()[0][0]));

	int lightDirUniform = -1;
	// bind the directional light position for a directional light
	lightDirUniform = glGetUniformLocation(m_program, "directionalLight");	//get the directional light uniform index from the vertex shader
	glm::vec3 dirLight = glm::vec3(0, 1, -10); //controls the lights position in the world	
	glUniform3fv(lightDirUniform, 1, glm::value_ptr(dirLight));	//set the lightDir uniform variabe in the vertex shader

	// bind the point light position for a directional light
	lightDirUniform = glGetUniformLocation(m_program, "pointLight");	//get the point light uniform index from the vertex shader
	glm::vec3 pointLight = glm::vec3(0, -1, -1); //controls the lights position in the world	
	glUniform3fv(lightDirUniform, 1, glm::value_ptr(pointLight));	//set the lightDir uniform variabe in the vertex shader

	// bind change the light colour
	int lightColUniform = glGetUniformLocation(m_program, "lightColour");	//get the Time uniform index from the vertex shader
	glm::vec3 lightColour = glm::vec3(1, 1, 1); //controls the lights colour
	glUniform3fv(lightColUniform, 1, glm::value_ptr(lightColour));	//set the lightDir uniform variabe in the vertex shader

	// bind change the camera position
	int cameraPosUniform = glGetUniformLocation(m_program, "CameraPos");	//get the Time uniform index from the vertex shader
	glm::vec3 cameraPos = glm::vec3(GameCam->GetWorldTransform()[3]); //controls the lights position in the world		
	glUniform3fv(cameraPosUniform, 1, glm::value_ptr(cameraPos));	//set the lightDir uniform variabe in the vertex shader

	// bind change the spec power
	int specPosUniform = glGetUniformLocation(m_program, "SpecPow");	//get the Time uniform index from the vertex shader
	GLfloat specPow = 512; //controls the lights position in the world		
	glUniform1f(specPosUniform, specPow);	//set the lightDir uniform variabe in the vertex shader

	// grab the skeleton and animation we want to use
	FBXSkeleton* skeleton = m_fbx->getSkeletonByIndex(0);
	skeleton->updateBones();
	int bones_location = glGetUniformLocation(m_program, "bones");
	glUniformMatrix4fv(bones_location, skeleton->m_boneCount, GL_FALSE, (float*)skeleton->m_bones);

	int global_location = glGetUniformLocation(m_program, "Global"); //apply a global scale
	glUniformMatrix4fv(global_location, 1, GL_FALSE, glm::value_ptr(glm::scale(glm::vec3(.005, .005, .005))));

	// bind our vertex array object and draw the mesh
	unsigned int meshCount = m_fbx->getMeshCount();
	for (unsigned int i = 0; i < meshCount; ++i) {
		FBXMeshNode* mesh = m_fbx->getMeshByIndex(i);
		unsigned int* glData = (unsigned int*)mesh->m_userData;
		glBindVertexArray(glData[0]);

		//set diffuse texture	
		glActiveTexture(GL_TEXTURE0); //set for initial active texture		
		glBindTexture(GL_TEXTURE_2D, glData[3]);	//bind the diffuse texture
		int difLoc = glGetUniformLocation(m_program, "Diffuse"); //get diffuse location
		glUniform1i(difLoc, 0); //set to the diffuse to the texture index	

		glDrawElements(GL_TRIANGLES,
			(unsigned int)mesh->m_indices.size(), GL_UNSIGNED_INT, 0);
	}
}