PNGs and alpha layers

KidTsunami
Unregistered
 
Post: #1
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 this message in a reply
DoG
Moderator
Posts: 869
Joined: 2003.01
Post: #2
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.
Quote this message in a reply
Member
Posts: 446
Joined: 2002.09
Post: #3
Do your self a favour and download the SuperPNG plugin: http://www.fnordware.com/superpng/ (it's free).

Alpha's in newer versions of Photoshop can be created two ways:

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 this message in a reply
KidTsunami
Unregistered
 
Post: #4
But Frank C. using Photoshop, I can't save with the alpha layer. Would the superpng plug in solve that?

Also, if possible is there any other programs that I can make pngs with alpha layers easily? I'm just trying to create some test art assets quickly.
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #5
graphic converter can also add alpha layers to images.
Quote this message in a reply
DoG
Moderator
Posts: 869
Joined: 2003.01
Post: #6
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.
Quote this message in a reply
Member
Posts: 509
Joined: 2002.05
Post: #7
Quote:Originally posted by KidTsunami
But Frank C. using Photoshop, I can't save with the alpha layer. Would the superpng plug in solve that?


I was having similar problems in PS7, this is what I did to fix it. Click the "Save as Copy" button in the save dialog, then the Alpha Layer check box should be enabled.
Quote this message in a reply
Member
Posts: 79
Joined: 2002.08
Post: #8
I just save images with alpha as TIFF. Works great. I haven't had any good success with PNG and alpha channels.

KenD

CodeBlender Software - http://www.codeblender.com
Quote this message in a reply
Member
Posts: 446
Joined: 2002.09
Post: #9
Quote:Originally posted by KidTsunami
But Frank C. using Photoshop, I can't save with the alpha layer. Would the superpng plug in solve that?
Yes (the built-in PNG support is pretty pathetic)

Quote:Originally posted by DoooG
The problem is getting the PNG to render into a buffer which can be passed to OpenGL...

PNGLib is best for loading PNG files: http://homepages.cwi.nl/~jack/macsoftware.html (it has ordering functions built in if you need them) but QuickTime should handle them just fine, and once you have the bytes you can coerce them into whatever format ya like. Here's an OpenGL specific PNG loader as an example: http://www.wyatt100.freeserve.co.uk/download.htm
Quote this message in a reply
KidTsunami
Unregistered
 
Post: #10
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 Wacko

Mind you I'm saying they show up as white blocks when i load them into my game.
Quote this message in a reply
KidTsunami
Unregistered
 
Post: #11
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...?
Quote this message in a reply
Founder
Posts: 1,138
Joined: 2002.04
Post: #12
>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.

Carlos A. Camacho,
Founder
iDevGames
Quote this message in a reply
Sta7ic
Unregistered
 
Post: #13
I'm not really sure what this thread is about anymore...

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.

Good luck w/ your graphic problems.
-"Sta7ic" Matt
Quote this message in a reply
Post Reply