Move po2ifying to Image, Quads broken at the moment

This commit is contained in:
Bart van Strien
2011-05-15 23:31:12 +02:00
parent 2e9e5a1502
commit 360c190ef7
3 changed files with 28 additions and 23 deletions
+21 -1
View File
@@ -284,13 +284,33 @@ namespace opengl
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
float p2width = next_p2(width);
float p2height = next_p2(height);
float t = width/p2width;
float s = height/p2height;
vertices[1].t = t;
vertices[2].t = t;
vertices[2].s = s;
vertices[3].s = s;
glTexImage2D(GL_TEXTURE_2D, glTexImage2D(GL_TEXTURE_2D,
0, 0,
GL_RGBA8, GL_RGBA8,
(GLsizei)p2width,
(GLsizei)p2height,
0,
GL_RGBA,
GL_UNSIGNED_BYTE,
0);
glTexSubImage2D(GL_TEXTURE_2D,
0,
0,
0,
(GLsizei)width, (GLsizei)width,
(GLsizei)height, (GLsizei)height,
0,
GL_RGBA, GL_RGBA,
GL_UNSIGNED_BYTE, GL_UNSIGNED_BYTE,
data->getData()); data->getData());
+5 -20
View File
@@ -35,7 +35,7 @@ namespace image
{ {
namespace devil namespace devil
{ {
void ImageData::createPo2(int width, int height, void * data) void ImageData::create(int width, int height, void * data)
{ {
//create the image //create the image
ilGenImages(1, &image); ilGenImages(1, &image);
@@ -43,10 +43,6 @@ namespace devil
//bind it //bind it
ilBindImage(image); ilBindImage(image);
//scale to nearest bigger po2
width = next_p2(width);
height = next_p2(height);
//create and populate the image //create and populate the image
bool success = (ilTexImage(width, height, 1, bpp, IL_RGBA, IL_UNSIGNED_BYTE, data) == IL_TRUE); bool success = (ilTexImage(width, height, 1, bpp, IL_RGBA, IL_UNSIGNED_BYTE, data) == IL_TRUE);
@@ -74,15 +70,11 @@ namespace devil
void ImageData::load(Data * data) void ImageData::load(Data * data)
{ {
// Create a temporary image to store
// the decoded image in.
ILuint tempimage;
// Generate DevIL image. // Generate DevIL image.
ilGenImages(1, &tempimage); ilGenImages(1, &image);
// Bind the image. // Bind the image.
ilBindImage(tempimage); ilBindImage(image);
// Try to load the image. // Try to load the image.
ILboolean success = ilLoadL(IL_TYPE_UNKNOWN, (void*)data->getData(), data->getSize()); ILboolean success = ilLoadL(IL_TYPE_UNKNOWN, (void*)data->getData(), data->getSize());
@@ -90,7 +82,6 @@ namespace devil
// Check for errors // Check for errors
if(!success) if(!success)
{ {
ilDeleteImages(1, &tempimage);
throw love::Exception("Could not decode image!"); throw love::Exception("Could not decode image!");
return; return;
} }
@@ -107,15 +98,9 @@ namespace devil
if(bpp != 4) if(bpp != 4)
{ {
ilDeleteImages(1, &tempimage);
std::cerr << "Bits per pixel != 4" << std::endl; std::cerr << "Bits per pixel != 4" << std::endl;
return; return;
} }
// Create a new, PO2, image based on it
createPo2(width, height, ilGetData());
// Delete the temporary image.
ilDeleteImages(1, &tempimage);
} }
ImageData::ImageData(Data * data) ImageData::ImageData(Data * data)
@@ -133,7 +118,7 @@ namespace devil
ImageData::ImageData(int width, int height) ImageData::ImageData(int width, int height)
: width(width), height(height), origin(IL_ORIGIN_UPPER_LEFT), bpp(4) : width(width), height(height), origin(IL_ORIGIN_UPPER_LEFT), bpp(4)
{ {
createPo2(width, height); create(width, height);
// Set to black. // Set to black.
memset((void*)ilGetData(), 0, width*height*4); memset((void*)ilGetData(), 0, width*height*4);
@@ -142,7 +127,7 @@ namespace devil
ImageData::ImageData(int width, int height, void *data) ImageData::ImageData(int width, int height, void *data)
: width(width), height(height), origin(IL_ORIGIN_UPPER_LEFT), bpp(4) : width(width), height(height), origin(IL_ORIGIN_UPPER_LEFT), bpp(4)
{ {
createPo2(width, height, data); create(width, height, data);
} }
ImageData::~ImageData() ImageData::~ImageData()
+2 -2
View File
@@ -53,8 +53,8 @@ namespace devil
// DevIL image identifier. // DevIL image identifier.
ILuint image; ILuint image;
// Create PO2 imagedata. // Create imagedata.
void createPo2(int width, int height, void * data = 0); void create(int width, int height, void * data = 0);
void load(Data * data); void load(Data * data);