Dengine/src/Renderer.cpp

39 lines
1.1 KiB
C++
Raw Normal View History

2016-06-09 05:49:03 +00:00
#include <Dengine/OpenGL.h>
2016-06-16 14:14:58 +00:00
#include <Dengine/Renderer.h>
2016-06-09 05:49:03 +00:00
#include <glm/gtc/matrix_transform.hpp>
2016-06-16 14:14:58 +00:00
#include <glm/gtx/transform.hpp>
2016-06-09 05:49:03 +00:00
2016-06-17 14:40:40 +00:00
void renderer_entity(Renderer *renderer, Entity *entity, GLfloat rotate,
glm::vec3 color)
2016-06-09 05:49:03 +00:00
{
2016-06-17 14:40:40 +00:00
shader_use(renderer->shader);
2016-06-16 14:14:58 +00:00
glm::mat4 transMatrix = glm::translate(glm::vec3(entity->pos, 0.0f));
glm::mat4 rotateMatrix = glm::rotate(rotate, glm::vec3(0.0f, 0.0f, 1.0f));
2016-06-17 14:40:40 +00:00
glCheckError();
2016-06-09 05:49:03 +00:00
// NOTE(doyle): We draw everything as a unit square in OGL. Scale it to size
2016-06-16 14:14:58 +00:00
glm::mat4 scaleMatrix = glm::scale(glm::vec3(entity->size, 1.0f));
2016-06-09 05:49:03 +00:00
glm::mat4 model = transMatrix * rotateMatrix * scaleMatrix;
2016-06-17 14:40:40 +00:00
shader_uniformSetMat4fv(renderer->shader, "model", model);
glCheckError();
2016-06-09 05:49:03 +00:00
// TODO(doyle): Unimplemented
// this->shader->uniformSetVec3f("spriteColor", color);
glActiveTexture(GL_TEXTURE0);
2016-06-17 14:40:40 +00:00
glCheckError();
glBindTexture(GL_TEXTURE_2D, entity->tex->id);
glCheckError();
shader_uniformSet1i(renderer->shader, "tex", 0);
glCheckError();
glBindVertexArray(renderer->quadVAO);
glCheckError();
2016-06-09 05:49:03 +00:00
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
2016-06-17 14:40:40 +00:00
glCheckError();
2016-06-09 05:49:03 +00:00
glBindVertexArray(0);
2016-06-17 14:40:40 +00:00
glCheckError();
2016-06-09 05:49:03 +00:00
}