---->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
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: