PNG Loading

Hi, I code for fun, nothing comercial going with me, so I decided to work with gl.h glu.h and windows.h, everything nice, once I realised something, how do I load a PNG image as textue without any img loading lib, only me, opengl and c++. I heard it's complicated, I like this kind of stuff, so any help is welcome!
without any img loading lib, only me, opengl and c++
What's the point of this restriction?

Here's the PNG spec: https://www.w3.org/TR/PNG/
Try opening a bmp file before you bump up to png. Both are in binary, but bmp's can be made without compression/encryption (though even that's not a certainty). It will give you an idea of what's to come.
Last edited on
What's the point of this restriction? one day I will make my own. When I will make an engine I will feel proud.
I already did with bmp.

edit:What I'm looking for is an idea how to handle this kind of stuff, like a simplified sample code
Last edited on
If you try to do everything from scratch you will never get anywhere. Like science, great software is built on the shoulders of giants.
Ok, well, making a usable library out of bmp was enough to satisfy my interest in the subject (easier to use libraries to get the pixels into a vector in the correct format and modify them at that point, but it was interesting in a "climb that mountain" kind of way).

Anyhow, try looking at the source code for libpng, it's one of the oldest and best documented png libraries.
http://www.libpng.org/pub/png/libpng.html (source download being in the table just a couple scrolls down)

Note: libpng consists of just over 40 thousand lines of code. If you only focus on pngwrite.c and pngread.c you're looking at 2385 and 4197 lines respectively. I suggest learning the API before delving into the code behind it. I took a peak and it looks like about 50% of the content is actually comments by the coder.

Last edited on
If you want to load and display PNG from scratch you will go nowhere because there are dozen of other image formats. In other words, your challenge you may be doing is not cost effective comparing to your efforts you will spend.

In the end, it is just boring because you may take months just to display some PNG images which is not impressive at all. One can just use libraries to help with their basic tasks, and put all together to create a game or a software you are proud. You can just forget about PNG and coding it is totally not worth your fun.
Topic archived. No new replies allowed.