Example #1
0
void SpriteRenderer::DrawSprite(Texture2D &texture, glm::vec2 position, glm::vec2 size, GLfloat rotate, glm::vec3 color)
{
	// Prepare transformations
	this->shader.Use();
	glm::mat4 model;
	model = glm::translate(model, glm::vec3(position, 0.0f));  // First translate (transformations are: scale happens first, then rotation and then finall translation happens; reversed order)

	model = glm::translate(model, glm::vec3(0.5f * size.x, 0.5f * size.y, 0.0f)); // Move origin of rotation to center of quad
	model = glm::rotate(model, rotate, glm::vec3(0.0f, 0.0f, 1.0f)); // Then rotate
	model = glm::translate(model, glm::vec3(-0.5f * size.x, -0.5f * size.y, 0.0f)); // Move origin back

	model = glm::scale(model, glm::vec3(size, 1.0f)); // Last scale

	this->shader.SetMatrix4("model", model);

	// Render textured quad
	this->shader.SetVector3f("spriteColor", color);

	glActiveTexture(GL_TEXTURE0);
	texture.Bind();

	glBindVertexArray(this->quadVAO);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, Ibo);
	glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, (GLvoid*)0);

	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
	glBindVertexArray(0);
}
	//--------------------------------------------------------------------------
	void PostProcessor::Draw(			const Texture2D& _colorTex,
										float _toneExposure,
										const RenderTarget& _renderTarget)
	{
		glUseProgram(toneMapping.program.id);
		glProgramUniform1f(toneMapping.program.id, toneMapping.exposureVar, _toneExposure);
		_colorTex.Bind(toneMapping.colorTexUnit);
		_renderTarget.Draw();
	}
Example #3
0
void SpriteRenderer::DrawSprite(Texture2D& texture, glm::vec2 position, glm::vec2 size /*= glm::vec2(10, 10)*/, GLfloat rotate /*= 0.0f*/, glm::vec3 color /*= glm::vec3(1.0f)*/)
{
	this->shader.Use();
	glm::mat4 model;
	
	model = glm::translate(model, glm::vec3(position, 0.0f));
	model = glm::translate(model, glm::vec3(0.5f * size.x, 0.5f * size.y, 0.0f));
	model = glm::rotate(model, rotate, glm::vec3(0.0f, 0.0f, 1.0f));
	model = glm::translate(model, glm::vec3(-0.5f * size.x, -0.5f * size.y, 0.0f));
	model = glm::scale(model, glm::vec3(size, 1.0f));

	this->shader.SetMatrix4("model", model);
	this->shader.SetVector3f("spriteColor", color);

	glActiveTexture(GL_TEXTURE0);
	texture.Bind();

	glBindVertexArray(this->quadVAO);
	glDrawArrays(GL_TRIANGLES, 0, 6);
	glBindVertexArray(0);
}
Example #4
0
void SpriteRenderer::draw(
    glm::vec2 position,
    glm::vec2 size,
    const Texture2D& texture,
    const Camera& camera
    ) const
{
    ResourceManager::GetShader("sprite_texture")->use();
    glm::mat4 model;
    // При расстановке объектов сдвигаем начало координат в центр экрана. Чтоб герой всегда был по центру.
    model = glm::translate(model, glm::vec3(position.x + screenWidth_ / 2, position.y + screenHeight_ / 2, 0.0f));
    model = glm::scale(model, glm::vec3(size, 1.0f));

    glm::mat4 view;
    camera.getView(view);

    ResourceManager::GetShader("sprite_texture")->setUniform("view", view);
    ResourceManager::GetShader("sprite_texture")->setUniform("model", model);

    glBindVertexArray(VAO_);
    texture.Bind();
    glDrawArrays(GL_TRIANGLES, 0, 6);
    glBindVertexArray(0);
}