libpng loading junk at bottom of my OpenGL textures...? - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: libpng loading junk at bottom of my OpenGL textures...? (/thread-3343.html)
libpng loading junk at bottom of my OpenGL textures...? - BinarySpike - Apr 18, 2007 07:22 PM
I am a bit rusty with OpenGL, but I know my code is fine, but the code I found on these forums by OneSadCookie is loading the texture weird.
First the png image I am trying to load and display is a 24 bit png, no alpha. I converted a gif checkerboard that was 512x512 off the internet.
(this is only a test, I fully understand licenses of code and images)
Here's a pic...
And for everyones information I'm using GLFW to setup my context, meaning it's cross-platform.
I don't know if it's the PNG header, or what that's at the bottom of that picture, but the texture is 512x512, a 128x128 is like half the image is just that garbled stuff.
the code I used..
I added a texName to Image class, and removed the whole static Image return junk in load_png_image in favor of references.
Here's *my* code:
*EDIT* THIS CODE IS INVALID, IT WILL NOT LOAD YOUR IMAGES PROPERLY
use the code from my very last post
libpng loading junk at bottom of my OpenGL textures...? - OneSadCookie - Apr 18, 2007 07:54 PM
Well, the png code works fine for me, so there are three obvious places to look for problems:
1) your modifications to my png code
2) a corrupt PNG image
3) a miscompiled libpng
To check 1), you could take one of my programs that uses the code -- http://onesadcookie.com/~keith/Mechanical.tar.bz2 for example -- and see if it works when you replace one of my images with yours.
To check 2), you could load it up in Preview, GIMP, etc. and see if any of them complain about it and/or load it correctly. I'm pretty sure GIMP will be using libpng, so if it works for GIMP, there's definitely something odd going on.
3) would be trickier to check -- if it comes with automated tests, you can run those, otherwise you can stick your own dynamic libpng into the library load path for a program like GIMP which normally dynamically links to another libpng, and check that it still works.
libpng loading junk at bottom of my OpenGL textures...? - BinarySpike - Apr 18, 2007 08:39 PM
Ok I tried pngtest.c which comes with libpng as a testing program.
The texture.png loaded but the output was different, meaning something is wrong. It also says that Libpng passes.
I can't really see two images failing, unless my converter is bad.
I'll go download GIMP and convert with that.
I only changed the way your function passes back the data. Instead of a static return it uses a reference. The rest was kept the same.
libpng loading junk at bottom of my OpenGL textures...? - BinarySpike - Apr 18, 2007 09:19 PM
Ok, Just something, but could it be that zlib and libpng don't have the same byte alignment?
After opening my png files in pngtest the pngout.png is smaller in size (like by 200 bytes)
I created a new image in GIMP, and it seems that the image is being stretched to the left as well as junk showing up on the bottom.
Updated Image Link
Note, the picture is supposed to be a perfect 512 by 512, with the arrow in the center.
libpng loading junk at bottom of my OpenGL textures...? - BinarySpike - Apr 18, 2007 09:38 PM
I did a clean compile of zlib and libpng. Same results as last post (the picture)
Although it did clean my project up some. I'm going to redo my libpng code by hand. Instead of copy-paste it.
I have piano guild this weekend so I'm turning in tonight.
libpng loading junk at bottom of my OpenGL textures...? - BinarySpike - Apr 18, 2007 09:57 PM
Ok so I didn't goto sleep like I should have...
But I fixed it!
I changed your function back to the way it was, OneSadCookie, and then did this here...
Now that's C mixed with C++, very bad programming style, but it worked. So I am gonna move everything to a nice class (loading, binding, etc. etc.)
I guess it had to do something with the reference. Actually I know very little about references or static returns.
libpng loading junk at bottom of my OpenGL textures...? - BinarySpike - Apr 19, 2007 12:20 PM
Ok, so I found the problem, I don't know why it even showed some of the picture. But it was the last parameter in glTexImage2D (the data parameter)
I was passing &image.data which was handle, not a pointer.
So here's the code in it's final form.