I have loaded an icon (HICON) and want to create a texture out of it...
unfortunately I have no clue how to achive this...
has someone an idea how to do this ???
(with Irrlicht 1.4.2 and WinXP)

no clue how to use it with an ITexture or IImage...bitplane wrote:I guess you'd use DrawIconEx to draw it into a render target texture.
I was experimenting with this, but got only distorted garphics datas so far...bitplane wrote:Or you could use GetIconInfo to get the raw bitmap data, then copy that to an image
this seems to be the problem I have...bitplane wrote:but you'd need to convert it from a colour key to a true-colour image and copy the mask bits into the alpha channel.

hmm, interesting approach...bitplane wrote:Hmm thinking about this some more, it would make more sense to write some code to extract the bitmaps directly from the .ico file, write them into ram as a file and then pass them to Irrlicht's bitmap loader-
http://msdn.microsoft.com/en-us/library/ms997538.aspx
Code: Select all
#include <irrlicht.h>
#include <windows.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
static const int icoLarge = 256;
static const int icoSmall = 257;
ITexture* getFileIcon(char* filename, int size, IVideoDriver* driver){
ITexture* ret = 0;
SHFILEINFO sfi;
SHGetFileInfo(filename, 0, &sfi, sizeof(SHFILEINFO), size);
ICONINFO icodat;
if(GetIconInfo(sfi.hIcon, &icodat)){
dimension2d<s32> icoSize = dimension2d<s32>(16,16);
if(size == icoLarge) icoSize = dimension2d<s32>(32,32);
// tried with all possible color formats (ECF_A1R5G5B5, ECF_R5G6B5, ECF_R8G8B8 and ECF_A8R8G8B8)
IImage* txt = driver->createImageFromData(ECF_A1R5G5B5, icoSize, &icodat.hbmColor);
stringc icn = filename;
icn += size;
ret = driver->addTexture(icn.c_str(), txt);
txt->drop();
}
return ret;
}
int main(){
IrrlichtDevice *device = createDevice(EDT_DIRECT3D9, dimension2d<s32>(640, 480), 16, false, false, false, 0);
IVideoDriver* driver = device->getVideoDriver();
// be aware it only works with back slashes, not with forward slashes !!!
ITexture* txt1 = getFileIcon("C:\\Programme\\CodeStuff\\Starter\\Starter.exe", icoSmall, driver);
ITexture* txt2 = getFileIcon("C:\\Programme\\CodeStuff\\Starter\\Starter.exe", icoLarge, driver);
while(device->run()){
driver->beginScene(true, true, video::SColor(0,0,0,0));
driver->draw2DImage(txt1, position2d<s32>(100,100));
driver->draw2DImage(txt2, position2d<s32>(150,100));
driver->endScene();
}
device->drop();
return 0;
}
Code: Select all
void getIconTexture( const char* name, HICON icon)
{
HDC hdc = GetDC( NULL);
PICONINFO iconInfo;
BITMAP bmpInfo;
GetIconInfo( icon, iconInfo);
GetObject( iconInfo->hbmColor, sizeof( bmpInfo), &bmpInfo);
ITexture* texture = driver->addTexture( core::dimension2di(bmpInfo.bmWidth, bmpInfo.bmHeight), name);
void* pTexPixel = texture->lock();
BITMAPINFO lBitmapInfo;
ZeroMemory(&lBitmapInfo, sizeof(BITMAPINFO));
lBitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
lBitmapInfo.bmiHeader.biWidth = bmpInfo.bmWidth;
lBitmapInfo.bmiHeader.biHeight = bmpInfo.bmHeight*-1;
lBitmapInfo.bmiHeader.biPlanes = 1;
lBitmapInfo.bmiHeader.biBitCount = bmpInfo.bmBitsPixel;
GetDIBits(hdc, iconInfo->hbmColor, 0, bmpInfo.bmHeight, pTexPixel, &lBitmapInfo, DIB_RGB_COLORS);
texture->unlock();
DeleteDC( hdc);
}
Code: Select all
HICON icon = LoadIcon (NULL, IDI_QUESTION); //Get your icon
getIconTexture( "myIconTexture_1", icon);
...
node->setMaterialTexture(0, driver->getTexture("myIconTexture_1"));
node->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);