Image loading working.

Still doesn't resize, tile, or render with alpha (though it loads it).
This commit is contained in:
Aloshi 2012-08-29 14:22:05 -05:00
parent 0314a14849
commit cdb63c4a4f
3 changed files with 37 additions and 12 deletions

View file

@ -168,6 +168,7 @@ void Font::drawText(std::string text, int startx, int starty, int color)
int pointCount = text.length() * 2; int pointCount = text.length() * 2;
point* points = new point[pointCount]; point* points = new point[pointCount];
tex* texs = new tex[pointCount]; tex* texs = new tex[pointCount];
GLubyte* colors = new GLubyte[pointCount * 3 * 4];
glBindTexture(GL_TEXTURE_2D, textureID); glBindTexture(GL_TEXTURE_2D, textureID);
@ -215,7 +216,6 @@ void Font::drawText(std::string text, int startx, int starty, int color)
x += charData[letter].advX; x += charData[letter].advX;
} }
GLubyte* colors = new GLubyte[pointCount * 3 * 4];
Renderer::buildGLColorArray(colors, color, pointCount * 3); Renderer::buildGLColorArray(colors, color, pointCount * 3);
glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_VERTEX_ARRAY);
@ -235,8 +235,9 @@ void Font::drawText(std::string text, int startx, int starty, int color)
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND); glDisable(GL_BLEND);
//not sure if this properly deletes or not
delete[] points; delete[] points;
delete[] texs;
delete[] colors;
} }
void Font::sizeText(std::string text, int* w, int* h) void Font::sizeText(std::string text, int* w, int* h)

View file

@ -163,7 +163,7 @@ namespace Renderer
glViewport(0, 0, 1680, 1050); glViewport(0, 0, 1680, 1050);
glOrthof(0, 1680, 1050, 0, -1.0, 1.0); glOrthof(0, 1680, 1050, 0, -1.0, 1.0);
glClearColor(0.5f, 1.0f, 1.0f, 1.0f); glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
return true; return true;
} }

View file

@ -3,7 +3,7 @@
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
int GuiImage::getWidth() { return mWidth; } int GuiImage::getWidth() { return mWidth; }
int GuiImage::getHeight() { return 100; } int GuiImage::getHeight() { return mHeight; }
GuiImage::GuiImage(int offsetX, int offsetY, std::string path, unsigned int maxWidth, unsigned int maxHeight, bool resizeExact) GuiImage::GuiImage(int offsetX, int offsetY, std::string path, unsigned int maxWidth, unsigned int maxHeight, bool resizeExact)
{ {
@ -79,6 +79,11 @@ void GuiImage::loadImage(std::string path)
return; return;
} }
//convert to 32bit
FIBITMAP* imgConv = FreeImage_ConvertTo32Bits(image);
FreeImage_Unload(image);
image = imgConv;
imageData = FreeImage_GetBits(image); imageData = FreeImage_GetBits(image);
if(!imageData) if(!imageData)
{ {
@ -97,13 +102,29 @@ void GuiImage::loadImage(std::string path)
return; return;
} }
//convert from BGRA to RGBA
GLubyte* imageRGBA = new GLubyte[4*width*height];
for(unsigned int i = 0; i < width*height; i++)
{
imageRGBA[i*4+0] = imageData[i*4+2];
imageRGBA[i*4+1] = imageData[i*4+1];
imageRGBA[i*4+2] = imageData[i*4+0];
imageRGBA[i*4+3] = imageData[i*4+3];
}
//force power of two for testing //force power of two for testing
width = 512; height = 512; //width = 512; height = 512;
//now for the openGL texture stuff //now for the openGL texture stuff
glGenTextures(1, &mTextureID); glGenTextures(1, &mTextureID);
glBindTexture(GL_TEXTURE_2D, mTextureID); glBindTexture(GL_TEXTURE_2D, mTextureID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, imageData);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageRGBA);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
mWidth = width; mWidth = width;
mHeight = height; mHeight = height;
@ -111,6 +132,9 @@ void GuiImage::loadImage(std::string path)
//free the image data //free the image data
FreeImage_Unload(image); FreeImage_Unload(image);
//free the memory from that pointer
delete[] imageRGBA;
std::cout << "Image load successful, w: " << mWidth << " h: " << mHeight << " texID: " << mTextureID << "\n"; std::cout << "Image load successful, w: " << mWidth << " h: " << mHeight << " texID: " << mTextureID << "\n";
} }
@ -178,13 +202,13 @@ void GuiImage::onRender()
//std::cout << "(w: " << mWidth << " h: " << mHeight << ")" << std::endl; //std::cout << "(w: " << mWidth << " h: " << mHeight << ")" << std::endl;
GLfloat texs[12]; GLfloat texs[12];
texs[0] = 0; texs[1] = 0; texs[0] = 0; texs[1] = 1;
texs[2] = 0; texs[3] = 1; texs[2] = 0; texs[3] = 0;
texs[4] = 1; texs[5] = 0; texs[4] = 1; texs[5] = 1;
texs[6] = 1; texs[7] = 0; texs[6] = 1; texs[7] = 1;
texs[8] = 0; texs[9] = 1; texs[8] = 0; texs[9] = 0;
texs[10] = 1; texs[11] = 1; texs[10] = 1; texs[11] = 0;