PDA

View Full Version : libpng.so and reading .png images



PompeyBlue
11th August 2004, 03:26 PM
Ok,

This is mega specialist, so I won't expect any replies, but I'll ask anyway :p

So if I use KPaint and examine a .png image it reports it's stats as:

128x128 24bpp

However, if I then use libpng.so to load this (using the sample code) and then look at the header (info_ptr) it reports:

width: 128 (fine)
height: 128 (fine)
rowbytes: 384 (fine i.e. 128 * 3 = 384)
bit_depth: 8 (what ? I thought it was 24bpp or 3 bytes)
valid: 32768 (I presume this is unpacked size which seems to small since 128 * 3 * 128 = 49152)

Has anybody used this before ? Maybe the .png I'm reading is fine, it's just when I try and texture with it using opengl it's colours are all washed out and it's at 45 degrees.

PompeyBlue
11th August 2004, 04:39 PM
I had presumed that the PNG was read into linear memory, it appears it is not. You must index into the row_pointer that you get given back, and build up the linear version ready for use.

Top, OpenGL texture mapping up and running, reading PNG's

I just need to write the rest of the game code now *gulp*

Bana
12th August 2004, 05:58 AM
bit_depth: 8 (what ? I thought it was 24bpp or 3 bytes)As far as I remember it, it is 3 channels of 8bits each (3*8=24 :))

On a broader note: learning OpenGL and libpng etc.. is a great way of understanding the fundamentals of game programming although one of the critical components of OpenSource is the reusability of code. If I could point you in the direction of Ogre (www.ogre3d.org), it is an OpenSource 3d graphics library specifically for games. It is quite spectacular, just look at this screenshot: http://ogre.sourceforge.net/albums/album01/quake3.sized.jpg
To copy and paste off the website:
What is OGRE?

OGRE (Object-Oriented Graphics Rendering Engine) is a scene-oriented, flexible 3D engine written in C++ designed to make it easier and more intuitive for developers to produce applications utilising hardware-accelerated 3D graphics. The class library abstracts all the details of using the underlying system libraries like Direct3D and OpenGL and provides an interface based on world objects and other intuitive classes. And from another post I have in this forum (sorry to copy paste but I liked the format :)):

I would suggest the following:
Ogre3d Graphics Library (www.ogre3d.org)
Anjuta IDE (http://anjuta.sourceforge.net/)
And to get them both playing happily this simple setup thread (http://www.ogre3d.org/phpBB2/viewtopic.php?t=5100)You can start right off the bat with these two tools alone to make some pretty cool stuff. Just look at the screenshots on Ogre's website if you are in doubt. And then when you are ready to move onto other areas you can add in Raknet for networking, OpenAL for sound, ODE for collision detection and physics, Crazy Eddies GUI for ingame interface etc... The possibilites are endless. If you have any questions, feel free to pm me.

PompeyBlue
12th August 2004, 11:54 AM
Thanks for the replies!

Somebody had mentioned the Ogre3d engine, but I'm really keen on finding out what goes on under the hood. I still don't truly get how the whole API -> OS -> Driver -> GFX CARD pipeline works.