.icon as Texture?
Hi,
is it possible to use .icon Files as textures? I get the icon file into memory with the WinAPI functions and thought about putting it on a quad, as i want to redraw my Desktop with OpenGL.
Alex
Well, i just have an handle to the Icon:
http://msdn.microsoft.com/en-us/library/ms648068(VS.85).aspx
The return value is a handle to an icon. If the file specified was not an executable file, DLL, or icon file, the return is 1. If no icons were found in the file, the return value is NULL.
Would it work anyways, as you described?
http://msdn.microsoft.com/en-us/library/ms648068(VS.85).aspx
The return value is a handle to an icon. If the file specified was not an executable file, DLL, or icon file, the return is 1. If no icons were found in the file, the return value is NULL.
Would it work anyways, as you described?
Well, I don't have any experience on extracting bitmaps but from what I found at MSDN, the following could work:
ICONINFO info;
BOOL res = GetIconInfo(hIcon,&info);
From the ICONINFO structure you should be able to extract the color map and the alpha map, i.e. info.hbmColor and info.hbmMask (both being of type HBITMAP). From those you can create the pixel array using the color map for rgb and the mask for alpha.
Then you load the pixel array into texture memory.
ICONINFO info;
BOOL res = GetIconInfo(hIcon,&info);
From the ICONINFO structure you should be able to extract the color map and the alpha map, i.e. info.hbmColor and info.hbmMask (both being of type HBITMAP). From those you can create the pixel array using the color map for rgb and the mask for alpha.
Then you load the pixel array into texture memory.
Thank you for your answer.
I found several examples how to extract the color map and the alpha map. But i´m not expierenced enough to create the pixel array. Do you know where to find some examples for that?
Alex
I found several examples how to extract the color map and the alpha map. But i´m not expierenced enough to create the pixel array. Do you know where to find some examples for that?
Alex
As long as you have the pixel information it's not that difficult:
1. create an array of numpixels * 4 bytes.
2. for every pixel you fill 4 bytes: r, g, b, a (one byte each).
3. pass the array to glTexImage2D();
1. create an array of numpixels * 4 bytes.
2. for every pixel you fill 4 bytes: r, g, b, a (one byte each).
3. pass the array to glTexImage2D();
Hi,
i´m stuck...thats what i have:
HICON hIconSmall;
ICONINFO IconInfo;
ExtractIconEx((LPCTSTR)"c:\polsuche.exe", 0, NULL, &hIconSmall, 1);
GetIconInfo(hIconSmall, &IconInfo);
HBITMAP color, alpha;
color = IconInfo.hbmColor;
alpha = IconInfo.hbmMask;
How do i find out the number of pixels for the array now?
How can i get the r,g,b,a pixel information in order to put it into the array?
--------------------
There is an other possibility, how i could load the icon as texture. There is this Texture Manager (http://members.iinet.net.au/~cleathley/openGL/TextureLoader.htm). It reads .ico Data as well.
LoadTextureFromRam(unsigned char *pData,
int Length,
glTexture *pglTexture,
eglTexType TexType)
How can I get the pointer to the Raw Data and its length after i loaded the Icon with:
HICON hIconSmall;
ICONINFO IconInfo;
ExtractIconEx((LPCTSTR)"c:\polsuche.exe", 0, NULL, &hIconSmall, 1);
GetIconInfo(hIconSmall, &IconInfo);
?
Alex
[Edited by - hury on June 14, 2008 3:26:46 AM]
i´m stuck...thats what i have:
HICON hIconSmall;
ICONINFO IconInfo;
ExtractIconEx((LPCTSTR)"c:\polsuche.exe", 0, NULL, &hIconSmall, 1);
GetIconInfo(hIconSmall, &IconInfo);
HBITMAP color, alpha;
color = IconInfo.hbmColor;
alpha = IconInfo.hbmMask;
How do i find out the number of pixels for the array now?
How can i get the r,g,b,a pixel information in order to put it into the array?
--------------------
There is an other possibility, how i could load the icon as texture. There is this Texture Manager (http://members.iinet.net.au/~cleathley/openGL/TextureLoader.htm). It reads .ico Data as well.
LoadTextureFromRam(unsigned char *pData,
int Length,
glTexture *pglTexture,
eglTexType TexType)
How can I get the pointer to the Raw Data and its length after i loaded the Icon with:
HICON hIconSmall;
ICONINFO IconInfo;
ExtractIconEx((LPCTSTR)"c:\polsuche.exe", 0, NULL, &hIconSmall, 1);
GetIconInfo(hIconSmall, &IconInfo);
?
Alex
[Edited by - hury on June 14, 2008 3:26:46 AM]
This is the structure of HBITMAP:
The number of pixels is bitmap.bmWidth * bitmap.bmHeight. Extracting the pixels can be easy if bmBitsPixel is 1 (black-white), 8 (greyscale) or 24 (rgb). If you have other bitdepths there might be some conversions needed (e.g. 16 bit might be r5b6g5 or r5g5b5 with 1 unused bit).
You could also use the GetPixel() function. Here's an overview of the bitmap functions from MSDN: http://msdn.microsoft.com/en-us/library/ms532343(VS.85).aspx
typedef struct tagBITMAP { LONG bmType; LONG bmWidth; LONG bmHeight; LONG bmWidthBytes; WORD bmPlanes; WORD bmBitsPixel; LPVOID bmBits; } BITMAP;
The number of pixels is bitmap.bmWidth * bitmap.bmHeight. Extracting the pixels can be easy if bmBitsPixel is 1 (black-white), 8 (greyscale) or 24 (rgb). If you have other bitdepths there might be some conversions needed (e.g. 16 bit might be r5b6g5 or r5g5b5 with 1 unused bit).
You could also use the GetPixel() function. Here's an overview of the bitmap functions from MSDN: http://msdn.microsoft.com/en-us/library/ms532343(VS.85).aspx
I´ve tried following:
HICON hIconSmall;
ICONINFO IconInfo;
BITMAP bmp;
ExtractIconEx((LPCTSTR)"polsuche.exe", 0, NULL, &hIconSmall, 1);
GetIconInfo(hIconSmall, &IconInfo);
GetObject ( IconInfo.hbmColor, sizeof(IconInfo.hbmColor), &bmp ) ;
cout << "Höhe: " << bmp.bmHeight << "\n";
cout << "Bits: " << bmp.bmBitsPixel << "\n";
but i´m getting strange values for height and bits (height -8343438) and bits= 23288, so it seems, im still doing something wrong.
Please assist :)
HICON hIconSmall;
ICONINFO IconInfo;
BITMAP bmp;
ExtractIconEx((LPCTSTR)"polsuche.exe", 0, NULL, &hIconSmall, 1);
GetIconInfo(hIconSmall, &IconInfo);
GetObject ( IconInfo.hbmColor, sizeof(IconInfo.hbmColor), &bmp ) ;
cout << "Höhe: " << bmp.bmHeight << "\n";
cout << "Bits: " << bmp.bmBitsPixel << "\n";
but i´m getting strange values for height and bits (height -8343438) and bits= 23288, so it seems, im still doing something wrong.
Please assist :)
GetObject might return an error. Did you check this? Try checking the parameters for GetObject in a debugger. Is IconInfo.hbmColor valid? What is sizeof(IconInfo.hbmColor)? (Try int s = sizeof(...) and pass s to GetObject()).
It might also be a matter of packing. Try #pragma pack(1) at the beginning of your source file.
It might also be a matter of packing. Try #pragma pack(1) at the beginning of your source file.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement