コード例 #1
0
ファイル: 33_Dissolve.cpp プロジェクト: 40167459/set08116
bool load_content() {
  // Create mesh object, cheating and using the mesh builder for now
  m = mesh(geometry_builder::create_box());
  // Scale geometry
  m.get_transform().scale = vec3(10.0f);

  // Load in dissolve shader
  eff.add_shader("33_Dissolve/dissolve.vert", GL_VERTEX_SHADER);
  eff.add_shader("33_Dissolve/dissolve.frag", GL_FRAGMENT_SHADER);

  // Build effect
  eff.build();

  // Load in textures
  tex = texture("textures/checker.png");
  dissolve = texture("textures/blend_map2.jpg");

  // Set camera properties
  cam.set_position(vec3(30.0f, 30.0f, 30.0f));
  cam.set_target(vec3(0.0f, 0.0f, 0.0f));
  auto aspect = static_cast<float>(renderer::get_screen_width()) / static_cast<float>(renderer::get_screen_height());
  cam.set_projection(quarter_pi<float>(), aspect, 2.414f, 1000.0f);

  return true;
}
コード例 #2
0
ファイル: 33_Dissolve.cpp プロジェクト: 40167459/set08116
bool render() {
  // 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"), // Location of uniform
                     1,                               // Number of values - 1 mat4
                     GL_FALSE,                        // Transpose the matrix?
                     value_ptr(MVP));                 // Pointer to matrix data

  // *********************************
  // Set the dissolve_factor uniform value

  // Bind the two textures - use different index for each


  // Set the uniform values for textures - use correct index


  // *********************************

  // Set UV_scroll uniform, adds cool movent (Protip: This is a super easy way to do fire effects;))
  glUniform2fv(eff.get_uniform_location("UV_SCROLL"), 1, value_ptr(uv_scroll));
  // Render the mesh
  renderer::render(m);

  return true;
}
コード例 #3
0
bool render() {
  // 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"), // Location of uniform
                     1,                               // Number of values - 1 mat4
                     GL_FALSE,                        // Transpose the matrix?
                     value_ptr(MVP));                 // Pointer to matrix data

  // *********************************
  // Bind texture to renderer
  renderer::bind(tex, 1);
  // Set the texture value for the shader here
  glUniform1i(eff.get_uniform_location(" tex"), 0);
  // *********************************

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

  return true;
}
コード例 #4
0
bool render()
{
	// 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;
}
コード例 #5
0
bool load_content() {
  // Construct geometry object
  geometry geom;
  // Create triangle data
  // Positions
  vector<vec3> positions{vec3(0.0f, 1.0f, 0.0f), vec3(-1.0f, -1.0f, 0.0f), vec3(1.0f, -1.0f, 0.0f)};
 
  // *********************************
  // Define texture coordinates for triangle
  vector<vec2> UVs{ vec2(0.0f, 1.0f),
	  vec2(-1.0f, -1.0f),
	  vec2(1.0f, -1.0f) };
  


  // *********************************
  // Add to the geometry
  geom.add_buffer(positions, BUFFER_INDEXES::POSITION_BUFFER);
  // *********************************
  // Add texture coordinate buffer to geometry
  geom.add_buffer(positions, BUFFER_INDEXES::TEXTURE_COORDS_0);
  // *********************************

  // Create mesh object
  m = mesh(geom);
  m2 = mesh(geom);
  m2.get_transform().translate(vec3(5.0f, 1.0f, 1.0f));
  // Load in texture shaders here
  eff.add_shader("27_Texturing_Shader/simple_texture.vert", GL_VERTEX_SHADER);
  eff.add_shader("27_Texturing_Shader/simple_texture.frag", GL_FRAGMENT_SHADER);
  // *********************************
  // Build effect
  eff.build();
  // Load texture "textures/sign.jpg"
  tex = texture("textures/sign.jpg");
  tex2 = texture("textures/stonygrass.jpg");
  // *********************************

  // Set camera properties
  cam.set_position(vec3(10.0f, 10.0f, 10.0f));
  cam.set_target(vec3(0.0f, 0.0f, 0.0f));
  auto aspect = static_cast<float>(renderer::get_screen_width()) / static_cast<float>(renderer::get_screen_height());
  cam.set_projection(quarter_pi<float>(), aspect, 2.414f, 1000.0f);

  return true;
}
コード例 #6
0
bool render()
{
	// 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"), // Location of uniform
		1, // Number of values - 1 mat4
		GL_FALSE, // Transpose the matrix?
		value_ptr(MVP)); // Pointer to matrix data

	// ******************************************************
	// Bind the three textures - use different index for each
	// ******************************************************

	renderer::bind(*texs[0], 0);
	renderer::bind(*texs[1], 1);
	renderer::bind(blend_map, 2); 

	// *******************************************************
	// Set the uniform values for textures - use correct index
	// *******************************************************

	
	glUniform1i(eff.get_uniform_location("tex[0]"), 0);
	glUniform1i(eff.get_uniform_location("tex[1]"), 1);
	glUniform1i(eff.get_uniform_location("blend"), 2);
    // ***************
	// Render the mesh
    // ***************
	renderer::render(m);


	return true;
}
コード例 #7
0
bool render() {
  // 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 texture to renderer

  // Set the texture value for the shader here

  // *********************************

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

  return true;
}
コード例 #8
0
bool load_content()
{
	// Construct geometry object
	geometry geom;
	geom.set_type(GL_QUADS);
	// Create quad data
	// Positions
	vector<vec3> positions
	{
		vec3(-1.0f, 1.0f, 0.0f),
		vec3(-1.0f, -1.0f, 0.0f),
		vec3(1.0f, -1.0f, 0.0f),
		vec3(1.0f, 1.0f, 0.0f)
	};
	// Texture coordinates
	vector<vec2> tex_coords
	{
		vec2(0.0f, 1.0f),
		vec2(0.0f, 0.0f),
		vec2(1.0f, 0.0f),
		vec2(1.0f, 1.0f)
	};
	// Add to the geometry
	geom.add_buffer(positions, BUFFER_INDEXES::POSITION_BUFFER);
	geom.add_buffer(tex_coords, BUFFER_INDEXES::TEXTURE_COORDS_0);

	// Create mesh object
	m = mesh(geom);
	// Scale geometry
	m.get_transform().scale = vec3(10.0f, 10.0f, 10.0f);

	// ********************
	// Load in blend shader
	// ********************
	eff.add_shader("..\\resources\\shaders\\blend.vert", GL_VERTEX_SHADER);			// vertex
	eff.add_shader("..\\resources\\shaders\\blend.frag", GL_FRAGMENT_SHADER);		// fragment

    // ************
	// Build effect
    // ************
	eff.build();


	// **********************
	// Load main two textures
	// **********************
	texs[0] = new texture("..\\resources\\textures\\grass.png", false, false);
	texs[1] = new texture("..\\resources\\textures\\stonygrass.jpg", false, false);


	// **************
	// Load blend map
	// **************
	blend_map = texture("..\\resources\\textures\\blend_map.jpg", false, false);

	// Set camera properties
	cam.set_position(vec3(0.0f, 0.0f, 30.0f));
	cam.set_target(vec3(0.0f, 0.0f, 0.0f));
	auto aspect = static_cast<float>(renderer::get_screen_width()) / static_cast<float>(renderer::get_screen_height());
	cam.set_projection(quarter_pi<float>(), aspect, 2.414f, 1000.0f);

	return true;
}