PNG

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Guest

PNG

Post by Guest »

Hey

I noticed on the feature list and the planned features that the PNG format isn't included, is it supported? I've heard of a licence needs to be purchased for JPEG ( PNG is SO much better at compression and quality anyway :) )

Also, any plans to support the .MAX model format? I know that you can't store animations in .3DS and I don't really want to buy Milkshape as well as 3DSM. Any other format I can use ( or is planned ) apart from ms3de and the Q2 format?
saigumi
Posts: 921
Joined: Fri Aug 22, 2003 11:31 am
Location: St. Louis, MO USA
Contact:

Post by saigumi »

From what I remember, PNG was suggested and Niko acknowledge working on it in the Feature Request thread in the Open Discussion forum. I really like PNG.

Anim8or support is in the works and is free. I've seen some talk about Max. But not many people can afford the $795.00 for it, so I can't see many people using it... more people can afford the $25 for milkShape or the $0 pricetag of Anim8or
Crud, how do I do this again?
wornaki
Posts: 54
Joined: Sat Aug 23, 2003 1:18 am
Location: Argentina, South America

Post by wornaki »

Yes, the png situation is about to be settled. Hope it happens the same with .an8 file support. Just waiting...
Isometric God
Posts: 69
Joined: Sun Oct 12, 2003 3:42 pm
Location: Germany

Post by Isometric God »

There is a free library on http://www.libpng.org/ including source code and tutorials. Why re-invent the wheel ?
And why does niko have to do all this ? Anybody could write a wrapper class for PNG files ( independent from using libpng or not )
Just my 2 cents ...
rt
Posts: 150
Joined: Sun Nov 30, 2003 6:54 am
Location: canada
Contact:

Post by rt »

has there been any more thought about getting a png loader into the engine? it is such a great format 8)

i coded a CImageLoaderPNG class and it works ok with 24-bpp, but in 32-bpp the alpha doesn't show up right :( .. and also it required libpng.dll which i don't think niko wants.

this is what it looks like when a 32-bpp (with alpha) .png is loaded and then displayed with useAlphaChannelOfTexture=false
Image

and this is what is looks with the same image but useAlphaChannelOfTexture = true
Image

the problem is that the center part of the scope (the white part from the first image) is actually transparent (0x00FFFFFF). it's almost like the alpha is backwards? and the color of the numbers is changed too ..
can anyone help out?

[edit]: i set ETCF_OPTIMIZED_FOR_QUALITY = true and now the .png image is displayed perfectly! ... but only with the directx driver :? when i switch to opengl it suddenly becomes 1-bit alpha instead of 8 bit. this is also a problem for 32-bit .tga files.. they only display correctly in directx mode.
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

Hm, ok.. I'll try to find out the problem until release :)
rt
Posts: 150
Joined: Sun Nov 30, 2003 6:54 am
Location: canada
Contact:

png loader source code (0.4.2)

Post by rt »

---->here<---- is the source for the CImageLoaderPng class (why png?).
there are at least 2 things you won't like about it:
1 - it requires you to hack CReadFile() so that it can get access the "FILE* File" variable.
2 - it requires libpng.dll (included) to be distributed with your exe (this of course could be solved by adding all the png source code to the project but who's got time for that!)

10 easy steps to adding the CImageLoaderPng class to irrlicht:
1 - unzip files to your irrlicht source code folder and in vc++ add CImageLoaderPng.h and .cpp to 'video impl' -> 'null'
2 - open CVideoNull.cpp and add 'createImageLoaderPNG()' in two places .. see if you can figure out where ;)
3 - hack CReadFile.h so that "FILE* File" is public (terrible.. simply terrible!)
4 - build irrlicht!
5 - copy libpng.dll to the same folder as your exe
6 - there is no step 6
7 - create a 64x64 .png image either with alpha (32bpp) or without (24bpp)
8 - add this line before loading any textures

Code: Select all

driver->setTextureCreationFlag(irr::video::ETCF_OPTIMIZED_FOR_QUALITY,true);
9 - load a texture like so

Code: Select all

irr::video::ITexture* my_png_image = driver->getTexture("cool_image.png");
10 - render it like so

Code: Select all

device->getVideoDriver()->draw2DImage(my_png_image,irr::core::position2d<irr::s32>(0,0),irr::core::rect<irr::s32>(0,0,63,63),NULL,irr::video::SColor(255,255,255,255),true);
good luck 8) i hope it works for you but i make no guarantee that it will or that there is not a huge memory leak which will blow up your system. i'm open to any suggestions or improvments so if you think you can improve the code please do.

[edit]: oh yeah, the 32bpp alpha only works properly when directx is the video driver at the moment. but before it will work you need to goto CVideoDirectX8::setRenderStates2DMode and look for the "if (alphaChannel)" block, now change SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE) to SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA)

here is a very ugly screen shot of the png alpha greatness in action:
Image
Last edited by rt on Sat Jan 22, 2005 4:08 am, edited 1 time in total.
rt
Posts: 150
Joined: Sun Nov 30, 2003 6:54 am
Location: canada
Contact:

opened up opengl

Post by rt »

after some poking around i found out how to make 32-bit .png's and .tga's show up properly in opengl mode.
open up CVideoOpenGL.cpp and locate CVideoOpenGL::setRenderStates2DMode().

change this

Code: Select all

		if (alphaChannel)
		{
			glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
			glDisable(GL_BLEND);
			glEnable(GL_ALPHA_TEST);
			glAlphaFunc(GL_GREATER, 0);
		}
to this

Code: Select all

		if (alphaChannel)
		{
			glEnable(GL_BLEND);
			glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
			glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
			glDisable(GL_ALPHA_TEST);
		}
now the alpha transparency shows up perfect :D ... but of course the .png file is 10 times smaller than the .tga!
rt
Posts: 150
Joined: Sun Nov 30, 2003 6:54 am
Location: canada
Contact:

the P is not for Popular

Post by rt »

i guess no one likes png format in this forum :lol:
keless
Posts: 805
Joined: Mon Dec 15, 2003 10:37 pm
Location: Los Angeles, California, USA

Post by keless »

i do. yay!

currently, however, I am writing an IrrLicht Tetris without textures..
a screen cap is worth 0x100000 DWORDS
saigumi
Posts: 921
Joined: Fri Aug 22, 2003 11:31 am
Location: St. Louis, MO USA
Contact:

Post by saigumi »

RT,

This would be a perfect TPIM. Mind if I put it into storage?

http://irrlicht.sourceforge.net/phpBB2/ ... =9076#9076
Crud, how do I do this again?
rt
Posts: 150
Joined: Sun Nov 30, 2003 6:54 am
Location: canada
Contact:

Post by rt »

saigumi wrote:RT,

This would be a perfect TPIM. Mind if I put it into storage?

http://irrlicht.sourceforge.net/phpBB2/ ... =9076#9076
sure, however my code bends the rules you set out... i.e. "TPIMs should be clean". as stated, the code requires a slight hack to CReadFile().. but if you (or someone else) can find a workaround i'd be happy to have it added to TPIM :D
Guest

Post by Guest »

Why do you need libpng.dll? You could just link with libpng.a / png.lib just like currently with libjpeg and libz :!:
Guest

Post by Guest »

rt wrote: .. and also it required libpng.dll which i don't think niko wants.
Why does it need libpng.dll? You can of course link it statically, can't you!?
I like PNG the only correct format for games.. jpeg not good for textures, tga and others bad compression. That's why PNG-loader should be included in the Engine! I'v been using libjpeg, libz and libpng in my engine and just noticed that I need libz.dll, but libjpeg and libpng are statically there.. so as well as you have linjpeg in your engine, you could also have libpng there. (Except if there are licensing restrictions). :)
blayde
Posts: 45
Joined: Fri Jul 16, 2004 12:49 pm
Contact:

Re: Glazer & the Buccaneers

Post by blayde »

duko wrote:Topics containing links to people's sites are unneeded and contribute nothing as a whole, much like topics containing content like this one. You could have PMed a moderator and asked this same question and received the same Black Jack response. Please do so in the future.
i'd have to disagree. i found them to be useful, helpful and informative.
Post Reply