aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/Graphics/Texture.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin/Graphics/Texture.cpp')
-rw-r--r--src/libjin/Graphics/Texture.cpp40
1 files changed, 14 insertions, 26 deletions
diff --git a/src/libjin/Graphics/Texture.cpp b/src/libjin/Graphics/Texture.cpp
index 9958935..5a39f77 100644
--- a/src/libjin/Graphics/Texture.cpp
+++ b/src/libjin/Graphics/Texture.cpp
@@ -1,4 +1,4 @@
-#include "../modules.h"
+#include "../jin_configuration.h"
#if LIBJIN_MODULES_RENDER
#include <fstream>
@@ -15,35 +15,23 @@ namespace graphics
/*static*/ Texture* Texture::createTexture(Bitmap* bitmap)
{
- Texture* tex = new Texture();
- const Color* pixels = bitmap->getPixels();
- tex->size.w = bitmap->getWidth();
- tex->size.h = bitmap->getHeight();
- unsigned int w = tex->size.w;
- unsigned int h = tex->size.h;
-
- glGenTextures(1, &tex->texture);
- glBindTexture(GL_TEXTURE_2D, tex->texture);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
-
- tex->vertCoord[0] = 0; tex->vertCoord[1] = 1;
- tex->vertCoord[2] = 0; tex->vertCoord[3] = h;
- tex->vertCoord[4] = w; tex->vertCoord[5] = h;
- tex->vertCoord[6] = w; tex->vertCoord[7] = 1;
-
- tex->textCoord[0] = 0; tex->textCoord[1] = 0;
- tex->textCoord[2] = 0; tex->textCoord[3] = 1;
- tex->textCoord[4] = 1; tex->textCoord[5] = 1;
- tex->textCoord[6] = 1; tex->textCoord[7] = 0;
-
+ Texture* tex = new Texture(bitmap);
return tex;
}
- Texture::Texture()
- : Drawable()
+ Texture::Texture(const Bitmap* bitmap)
+ : Drawable(bitmap->getWidth(), bitmap->getHeight())
{
+ unsigned int w = size.w;
+ unsigned int h = size.h;
+ 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);
}
Texture::~Texture()