Jump to content
  • Advertisement
Sign in to follow this  
neo187

OpenGL Transparent bitmaps help - lodePNG/SOIL problem

This topic is 2588 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,

I am working on a 3D game, I'd like to overlay the 3D scene with some GUI elements with transparency... The engine I am working with has got loaders for TGA and BMP files, my first guess was to try incorporate PNG in it. I am trying to use lodePNG, which any recomment. I included lodepng.h to the header files and lodepng.c to the source files. I included the header in my class and created this function froma sample I saw:



GLuint GLTexture::LoadPNG(char* filename){
unsigned char* buffer;
unsigned char* image;
size_t buffersize, imagesize;
GLuint texName;
LodePNG_Decoder decoder;

LodePNG_loadFile(&buffer, &buffersize, filename);
LodePNG_Decoder_init(&decoder);
decoder.infoRaw.color.colorType = 6; /* Load image as RGBA */
LodePNG_decode(&decoder, &image, &imagesize, buffer, buffersize);
if(decoder.error) {
printf("Error reading in png image: %d\n", decoder.error);
exit(1);
} else {
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glGenTextures(1,&texture[0]);
glBindTexture(GL_TEXTURE_2D,texture[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,decoder.infoPng.width,
decoder.infoPng.height,0, GL_RGBA,GL_UNSIGNED_BYTE,image);
}
return texName;
}


But when I compile I get a bunch of unresolved symbol errors:

lodepng Error 1 error LNK2019: unresolved external symbol "void __cdecl LodePNG_decode
...

And many other references to functions....

I tried with SOIL (Simple Opengl Image Library) too, where I included the libSOIL.a file and the SOIL.h file to my project, still a bunch of unresolved simbols when compiling...

I am not sure what I am doing wrong.... But I don't necessarily need to read PNG, all I need is a quick and easy way to render 2D sprites with transparency...

Could anyone help with this?

Thank you!

Share this post


Link to post
Share on other sites
Advertisement
Hidden
Hello,

First of all, I think it is easier with the following code by using LodePNG_decode32_file which does everything (loading file, decoding, using RGBA format) at once. Also note the "free" at the end, otherwise you'll have a memory leak, the complete memory of the texture will remain in RAM for nothing. OpenGL makes a copy of this data, the original one can be freed.


GLuint GLTexture::LoadPNG(char* filename){
unsigned char* image;
unsigned w, h;
unsigned error;
GLuint texName;
error = LodePNG_decode32_file(&image, &w, &h, filename);
if(error) {
printf("Error reading in png image: %d\n", error);
exit(1);
} else {
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glGenTextures(1,&texture[0]);
glBindTexture(GL_TEXTURE_2D,texture[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,w,
h,0, GL_RGBA,GL_UNSIGNED_BYTE,image);
}
free(image);
return texName;
}


If you're working in C++, you can also use the C++ version of LodePNG.

If you include all source files, normally it should be able to link. What happens if you use the code above? Probably the sample was for an older version of LodePNG. Does your project already exist out of multiple source files, is using functions from other source files possible, and are there differences in settings related to this file in your IDE? Does your IDE support mixing C and C++ code? Try renaming lodepng.c into lodepng.cpp?

Share this post


Link to post
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!