PNG help???

Started by
7 comments, last by MasterWorks 19 years, 2 months ago
I was looking over the donuts demo in 9.0b sdk and found that microsoft uses a png file to overlay a user interface at the end of there renderings. Looked at the png file and it looks like it has transparent pixels in it. What is a png file? And how can we use them to create transparent overlays (p.s. the donut demo is way to complicated for me to try to use code from it). Any one know of a simple tutorial that uses them? Or a web page that explains them? Or an article?
Advertisement
There's lots of info about PNG here.
Sorry, apparantly anonymous posting kills links. I meant to point you here.
Thanks but I really didn't see much about usuage with directx
on the page (it had everything else)
There's not much you need to know. PNG is a image file format, which is good for compressing non-photo images, and it can have transparency in it.
You can use D3DXCreateTextureFromFile() to load a PNG file into a texture surface. I've never had a use for file formats with transparency, I usually just use colour keying with D3DXCreateTextureFromFileEx().
Evil Steve is spot on.

Further, PNG images let you do proper transparency rather than keyed transparency: A keyed transparency image uses a praticular colour to represent how transparent a pixel is.

Imagine a sprite which fades from white to transparent. That would be a white -> black fade in a keyed image... but say you want to do a smoke sprite which fades from black to transparent.. sure, you could use another key.. but that's something you won't need to worry about with PNG.

Since PNG's have true transparency (any colour can be any level of transparent).

And a tip: In my experience Adobe Photoshop's PNGs won't display correctly as transparent sprites in DirectX. Use Macromedia Fireworks (others?) instead.
Right, Photoshop writes any pixel that is transparent (alpha=0) as (255,255,255,0) regardless of what color you'd like to be there. This messes things up in Direct3D where pixel colors are interpolated if you use mag/min filters. You'll notice a white fringe around your sprites if you use Photoshop to save PNG files.

I now have a pipeline where I edit files in TGA or TIF and then convert to PNG before distributing. Too bad Photoshop doesn't work correctly with the best image format in existence and that we have to do things like this.

(In versions 6.0 or earlier, at least, TGA/TIF files display alpha information as a separate "channel". PNG files -should- work like this also but don't, they use Photoshop's internal "transparency" instead, which is like a crippled alpha channel.)
Original post by MasterWorks
Right, Photoshop writes any pixel that is transparent (alpha=0) as (255,255,255,0) regardless of what color you'd like to be there. This messes things up in Direct3D where pixel colors are interpolated if you use mag/min filters. You'll notice a white fringe around your sprites if you use Photoshop to save PNG files.

hOW BOUT gimp? dOES THERE PNG FILES WORK?
I have not used GIMP but I think it works properly. There is a mention of the Photoshop problem on the PNG specs homepage, check if it says anything about <your editor of choice>!

This topic is closed to new replies.

Advertisement