aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/graphics/mesh.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin/graphics/mesh.cpp')
-rw-r--r--src/libjin/graphics/mesh.cpp114
1 files changed, 57 insertions, 57 deletions
diff --git a/src/libjin/graphics/mesh.cpp b/src/libjin/graphics/mesh.cpp
index 71ebf62..2847a4f 100644
--- a/src/libjin/graphics/mesh.cpp
+++ b/src/libjin/graphics/mesh.cpp
@@ -8,71 +8,71 @@ using namespace JinEngine::Graphics::Shaders;
namespace JinEngine
{
- namespace Graphics
- {
+ namespace Graphics
+ {
- Mesh::Mesh()
- : mGraphic(nullptr)
- {
- }
+ Mesh::Mesh()
+ : mGraphic(nullptr)
+ {
+ }
- void Mesh::setGraphic(const Graphic* graphic)
- {
- mGraphic = graphic;
- }
+ void Mesh::setGraphic(const Graphic* graphic)
+ {
+ mGraphic = graphic;
+ }
- void Mesh::pushVertex(float x, float y, float u, float v, Color color)
- {
- Vertex vert;
- vert.xy.x() = x; vert.xy.y() = y;
- vert.uv.u() = u; vert.uv.v() = v;
- vert.color = color;
- pushVertex(vert);
- }
+ void Mesh::pushVertex(float x, float y, float u, float v, Color color)
+ {
+ Vertex vert;
+ vert.xy.x() = x; vert.xy.y() = y;
+ vert.uv.u() = u; vert.uv.v() = v;
+ vert.color = color;
+ pushVertex(vert);
+ }
- void Mesh::pushVertex(const Vertex& vert)
- {
- mVertices.push_back(vert);
- // Update bound
- if (mVertices.size() == 2)
- {
- const Vertex& v0 = mVertices[0];
- mBound.l = min(v0.xy.x(), vert.xy.x());
- mBound.r = max(v0.xy.x(), vert.xy.x());
- mBound.t = min(v0.xy.y(), vert.xy.y());
- mBound.b = max(v0.xy.y(), vert.xy.y());
- }
- else
- {
- float x = vert.xy.x(), y = vert.xy.y();
- mBound.l = x < mBound.l ? x : mBound.l;
- mBound.r = x > mBound.r ? x : mBound.r;
- mBound.t = y < mBound.t ? y : mBound.t;
- mBound.b = y > mBound.b ? y : mBound.b;
- }
- }
+ void Mesh::pushVertex(const Vertex& vert)
+ {
+ mVertices.push_back(vert);
+ // Update bound
+ if (mVertices.size() == 2)
+ {
+ const Vertex& v0 = mVertices[0];
+ mBound.l = min(v0.xy.x(), vert.xy.x());
+ mBound.r = max(v0.xy.x(), vert.xy.x());
+ mBound.t = min(v0.xy.y(), vert.xy.y());
+ mBound.b = max(v0.xy.y(), vert.xy.y());
+ }
+ else
+ {
+ float x = vert.xy.x(), y = vert.xy.y();
+ mBound.l = x < mBound.l ? x : mBound.l;
+ mBound.r = x > mBound.r ? x : mBound.r;
+ mBound.t = y < mBound.t ? y : mBound.t;
+ mBound.b = y > mBound.b ? y : mBound.b;
+ }
+ }
- void Mesh::render(float x, float y, float sx, float sy, float r, float ox, float oy) const
- {
- if (mGraphic == nullptr || mVertices.size() == 0)
- return;
+ void Mesh::render(float x, float y, float sx, float sy, float r, float ox, float oy) const
+ {
+ if (mGraphic == nullptr || mVertices.size() == 0)
+ return;
- Math::Matrix modelViewMatrix = gl.getModelViewMatrix(x, y, sx, sy, r, ox, oy);
+ Math::Matrix modelViewMatrix = gl.getModelViewMatrix(x, y, sx, sy, r, ox, oy);
- Shader* shader = gl.getShader();
- shader->begin()
- .sendMatrix4(SHADER_MODELVIEW_MATRIX, &modelViewMatrix)
- .sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix())
- .uploadVertices(2, GL_FLOAT, sizeof(Vertex), &(mVertices[0].xy))
- .uploadUV(2, GL_FLOAT, sizeof(Vertex), &(mVertices[0].uv))
- .uploadColor(4, GL_UNSIGNED_BYTE, sizeof(Vertex), &(mVertices[0].color), GL_TRUE);
+ Shader* shader = gl.getShader();
+ shader->begin()
+ .sendMatrix4(SHADER_MODELVIEW_MATRIX, &modelViewMatrix)
+ .sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.getProjectionMatrix())
+ .uploadVertices(2, GL_FLOAT, sizeof(Vertex), &(mVertices[0].xy))
+ .uploadUV(2, GL_FLOAT, sizeof(Vertex), &(mVertices[0].uv))
+ .uploadColor(4, GL_UNSIGNED_BYTE, sizeof(Vertex), &(mVertices[0].color), GL_TRUE);
- gl.bindTexture2D(mGraphic->getGLTexture());
- gl.drawArrays(GL_POLYGON, 0, mVertices.size());
-
+ gl.bindTexture2D(mGraphic->getGLTexture());
+ gl.drawArrays(GL_POLYGON, 0, mVertices.size());
+
- shader->end();
- };
+ shader->end();
+ };
- } // namespace Graphics
+ } // namespace Graphics
} // namespace JinEngine \ No newline at end of file