aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/Graphics
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin/Graphics')
-rw-r--r--src/libjin/Graphics/Drawable.cpp206
-rw-r--r--src/libjin/Graphics/Drawable.h54
-rw-r--r--src/libjin/Graphics/Font/TextureFont.cpp6
-rw-r--r--src/libjin/Graphics/Image.cpp66
-rw-r--r--src/libjin/Graphics/Image.h50
-rw-r--r--src/libjin/Graphics/Particles/Particle.cpp0
-rw-r--r--src/libjin/Graphics/Particles/Particle.h0
-rw-r--r--src/libjin/Graphics/Sprite.h14
8 files changed, 197 insertions, 199 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
diff --git a/src/libjin/Graphics/Drawable.h b/src/libjin/Graphics/Drawable.h
index 0c4c3ef..29f1946 100644
--- a/src/libjin/Graphics/Drawable.h
+++ b/src/libjin/Graphics/Drawable.h
@@ -10,39 +10,39 @@
namespace jin
{
-namespace graphics
-{
-
- class Drawable
+ namespace graphics
{
- public:
- Drawable(int w = 0, int h = 0);
- Drawable(const Bitmap* bitmap);
- virtual ~Drawable();
- void setAnchor(int x, int y);
- void draw(int x, int y, float sx = 1, float sy = 1, float r = 0);
- void draw(const math::Quad& slice, int x, int y, float sx = 1, float sy = 1, float r = 0, float ax = 0, float ay = 0);
- inline int getWidth() const { return size.w; }
- inline int getHeight() const { return size.h; }
- inline GLuint getTexture() const { return texture; }
+ class Drawable
+ {
+ public:
+ Drawable(int w = 0, int h = 0);
+ Drawable(const Bitmap* bitmap);
+ virtual ~Drawable();
+
+ void setAnchor(int x, int y);
+ void draw(int x, int y, float sx = 1, float sy = 1, float r = 0);
+ void draw(const math::Quad& slice, int x, int y, float sx = 1, float sy = 1, float r = 0, float ax = 0, float ay = 0);
+ inline int getWidth() const { return size.w; }
+ inline int getHeight() const { return size.h; }
+ inline GLuint getTexture() const { return texture; }
- protected:
- static const int DRAWABLE_V_SIZE = 8;
+ protected:
+ static const int DRAWABLE_V_SIZE = 8;
- GLuint texture;
- GLuint vbo;
- /* TODO: vertex buffer object */
- /* GLuint vbo; */
- jin::math::Vector2<unsigned int> size;
- jin::math::Vector2<int> anchor;
- float vertex_coords[DRAWABLE_V_SIZE];
- float texture_coords[DRAWABLE_V_SIZE];
+ GLuint texture;
+ GLuint vbo;
+ /* TODO: vertex buffer object */
+ /* GLuint vbo; */
+ jin::math::Vector2<unsigned int> size;
+ jin::math::Vector2<int> anchor;
+ float vertex_coords[DRAWABLE_V_SIZE];
+ float texture_coords[DRAWABLE_V_SIZE];
- };
+ };
-} // render
-} // jin
+ } // namespace render
+} // namespace jin
#endif // LIBJIN_MODULES_RENDER
#endif // __LIBJIN_DRAWABLE \ No newline at end of file
diff --git a/src/libjin/Graphics/Font/TextureFont.cpp b/src/libjin/Graphics/Font/TextureFont.cpp
index 7ee1962..a1f2b27 100644
--- a/src/libjin/Graphics/Font/TextureFont.cpp
+++ b/src/libjin/Graphics/Font/TextureFont.cpp
@@ -70,8 +70,7 @@ namespace graphics
for (Codepoint c : text)
{
- if (c == 0x0D)
- continue;
+ if (c == 0x0D) continue;
if (c == 0x0A)
{
/* new line */
@@ -80,8 +79,7 @@ namespace graphics
continue;
}
glyph = findGlyph(c);
- if (glyph == nullptr)
- continue;
+ if (glyph == nullptr) continue;
if (texture != this->texture)
{
texture = this->texture;
diff --git a/src/libjin/Graphics/Image.cpp b/src/libjin/Graphics/Image.cpp
index 5700f60..358a144 100644
--- a/src/libjin/Graphics/Image.cpp
+++ b/src/libjin/Graphics/Image.cpp
@@ -4,42 +4,42 @@
namespace jin
{
-namespace graphics
-{
+ namespace graphics
+ {
- using namespace filesystem;
+ using namespace filesystem;
- /*static*/ Image* Image::createImage(const void* imgData, size_t size)
- {
- if (imgData == nullptr)
- return nullptr;
- int w, h;
- void* data = stbi_load_from_memory((unsigned char *)imgData, size, &w, &h, NULL, STBI_rgb_alpha);
- if (data == nullptr)
- return nullptr;
- Image* image = new Image();
- image->pixels = (Color*)data;
- image->width = w;
- image->height = h;
- return image;
- }
+ /*static*/ Image* Image::createImage(const void* imgData, size_t size)
+ {
+ if (imgData == nullptr)
+ return nullptr;
+ int w, h;
+ void* data = stbi_load_from_memory((unsigned char *)imgData, size, &w, &h, NULL, STBI_rgb_alpha);
+ if (data == nullptr)
+ return nullptr;
+ Image* image = new Image();
+ image->pixels = (Color*)data;
+ image->width = w;
+ image->height = h;
+ return image;
+ }
- Image* Image::createImage(const char* path)
- {
- Filesystem* fs = Filesystem::get();
- Buffer buffer;
- fs->read(path, &buffer);
- return createImage(buffer.data, buffer.size);
- }
+ Image* Image::createImage(const char* path)
+ {
+ Filesystem* fs = Filesystem::get();
+ Buffer buffer;
+ fs->read(path, &buffer);
+ return createImage(buffer.data, buffer.size);
+ }
- Image::Image()
- : Bitmap()
- {
- }
+ Image::Image()
+ : Bitmap()
+ {
+ }
- Image::~Image()
- {
- }
+ Image::~Image()
+ {
+ }
-}
-}
+ } // namespace graphics
+} // namespace jin
diff --git a/src/libjin/Graphics/Image.h b/src/libjin/Graphics/Image.h
index 215ac34..bed1986 100644
--- a/src/libjin/Graphics/Image.h
+++ b/src/libjin/Graphics/Image.h
@@ -5,31 +5,31 @@
namespace jin
{
-namespace graphics
-{
-
- /* just like bitmap but only from image file*/
- /* readonly bitmap */
- class Image : public Bitmap
- {
- public:
- static Image* createImage(const char* path);
- static Image* createImage(const void* imgData, size_t size);
- ~Image();
-
- private:
- Image();
-
- void bind(Color* pixels, int w, int h);
- void resetPixels(const Color* pixels, int w, int h);
- void resetPixels(const Color& pixels, int w, int h);
- void setPixel(const Color& pixel, int x, int y);
- void setPixels(Color pixels);
- void setPixels(Color* pixels);
-
- };
-
-}
+ namespace graphics
+ {
+
+ /* just like bitmap but only from image file*/
+ /* readonly bitmap */
+ class Image : public Bitmap
+ {
+ public:
+ static Image* createImage(const char* path);
+ static Image* createImage(const void* imgData, size_t size);
+ ~Image();
+
+ private:
+ Image();
+
+ void bind(Color* pixels, int w, int h);
+ void resetPixels(const Color* pixels, int w, int h);
+ void resetPixels(const Color& pixels, int w, int h);
+ void setPixel(const Color& pixel, int x, int y);
+ void setPixels(Color pixels);
+ void setPixels(Color* pixels);
+
+ };
+
+ }
}
#endif \ No newline at end of file
diff --git a/src/libjin/Graphics/Particles/Particle.cpp b/src/libjin/Graphics/Particles/Particle.cpp
deleted file mode 100644
index e69de29..0000000
--- a/src/libjin/Graphics/Particles/Particle.cpp
+++ /dev/null
diff --git a/src/libjin/Graphics/Particles/Particle.h b/src/libjin/Graphics/Particles/Particle.h
deleted file mode 100644
index e69de29..0000000
--- a/src/libjin/Graphics/Particles/Particle.h
+++ /dev/null
diff --git a/src/libjin/Graphics/Sprite.h b/src/libjin/Graphics/Sprite.h
index 0d73464..2c7e0f5 100644
--- a/src/libjin/Graphics/Sprite.h
+++ b/src/libjin/Graphics/Sprite.h
@@ -3,16 +3,16 @@
namespace jin
{
-namespace graphics
-{
+ namespace graphics
+ {
- /* just like texture but with x,y */
- class Sprite
- {
+ /* just like texture but with x,y */
+ class Sprite
+ {
- };
+ };
-}
+ }
}
#endif \ No newline at end of file