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.cpp46
1 files changed, 23 insertions, 23 deletions
diff --git a/src/libjin/Graphics/Texture.cpp b/src/libjin/Graphics/Texture.cpp
index 4c6707d..f3c08fb 100644
--- a/src/libjin/Graphics/Texture.cpp
+++ b/src/libjin/Graphics/Texture.cpp
@@ -57,46 +57,46 @@ namespace graphics
color Texture::getPixel(int x, int y)
{
- if (without(x, 0, width) || without(y, 0, height))
+ int w = size.x;
+ int h = size.y;
+ if (without(x, 0, w) || without(y, 0, h))
{
return { 0 };
}
- return pixels[x + y * width];
+ return pixels[x + y * w];
}
- bool Texture::loadb(const void* b, size_t size)
+ bool Texture::loadb(const void* b, size_t s)
{
// ʹstbi_load_from_memory
- unsigned char* textureData = stbi_load_from_memory((unsigned char *)b, size, &width, &height, NULL, STBI_rgb_alpha);
+ int w;
+ int h;
+ unsigned char* textureData = stbi_load_from_memory((unsigned char *)b, s, &w, &h, NULL, STBI_rgb_alpha);
if (textureData == 0) return false;
+ size.x = w;
+ size.y = h;
pixels = (color*)textureData;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, 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, width,
- height, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData);
- // set render vertices
- Drawable::setVertices(
- new float [DRAWABLE_V_SIZE] {
- 0, 0,
- 0, (float)height,
- (float)width, (float)height,
- (float)width, 0,
- },
- new float [DRAWABLE_V_SIZE] {
- 0, 0,
- 0, 1,
- 1, 1,
- 1, 0
- }
- );
+ vertCoord[0] = 0; vertCoord[1] = 1;
+ vertCoord[2] = 0; vertCoord[3] = h;
+ vertCoord[4] = w; vertCoord[5] = h;
+ vertCoord[6] = w; vertCoord[7] = 1;
+
+ textCoord[0] = 0; textCoord[1] = 0;
+ textCoord[2] = 0; textCoord[3] = 1;
+ textCoord[4] = 1; textCoord[5] = 1;
+ textCoord[6] = 1; textCoord[7] = 0;
return true;
}
-}
-}
+
+} // graphics
+} // jin
#endif // JIN_MODULES_RENDER \ No newline at end of file