aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/Graphics/Drawable.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin/Graphics/Drawable.cpp')
-rw-r--r--src/libjin/Graphics/Drawable.cpp206
1 files changed, 103 insertions, 103 deletions
diff --git a/src/libjin/Graphics/Drawable.cpp b/src/libjin/Graphics/Drawable.cpp
index 4be1cc2..b9a0b36 100644
--- a/src/libjin/Graphics/Drawable.cpp
+++ b/src/libjin/Graphics/Drawable.cpp
@@ -8,111 +8,111 @@
namespace jin
{
-namespace graphics
-{
-
- Drawable::Drawable(int w, int h)
- : texture(0)
- , size(w, h)
- , anchor(0, 0)
- {
- vertex_coords[0] = 0; vertex_coords[1] = 0;
- vertex_coords[2] = 0; vertex_coords[3] = h;
- vertex_coords[4] = w; vertex_coords[5] = h;
- vertex_coords[6] = w; vertex_coords[7] = 0;
-
- texture_coords[0] = 0; texture_coords[1] = 0;
- texture_coords[2] = 0; texture_coords[3] = 1;
- texture_coords[4] = 1; texture_coords[5] = 1;
- texture_coords[6] = 1; texture_coords[7] = 0;
- }
-
- Drawable::Drawable(const Bitmap* bitmap)
- : texture(0)
- , anchor(0, 0)
- {
- unsigned int w = size.w = bitmap->getWidth();
- unsigned int h = size.h = bitmap->getHeight();
-
- vertex_coords[0] = 0; vertex_coords[1] = 0;
- vertex_coords[2] = 0; vertex_coords[3] = h;
- vertex_coords[4] = w; vertex_coords[5] = h;
- vertex_coords[6] = w; vertex_coords[7] = 0;
-
- texture_coords[0] = 0; texture_coords[1] = 0;
- texture_coords[2] = 0; texture_coords[3] = 1;
- texture_coords[4] = 1; texture_coords[5] = 1;
- texture_coords[6] = 1; texture_coords[7] = 0;
-
- const Color* pixels = bitmap->getPixels();
-
- texture = gl.genTexture();
- gl.bindTexture(texture);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- gl.texImage(GL_RGBA8, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
- gl.bindTexture(0);
- }
-
- Drawable::~Drawable()
- {
- glDeleteTextures(1, &texture);
- }
-
- void Drawable::setAnchor(int x, int y)
+ namespace graphics
{
- anchor.x = x;
- anchor.y = y;
- }
- void Drawable::draw(int x, int y, float sx, float sy, float r)
- {
- gl.ModelMatrix.setTransformation(x, y, r, sx, sy, anchor.x, anchor.y);
-
- Shader* shader = Shader::getCurrentShader();
- shader->sendMatrix4(SHADER_MODEL_MATRIX, &gl.ModelMatrix);
- shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.ProjectionMatrix);
- shader->bindVertexPointer(2, GL_FLOAT, 0, vertex_coords);
- shader->bindUVPointer(2, GL_FLOAT, 0, texture_coords);
-
- gl.bindTexture(texture);
- gl.drawArrays(GL_QUADS, 0, 4);
- gl.bindTexture(0);
- }
-
- void Drawable::draw(const math::Quad& slice, int x, int y, float sx, float sy, float r, float ax, float ay)
- {
- float vertCoords[8] = {
- 0, 0,
- 0, slice.h,
- slice.w, slice.h,
- slice.w, 0
- };
- float slx = slice.x / size.w;
- float sly = slice.y / size.h;
- float slw = slice.w / size.w;
- float slh = slice.h / size.h;
- float texCoords[8] = {
- slx, sly,
- slx, sly + slh,
- slx + slw, sly + slh,
- slx + slw, sly
- };
-
- gl.ModelMatrix.setTransformation(x, y, r, sx, sy, ax, ay);
-
- Shader* shader = Shader::getCurrentShader();
- shader->sendMatrix4(SHADER_MODEL_MATRIX, &gl.ModelMatrix);
- shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.ProjectionMatrix);
- shader->bindVertexPointer(2, GL_FLOAT, 0, vertCoords);
- shader->bindUVPointer(2, GL_FLOAT, 0, texCoords);
-
- gl.bindTexture(texture);
- gl.drawArrays(GL_QUADS, 0, 4);
- gl.bindTexture(0);
- }
-
-} // render
+ Drawable::Drawable(int w, int h)
+ : texture(0)
+ , size(w, h)
+ , anchor(0, 0)
+ {
+ vertex_coords[0] = 0; vertex_coords[1] = 0;
+ vertex_coords[2] = 0; vertex_coords[3] = h;
+ vertex_coords[4] = w; vertex_coords[5] = h;
+ vertex_coords[6] = w; vertex_coords[7] = 0;
+
+ texture_coords[0] = 0; texture_coords[1] = 0;
+ texture_coords[2] = 0; texture_coords[3] = 1;
+ texture_coords[4] = 1; texture_coords[5] = 1;
+ texture_coords[6] = 1; texture_coords[7] = 0;
+ }
+
+ Drawable::Drawable(const Bitmap* bitmap)
+ : texture(0)
+ , anchor(0, 0)
+ {
+ unsigned int w = size.w = bitmap->getWidth();
+ unsigned int h = size.h = bitmap->getHeight();
+
+ vertex_coords[0] = 0; vertex_coords[1] = 0;
+ vertex_coords[2] = 0; vertex_coords[3] = h;
+ vertex_coords[4] = w; vertex_coords[5] = h;
+ vertex_coords[6] = w; vertex_coords[7] = 0;
+
+ texture_coords[0] = 0; texture_coords[1] = 0;
+ texture_coords[2] = 0; texture_coords[3] = 1;
+ texture_coords[4] = 1; texture_coords[5] = 1;
+ texture_coords[6] = 1; texture_coords[7] = 0;
+
+ const Color* pixels = bitmap->getPixels();
+
+ texture = gl.genTexture();
+ gl.bindTexture(texture);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ gl.texImage(GL_RGBA8, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
+ gl.bindTexture(0);
+ }
+
+ Drawable::~Drawable()
+ {
+ glDeleteTextures(1, &texture);
+ }
+
+ void Drawable::setAnchor(int x, int y)
+ {
+ anchor.x = x;
+ anchor.y = y;
+ }
+
+ void Drawable::draw(int x, int y, float sx, float sy, float r)
+ {
+ gl.ModelMatrix.setTransformation(x, y, r, sx, sy, anchor.x, anchor.y);
+
+ Shader* shader = Shader::getCurrentShader();
+ shader->sendMatrix4(SHADER_MODEL_MATRIX, &gl.ModelMatrix);
+ shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.ProjectionMatrix);
+ shader->bindVertexPointer(2, GL_FLOAT, 0, vertex_coords);
+ shader->bindUVPointer(2, GL_FLOAT, 0, texture_coords);
+
+ gl.bindTexture(texture);
+ gl.drawArrays(GL_QUADS, 0, 4);
+ gl.bindTexture(0);
+ }
+
+ void Drawable::draw(const math::Quad& slice, int x, int y, float sx, float sy, float r, float ax, float ay)
+ {
+ float vertCoords[8] = {
+ 0, 0,
+ 0, slice.h,
+ slice.w, slice.h,
+ slice.w, 0
+ };
+ float slx = slice.x / size.w;
+ float sly = slice.y / size.h;
+ float slw = slice.w / size.w;
+ float slh = slice.h / size.h;
+ float texCoords[8] = {
+ slx, sly,
+ slx, sly + slh,
+ slx + slw, sly + slh,
+ slx + slw, sly
+ };
+
+ gl.ModelMatrix.setTransformation(x, y, r, sx, sy, ax, ay);
+
+ Shader* shader = Shader::getCurrentShader();
+ shader->sendMatrix4(SHADER_MODEL_MATRIX, &gl.ModelMatrix);
+ shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.ProjectionMatrix);
+ shader->bindVertexPointer(2, GL_FLOAT, 0, vertCoords);
+ shader->bindUVPointer(2, GL_FLOAT, 0, texCoords);
+
+ gl.bindTexture(texture);
+ gl.drawArrays(GL_QUADS, 0, 4);
+ gl.bindTexture(0);
+ }
+
+ } // render
} // jin
#endif // LIBJIN_MODULES_RENDER \ No newline at end of file