aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/Render/Drawable.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-07-27 00:01:34 +0800
committerchai <chaifix@163.com>2018-07-27 00:01:34 +0800
commitb855ebb91ad8d97617ec1aa418b4add84670a07d (patch)
treeb11847a1879a2582c9cfd380074ad4c70f17a1a8 /src/libjin/Render/Drawable.cpp
parent1a882936e91826e4d69584745e16a79650272015 (diff)
*change name
Diffstat (limited to 'src/libjin/Render/Drawable.cpp')
-rw-r--r--src/libjin/Render/Drawable.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/libjin/Render/Drawable.cpp b/src/libjin/Render/Drawable.cpp
new file mode 100644
index 0000000..cbdf250
--- /dev/null
+++ b/src/libjin/Render/Drawable.cpp
@@ -0,0 +1,77 @@
+#include "../modules.h"
+#if JIN_MODULES_RENDER
+
+#include "drawable.h"
+#include "../math/matrix.h"
+#include <stdlib.h>
+
+namespace jin
+{
+namespace render
+{
+ Drawable::Drawable(int w, int h):texture(0), width(w), height(h), ancx(0), ancy(0), textCoord(0), vertCoord(0)
+ {
+ }
+
+ Drawable::~Drawable()
+ {
+ glDeleteTextures(1, &texture);
+ delete[] vertCoord;
+ delete[] textCoord;
+ }
+
+ void Drawable::setVertices(float* v, float* t)
+ {
+ // render area
+ if (vertCoord)
+ delete[] vertCoord;
+ vertCoord = v;
+
+ // textrue
+ if (textCoord)
+ delete[] textCoord;
+ textCoord = t;
+ }
+
+ void Drawable::setAnchor(int x, int y)
+ {
+ ancx = x;
+ ancy = y;
+ }
+
+ void Drawable::draw(int x, int y, float sx, float sy, float r)
+ {
+ // Must set textCoord and vertCoord before renderring
+ if (! textCoord||! vertCoord) return;
+
+ static jin::math::Matrix t;
+ t.setTransformation(x, y, r, sx, sy, ancx, ancy);
+
+ glEnable(GL_TEXTURE_2D);
+
+ glBindTexture(GL_TEXTURE_2D, texture);
+
+ // push modle matrix
+ glPushMatrix();
+ glMultMatrixf((const GLfloat*)t.getElements());
+
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ glTexCoordPointer(2, GL_FLOAT, 0, textCoord);
+ glVertexPointer(2, GL_FLOAT, 0, vertCoord);
+ glDrawArrays(GL_QUADS, 0, 4);
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+ glDisableClientState(GL_VERTEX_ARRAY);
+
+ // pop the model matrix
+ glPopMatrix();
+
+ // bind texture to default screen
+ glBindTexture(GL_TEXTURE_2D, 0);
+
+ glDisable(GL_TEXTURE_2D);
+ }
+}
+}
+
+#endif // JIN_MODULES_RENDER \ No newline at end of file