Jump to content
  • Advertisement
Sign in to follow this  
hury

OpenGL .icon as Texture?

This topic is 3712 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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();

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
This is the structure of HBITMAP:

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

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!