|
|
|
@ -110,10 +110,10 @@ namespace lunarium
|
|
|
|
// DRAW METHODS
|
|
|
|
// DRAW METHODS
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
void Renderer2D::DrawSprite(Texture* texture, glm::vec2 position, Rectangle sub_texture_area, Color color, float angle)
|
|
|
|
void Renderer2D::DrawSprite(Texture* texture, glm::vec2 position, Rectangle sub_texture_area, Color color, float angle, glm::mat4 parent_transform)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Rectangle quad = Rectangle::MakeFromTopLeft(position.x, position.y, sub_texture_area.width(), sub_texture_area.height());
|
|
|
|
Rectangle quad = Rectangle::MakeFromTopLeft(position.x, position.y, sub_texture_area.width(), sub_texture_area.height());
|
|
|
|
DrawQuad(quad, color, texture, angle, sub_texture_area);
|
|
|
|
DrawQuad(quad, color, texture, angle, sub_texture_area, parent_transform);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// void Renderer2D::DrawSprite(Texture* texture, Rectangle destination, Rectangle sub_texture_area, Color color = Color::White(), float angle = 0.0f)
|
|
|
|
// void Renderer2D::DrawSprite(Texture* texture, Rectangle destination, Rectangle sub_texture_area, Color color = Color::White(), float angle = 0.0f)
|
|
|
|
@ -121,7 +121,7 @@ namespace lunarium
|
|
|
|
// DrawQuad(destination, color, texture, angle, sub_texture_area);
|
|
|
|
// DrawQuad(destination, color, texture, angle, sub_texture_area);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
void Renderer2D::DrawQuad(Rectangle quad, Color color, Texture* texture, float angle, Rectangle sub_texture_area)
|
|
|
|
void Renderer2D::DrawQuad(Rectangle quad, Color color, Texture* texture, float angle, Rectangle sub_texture_area, glm::mat4 parent_transform)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!mQuadData.VertexBuffer->WillFit(4))
|
|
|
|
if (!mQuadData.VertexBuffer->WillFit(4))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -168,6 +168,8 @@ namespace lunarium
|
|
|
|
// Need to invert the offset_y because OpenGL likes being weird
|
|
|
|
// Need to invert the offset_y because OpenGL likes being weird
|
|
|
|
offset_y *= -1.0f;
|
|
|
|
offset_y *= -1.0f;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glm::vec3 parent_pos = parent_transform[3];
|
|
|
|
|
|
|
|
|
|
|
|
// FIRST
|
|
|
|
// FIRST
|
|
|
|
QuadData::Vertex verts[4];
|
|
|
|
QuadData::Vertex verts[4];
|
|
|
|
int vert_size = sizeof(QuadData::Vertex);
|
|
|
|
int vert_size = sizeof(QuadData::Vertex);
|
|
|
|
@ -179,6 +181,7 @@ namespace lunarium
|
|
|
|
verts[0].angle = angle;
|
|
|
|
verts[0].angle = angle;
|
|
|
|
verts[0].scale = glm::vec3(quad.HalfWidth * 2, quad.HalfHeight * 2, 1.0f);
|
|
|
|
verts[0].scale = glm::vec3(quad.HalfWidth * 2, quad.HalfHeight * 2, 1.0f);
|
|
|
|
verts[0].tex_is_grey_scale = tex_is_grey_scale;
|
|
|
|
verts[0].tex_is_grey_scale = tex_is_grey_scale;
|
|
|
|
|
|
|
|
verts[0].parent_transform = parent_pos;
|
|
|
|
//memcpy(&mQuadData.RawVertexBuffer[mQuadData.RawBufferIndex], &v1, vert_size);
|
|
|
|
//memcpy(&mQuadData.RawVertexBuffer[mQuadData.RawBufferIndex], &v1, vert_size);
|
|
|
|
//mQuadData.RawBufferIndex += 1;
|
|
|
|
//mQuadData.RawBufferIndex += 1;
|
|
|
|
//mQuadData.VertexBuffer->PushVertices((void*)&v1, 1);
|
|
|
|
//mQuadData.VertexBuffer->PushVertices((void*)&v1, 1);
|
|
|
|
@ -192,6 +195,7 @@ namespace lunarium
|
|
|
|
verts[1].angle = angle;
|
|
|
|
verts[1].angle = angle;
|
|
|
|
verts[1].scale = glm::vec3(quad.HalfWidth * 2, quad.HalfHeight * 2, 1.0f);
|
|
|
|
verts[1].scale = glm::vec3(quad.HalfWidth * 2, quad.HalfHeight * 2, 1.0f);
|
|
|
|
verts[1].tex_is_grey_scale = tex_is_grey_scale;
|
|
|
|
verts[1].tex_is_grey_scale = tex_is_grey_scale;
|
|
|
|
|
|
|
|
verts[1].parent_transform = parent_pos;
|
|
|
|
//memcpy(&mQuadData.RawVertexBuffer[mQuadData.RawBufferIndex], &v2, vert_size);
|
|
|
|
//memcpy(&mQuadData.RawVertexBuffer[mQuadData.RawBufferIndex], &v2, vert_size);
|
|
|
|
//mQuadData.RawBufferIndex += 1;
|
|
|
|
//mQuadData.RawBufferIndex += 1;
|
|
|
|
// mQuadData.VertexBuffer->PushVertices((void*)&v2, 1);
|
|
|
|
// mQuadData.VertexBuffer->PushVertices((void*)&v2, 1);
|
|
|
|
@ -205,6 +209,7 @@ namespace lunarium
|
|
|
|
verts[2].angle = angle;
|
|
|
|
verts[2].angle = angle;
|
|
|
|
verts[2].scale = glm::vec3(quad.HalfWidth * 2, quad.HalfHeight * 2, 1.0f);
|
|
|
|
verts[2].scale = glm::vec3(quad.HalfWidth * 2, quad.HalfHeight * 2, 1.0f);
|
|
|
|
verts[2].tex_is_grey_scale = tex_is_grey_scale;
|
|
|
|
verts[2].tex_is_grey_scale = tex_is_grey_scale;
|
|
|
|
|
|
|
|
verts[2].parent_transform = parent_pos;
|
|
|
|
//memcpy(&mQuadData.RawVertexBuffer[mQuadData.RawBufferIndex], &v3, vert_size);
|
|
|
|
//memcpy(&mQuadData.RawVertexBuffer[mQuadData.RawBufferIndex], &v3, vert_size);
|
|
|
|
//mQuadData.RawBufferIndex += 1;
|
|
|
|
//mQuadData.RawBufferIndex += 1;
|
|
|
|
//mQuadData.VertexBuffer->PushVertices((void*)&v3, 1);
|
|
|
|
//mQuadData.VertexBuffer->PushVertices((void*)&v3, 1);
|
|
|
|
@ -218,6 +223,7 @@ namespace lunarium
|
|
|
|
verts[3].angle = angle;
|
|
|
|
verts[3].angle = angle;
|
|
|
|
verts[3].scale = glm::vec3(quad.HalfWidth * 2, quad.HalfHeight * 2, 1.0f);
|
|
|
|
verts[3].scale = glm::vec3(quad.HalfWidth * 2, quad.HalfHeight * 2, 1.0f);
|
|
|
|
verts[3].tex_is_grey_scale = tex_is_grey_scale;
|
|
|
|
verts[3].tex_is_grey_scale = tex_is_grey_scale;
|
|
|
|
|
|
|
|
verts[3].parent_transform = parent_pos;
|
|
|
|
//memcpy(&mQuadData.RawVertexBuffer[mQuadData.RawBufferIndex], &v4, vert_size);
|
|
|
|
//memcpy(&mQuadData.RawVertexBuffer[mQuadData.RawBufferIndex], &v4, vert_size);
|
|
|
|
//mQuadData.RawBufferIndex += 1;
|
|
|
|
//mQuadData.RawBufferIndex += 1;
|
|
|
|
|
|
|
|
|
|
|
|
@ -498,6 +504,7 @@ namespace lunarium
|
|
|
|
mQuadData.BufferLayout.PushVertexAttribute(VertexAttribute { VertexAttributeType::FLOAT32, 1 }); // angle
|
|
|
|
mQuadData.BufferLayout.PushVertexAttribute(VertexAttribute { VertexAttributeType::FLOAT32, 1 }); // angle
|
|
|
|
mQuadData.BufferLayout.PushVertexAttribute(VertexAttribute { VertexAttributeType::FLOAT32, 3 }); // Scale
|
|
|
|
mQuadData.BufferLayout.PushVertexAttribute(VertexAttribute { VertexAttributeType::FLOAT32, 3 }); // Scale
|
|
|
|
mQuadData.BufferLayout.PushVertexAttribute(VertexAttribute { VertexAttributeType::FLOAT32, 1 }); // tex_is_grey_scale
|
|
|
|
mQuadData.BufferLayout.PushVertexAttribute(VertexAttribute { VertexAttributeType::FLOAT32, 1 }); // tex_is_grey_scale
|
|
|
|
|
|
|
|
mQuadData.BufferLayout.PushVertexAttribute(VertexAttribute { VertexAttributeType::FLOAT32, 3 }); // parent_transform
|
|
|
|
mQuadData.VertexBuffer = VertexBuffer::Create(mQuadData.BufferLayout, mQuadData.MaxVertices, nullptr, mQuadData.MaxIndices, indices);
|
|
|
|
mQuadData.VertexBuffer = VertexBuffer::Create(mQuadData.BufferLayout, mQuadData.MaxVertices, nullptr, mQuadData.MaxIndices, indices);
|
|
|
|
|
|
|
|
|
|
|
|
// RAW VERTEX BUFFER
|
|
|
|
// RAW VERTEX BUFFER
|
|
|
|
|