I've been attempting to rewrite my graphics engine recently to speed it up, but I'm running into the issue of my textures not binding.
This is my function for loading the image:
unsigned char * HVSTGFX::loadPNGFile(char *fileName, HVSTGFX::PNGFILE *pngfile, GLuint &texture)
{
FREE_IMAGE_FORMAT fif = FIF_PNG;
//pointer to the image, once loaded
FIBITMAP *dib(0);
//pointer to the image data
unsigned char* bits(0);
unsigned char tempRGB;
GLuint tempTex = 0;
if(FreeImage_FIFSupportsReading(fif))
dib = FreeImage_Load(fif, fileName);
if(!dib)
return NULL;
bits = FreeImage_GetBits(dib);
pngfile->width = FreeImage_GetWidth(dib); pngfile->height = FreeImage_GetHeight(dib);
pngfile->size = sizeof(bits);
int size = pngfile->width*pngfile->height;//(FreeImage_GetWidth(dib) * FreeImage_GetHeight(dib));
for (int imageIDx = 0; imageIDx < size * 4; imageIDx += 4)
{
tempRGB = bits[imageIDx];
bits[imageIDx] = bits[imageIDx + 2];
bits[imageIDx + 2] = tempRGB;
}
//FreeImage_Unload(dib);
glGenTextures(1, &tempTex);
glBindTexture(GL_TEXTURE_2D, tempTex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pngfile->width, pngfile->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, bits);
texture = tempTex;
return bits;
}
After watching it in debug mode, I've noticed that the GenTextures function isn't doing anything to tempTex, which is probably where the problem is. But, just to be sure, this is my function for actually drawing the sprite:
void HVSTGFX::createSpritePNGX(float width, float height, float x, float y, CSprite sprite)
{
glBindTexture(GL_TEXTURE_2D, sprite.texture);
glColor4f(1.0f,1.0f,1.0f, 1.0f );
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(x, y, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(x + width, y, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(x + width, y + height, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(x, y + height, 0.0f);
glEnd();
}
I've been digging around my textbooks and everywhere else on the internet, I just can't seem to find an answer as to why this isn't working.