示例#1
0
bool render() {
  // Render meshes
  for (auto &e : meshes) {
    auto m = e.second;
    // Bind effect
    renderer::bind(eff);
    // Create MVP matrix
    auto M = m.get_transform().get_transform_matrix();
    auto V = cam.get_view();
    auto P = cam.get_projection();
    auto MVP = P * V * M;
    // Set MVP matrix uniform
    glUniformMatrix4fv(eff.get_uniform_location("MVP"), 1, GL_FALSE, value_ptr(MVP));

    // Bind and set texture
    renderer::bind(tex, 0);
    glUniform1i(eff.get_uniform_location("tex"), 0);

    // Render mesh
    renderer::render(m);
  }

  return true;
}
bool render()
{
	// Render meshes
	for (auto &e : meshes)
	{
		auto m = e.second;
		
		if (CHECK_GL_ERROR)
		{
			__debugbreak();
		}

		// Bind effect
		renderer::bind(eff);

		if (CHECK_GL_ERROR)
		{
			__debugbreak();
		}

		// Create MVP matrix
		auto M = m.get_transform().get_transform_matrix();
		auto V = cam.get_view();
		auto P = cam.get_projection();
		auto MVP = P * V * M;
		// Set MVP matrix uniform
		glUniformMatrix4fv(
			eff.get_uniform_location("MVP"), // Location of uniform
			1, // Number of values - 1 mat4
			GL_FALSE, // Transpose the matrix?
			value_ptr(MVP)); // Pointer to matrix data

		// ********************
		// Set M matrix uniform
		// ********************
		glUniformMatrix4fv(eff.get_uniform_location("M"), 1, GL_FALSE, value_ptr(M));


		// ***********************
		// Set N matrix uniform
		// - remember - 3x3 matrix
		// ***********************
		mat3 N = mat3(M);
		N = transpose(N);
		glUniformMatrix3fv(eff.get_uniform_location("N"), 1, GL_FALSE, value_ptr(N));


		// *************
		// Bind material
		// *************
		material mm = m.get_material();

		renderer::bind(mm, "mat");
	
		

		// **********
		// Bind light
		// **********
		//glUniform4fv(eff.get_uniform_location("light.ambient_intensity"), 1, value_ptr(light.get_ambient_intensity));
		renderer::bind(light, "light");
		

		// ************
		// Bind texture
		// ************
		renderer::bind(tex, 0);
		

		// ***************
		// Set tex uniform
		// ***************
		glUniform1i(eff.get_uniform_location("tex"), 0);

		// *****************************
		// Set eye position
		// - Get this from active camera
		// *****************************
		vec3 eyeP = cam.get_position();

		glUniform3f(eff.get_uniform_location("eye_pos"), eyeP.x, eyeP.y, eyeP.z);

		


		// Render mesh
		renderer::render(m);
	}

	return true;
}