diff --git a/src/Font.cpp b/src/Font.cpp index 11f125f66..9e160d214 100644 --- a/src/Font.cpp +++ b/src/Font.cpp @@ -168,6 +168,7 @@ void Font::drawText(std::string text, int startx, int starty, int color) int pointCount = text.length() * 2; point* points = new point[pointCount]; tex* texs = new tex[pointCount]; + GLubyte* colors = new GLubyte[pointCount * 3 * 4]; 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; } - GLubyte* colors = new GLubyte[pointCount * 3 * 4]; Renderer::buildGLColorArray(colors, color, pointCount * 3); 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_BLEND); - //not sure if this properly deletes or not delete[] points; + delete[] texs; + delete[] colors; } void Font::sizeText(std::string text, int* w, int* h) diff --git a/src/Renderer_init_rpi.cpp b/src/Renderer_init_rpi.cpp index 6ecf3534c..d33eb5b44 100644 --- a/src/Renderer_init_rpi.cpp +++ b/src/Renderer_init_rpi.cpp @@ -163,7 +163,7 @@ namespace Renderer glViewport(0, 0, 1680, 1050); 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; } diff --git a/src/components/GuiImage.cpp b/src/components/GuiImage.cpp index 36e5310f7..baa152697 100644 --- a/src/components/GuiImage.cpp +++ b/src/components/GuiImage.cpp @@ -3,7 +3,7 @@ #include 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) { @@ -79,6 +79,11 @@ void GuiImage::loadImage(std::string path) return; } + //convert to 32bit + FIBITMAP* imgConv = FreeImage_ConvertTo32Bits(image); + FreeImage_Unload(image); + image = imgConv; + imageData = FreeImage_GetBits(image); if(!imageData) { @@ -97,13 +102,29 @@ void GuiImage::loadImage(std::string path) 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 - width = 512; height = 512; + //width = 512; height = 512; //now for the openGL texture stuff glGenTextures(1, &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; mHeight = height; @@ -111,6 +132,9 @@ void GuiImage::loadImage(std::string path) //free the image data FreeImage_Unload(image); + //free the memory from that pointer + delete[] imageRGBA; + 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; GLfloat texs[12]; - texs[0] = 0; texs[1] = 0; - texs[2] = 0; texs[3] = 1; - texs[4] = 1; texs[5] = 0; + texs[0] = 0; texs[1] = 1; + texs[2] = 0; texs[3] = 0; + texs[4] = 1; texs[5] = 1; - texs[6] = 1; texs[7] = 0; - texs[8] = 0; texs[9] = 1; - texs[10] = 1; texs[11] = 1; + texs[6] = 1; texs[7] = 1; + texs[8] = 0; texs[9] = 0; + texs[10] = 1; texs[11] = 0;