diff options
Diffstat (limited to 'src/libjin/Graphics/je_gl.cpp')
-rw-r--r-- | src/libjin/Graphics/je_gl.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/libjin/Graphics/je_gl.cpp b/src/libjin/Graphics/je_gl.cpp index f72ce37..3f19d36 100644 --- a/src/libjin/Graphics/je_gl.cpp +++ b/src/libjin/Graphics/je_gl.cpp @@ -2,6 +2,8 @@ #include "je_gl.h" #include "je_color.h" +using namespace JinEngine::Math; + namespace JinEngine { namespace Graphics @@ -9,6 +11,13 @@ namespace JinEngine OpenGL gl; + OpenGL::OpenGL() + : ogl2d::OpenGL() + { + mMatrices.push_back(Matrix()); + calcMatrix(); + } + void OpenGL::setColor(Channel r, Channel g, Channel b, Channel a) { setColor(Color(r, g, b, a)); @@ -25,6 +34,59 @@ namespace JinEngine return mCurrentColor; } + void OpenGL::clearMatrix() + { + mMatrices.clear(); + mMatrices.push_back(Matrix()); + mMatrix.setIdentity(); + } + + void OpenGL::push() + { + mMatrices.push_back(Matrix()); + } + + void OpenGL::pop() + { + if (mMatrices.size() == 1) + return; + mMatrices.pop_back(); + calcMatrix(); + } + + void OpenGL::calcMatrix() + { + mMatrix.setIdentity(); + for (Matrix& m : mMatrices) + mMatrix *= m; + } + + void OpenGL::translate(float x, float y) + { + if (mMatrices.size() == 1) + return; + Matrix& m = mMatrices.back(); + m.translate(x, y); + mMatrix.translate(x, y); + } + + void OpenGL::scale(float sx, float sy) + { + if (mMatrices.size() == 1) + return; + Matrix& m = mMatrices.back(); + m.scale(sx, sy); + mMatrix.scale(sx, sy); + } + + void OpenGL::rotate(float r) + { + if (mMatrices.size() == 1) + return; + Matrix& m = mMatrices.back(); + m.rotate(r); + mMatrix.rotate(r); + } } // namespace Graphics } // namespace JinEngine |