PNGs and alpha layers

I'm writing a 2D openGL engine using pngs and testing it I've used Carlos's png textures that he just put up. But I realize they don't have an alpha layer. I can't seem to figure out how to use photoshop to make pngs (or any image for that matter) with an alpha layer. Any guidance would be much appreciated.

Quote:Originally posted by KidTsunami I'm writing a 2D openGL engine using pngs and testing it I've used Carlos's png textures that he just put up. But I realize they don't have an alpha layer. I can't seem to figure out how to use photoshop to make pngs (or any image for that matter) with an alpha layer. Any guidance would be much appreciated.

PNGs have similarly to GIF a transparent color, which I don't think is too easy to exploit in OpenGL. If NSImage or quickdraw can draw it correctly, you can use it as a texture. If not, I suggest you try converting them to TIFF images, which I know handle alphas well, and are well supported, too.

The "old" way is to create go to the channel palette and create new channel, and draw in it - the first channel after the R, G & B channels is used as the alpha.

The "new" way is to create your art on a new layer (instead of the "background" layer) and just leave some parts transparent.

I prefer the old method myself, as there are times when you may want to reverse the alpha, or make certain bits invisible without destroying the image data, or pre-multiply the image.

DoooG: PNG's can contain a full 8 bits of alpha, just like TIFF (and compress without resorting to proprietary algorithms like LZW). You can also use 1bit alpha's in OpenGL just like any other alpha - it's your loading code that does the work, OGL doesn't really care where the alpha comes from or how it looks. If you want an OGL texture to "behave" like it has a 1bit alpha, just use alphatesting rather than blending.

Quote:Originally posted by Frank C. ...
DoooG: PNG's can contain a full 8 bits of alpha, just like TIFF (and compress without resorting to proprietary algorithms like LZW). You can also use 1bit alpha's in OpenGL just like any other alpha - it's your loading code that does the work, OGL doesn't really care where the alpha comes from or how it looks. If you want an OGL texture to "behave" like it has a 1bit alpha, just use alphatesting rather than blending.

The problem is getting the PNG to render into a buffer which can be passed to OpenGL. Assuming QuickTime or NSImage doing this, it has to be checked into what pixel format they can render. I know QT does it into BGRA with 8 bits per channel. So yes, the loading code does the work, and if you don't want to write a custom PNG loader, QT is the obvious choice.

Well, I really don't have a problem I guess loading pngs, I'm able to load both carlos's textures and a jpg I had that I brought into photoshop, added an alpha layer, then saved them with super png. But if I change anything but the alpha layer, and save them using super png, they show up as white blocks the size of the actual texture. Does this have to do with the order the bits are in?

This is starting to give me a crucial headache

Mind you I'm saying they show up as white blocks when i load them into my game.

I just don't know, i've been having many problems using these PNGs, are you sure I can't just use jpegs as sprites and use them in a way that the background doesn't show, just the sprite. I know they just have RGB bits but there has to be some sort of easier way to deal with regular sprites and openGL...?

>Do your self a favour and download the SuperPNG plugin
I can'T agree more. I use SuperPNG to save those textures. (Speaking of which, I haven't gotten any feedback on them!) I don't expect everyone to keep them in PNG, so use whatever format is best for your project. I picked PNG for file savings.

PNGs -- Portable Network Graphics -- are images that use a free compression routine, and happily support 32 bit RGBA formats. The artist working on a project with me is using that format, and there've been no problems. As Frank said and DoooooG agreed, that format's R:8 G:8 B:8 A:8.

The "baseline" source for loading PNGs, to my knowledge, is LibPNG and ZLib, both available from http://www.libpng.org and generally free. They also have a page with libraries that wrap the libpng/zlib functions for various reasons; I've found that glpng works great if you remember to set the orientation flag (don't ask). The libpng and zlib code is straight C through and through; you'd have to been masochistic to rewrite the code completely in Cpp or Cocoa or whatnot.

To make OpenGL work with these things, you need to have your loader pick up the alpha channel, the texture format in GL_RGBA_32 (or some such w/ alpha), enable alpha blending, and then remember to draw the transparent objects LAST (the Red Book also says to turn off z-buffer writing).

Email sta7ic at neonshadow dot net if you want some source to look through.