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
|
|
|
|
2016-06-18 09:12:09 +00:00
|
|
|
void renderer_entity(Renderer *renderer, Entity *entity, f32 rotate, v3 color)
|
2016-06-25 11:23:15 +00:00
|
|
|
{
|
|
|
|
renderer_object(renderer, entity->pos, entity->size, rotate, color,
|
|
|
|
entity->tex);
|
|
|
|
}
|
|
|
|
|
|
|
|
void renderer_object(Renderer *renderer, v2 pos, v2 size, f32 rotate, v3 color,
|
|
|
|
Texture *tex)
|
2016-06-09 05:49:03 +00:00
|
|
|
{
|
2016-06-17 14:40:40 +00:00
|
|
|
shader_use(renderer->shader);
|
2016-06-25 11:23:15 +00:00
|
|
|
mat4 transMatrix = mat4_translate(pos.x, pos.y, 0.0f);
|
2016-06-18 09:12:09 +00:00
|
|
|
mat4 rotateMatrix = mat4_rotate(rotate, 0.0f, 0.0f, 1.0f);
|
2016-06-23 11:34:38 +00:00
|
|
|
|
2016-06-13 14:51:14 +00:00
|
|
|
// NOTE(doyle): We draw everything as a unit square in OGL. Scale it to size
|
2016-06-23 11:34:38 +00:00
|
|
|
// TODO(doyle): We should have a notion of hitbox size and texture size
|
|
|
|
// we're going to render so we can draw textures that may be bigger than the
|
|
|
|
// entity, (slightly) but keep a consistent bounding box
|
2016-06-25 11:23:15 +00:00
|
|
|
mat4 scaleMatrix = mat4_scale(size.x, size.y, 1.0f);
|
2016-06-09 05:49:03 +00:00
|
|
|
|
2016-06-18 09:12:09 +00:00
|
|
|
mat4 model = mat4_mul(transMatrix, mat4_mul(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-25 11:23:15 +00:00
|
|
|
|
|
|
|
if (tex)
|
|
|
|
{
|
|
|
|
glBindTexture(GL_TEXTURE_2D, tex->id);
|
|
|
|
shader_uniformSet1i(renderer->shader, "tex", 0);
|
|
|
|
}
|
2016-06-17 14:40:40 +00:00
|
|
|
|
2016-06-18 14:34:20 +00:00
|
|
|
glBindVertexArray(renderer->vao);
|
2016-06-09 05:49:03 +00:00
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
|
|
|
glBindVertexArray(0);
|
2016-06-25 09:12:25 +00:00
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
2016-06-17 14:40:40 +00:00
|
|
|
glCheckError();
|
2016-06-09 05:49:03 +00:00
|
|
|
}
|