aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/Graphics/je_gl.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-11-15 21:44:02 +0800
committerchai <chaifix@163.com>2018-11-15 21:44:02 +0800
commite654344bc262c8393559e5cd535f440133fb2406 (patch)
tree7ac96581726c7d81599d72fdd811b5d991e2e362 /src/libjin/Graphics/je_gl.cpp
parent7e51ff3bfae0becc260452a427a1fc1232a4b348 (diff)
*渲染矩阵
Diffstat (limited to 'src/libjin/Graphics/je_gl.cpp')
-rw-r--r--src/libjin/Graphics/je_gl.cpp62
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