Texture Colors Not exact as Texture

Started by
17 comments, last by marcClintDion 12 years, 4 months ago

Ok fine I'm sorry for being grouchy. Thank you all for helping people fix their code. How's this look? //------------------------------------------------------------------------------------------------------------------------------------------------. void loadTexture(char *textureFileName, GLuint &textureMapID) { FREE_IMAGE_FORMAT fifmt = FreeImage_GetFileType(textureFileName, 0); FIBITMAP *dib = FreeImage_Load(fifmt, textureFileName,0); FIBITMAP *temp = dib; dib = FreeImage_ConvertTo32Bits(temp); FreeImage_Unload(temp); if( dib != NULL ) { glGenTextures( 1, &textureMapID ); glBindTexture( GL_TEXTURE_2D, textureMapID ); BYTE *pixels = (BYTE*)FreeImage_GetBits(dib); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT_ARB); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT_ARB); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); glTexParameteri( GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE ); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, FreeImage_GetWidth(dib), FreeImage_GetHeight(dib), 0, GL_BGRA, GL_UNSIGNED_BYTE, pixels); free(pixels); FreeImage_Unload(dib); } } //------------------------------------------------------------------------------------------------------------------------------------------------. Maybe now we are closer to having a proper image loader for people to make use of. The SGIS mip map generator appears to be hardware accelerated, almost twice as fast on a low end quadro, and about 1/3 faster on a budget intel graphics machine. Is a performance comparison like this inappropriate? Would it be considered bias or favoritism towards one or the other? I'm happy for both running faster now. There do not appear to be memory leaks. The dual core Intel with 2GB RAM and mobile 4 series graphics running on Win7 handled the loading of 100 1024x1024 images, then 200 1024x1024 images, then 300 1024x1024 images.

Consider it pure joy, my brothers and sisters, whenever you face trials of many kinds, 3 because you know that the testing of your faith produces perseverance. 4 Let perseverance finish its work so that you may be mature and complete, not lacking anything.

Advertisement
Maybe this is better for people who chance upon this topic.. I've chosen to comment out ---> //glGenerateMipmap(GL_TEXTURE_2D); because the documentation mentioned above gives the impression
that --->>>glGenerateMipmap(GL_TEXTURE_2D); is having some sort of version conflict nonsense. It is supported then not supported or some such nonsense. The --->>GL_GENERATE_MIPMAP_SGIS<<----works without adding extensions, seems to have no deprecation or version problems and offers a substantial performance boost on both nVidia as well as mobile Intel graphics(ATI, not tested yet) . Almost half the loading time for a mobile Quadro(NVS 130), and about 25% faster on budget mobile Intel(x4500).

I'm not sure if I've gotten things up to speed so far as all of the hints and tips provided goes, but things are at least, superficially, looking good. Two hundred and forty 1024 x 1024 textures loaded simultaneously without crashing either machine seems workable to me.

//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//FreeImage_Save(FIF_JPEG, dib, "mybitmap.jpg", JPEG_QUALITYSUPERB);

void loadTexture(char *textureFileName, GLuint &textureMapID)
{
FREE_IMAGE_FORMAT fifmt = FreeImage_GetFileType(textureFileName, 0);

FIBITMAP *dib = FreeImage_Load(fifmt, textureFileName,0);

FIBITMAP *temp = dib;
dib = FreeImage_ConvertTo32Bits(temp);
FreeImage_Unload(temp);

if( dib != NULL )
{
glGenTextures( 1, &textureMapID );
glBindTexture( GL_TEXTURE_2D, textureMapID );

BYTE *pixels = (BYTE*)FreeImage_GetBits(dib);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT_ARB);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT_ARB);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri( GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE );
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, FreeImage_GetWidth(dib), FreeImage_GetHeight(dib), 0, GL_BGRA, GL_UNSIGNED_BYTE, pixels);
//glGenerateMipmap(GL_TEXTURE_2D);

free(pixels);
FreeImage_Unload(dib);

}

}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Consider it pure joy, my brothers and sisters, whenever you face trials of many kinds, 3 because you know that the testing of your faith produces perseverance. 4 Let perseverance finish its work so that you may be mature and complete, not lacking anything.

This topic is closed to new replies.

Advertisement