How do I...Image to win32 HBITMAP

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.
Post Reply
monchito
Posts: 59
Joined: Thu Mar 08, 2007 9:38 pm

How do I...Image to win32 HBITMAP

Post by monchito »

Hi
I'm triying to create a bitmap in win32 from the Textures or images from irrlicht from some code i found here.
No success for now. Only a black square.
Any help is appreciated
Thanks

Code: Select all

  video::IImage* img =       device->getVideoDriver()->createImageFromFile(...);

    int x_dim = (int) img->getDimension().Width;
    int y_dim = (int) img->getDimension().Height;

    HDC hDC = ::GetDC( NULL );
    HDC hdc = CreateCompatibleDC( hDC );
    HBITMAP hbm = CreateCompatibleBitmap( hdc, x_dim , y_dim );
    HBITMAP hbm_tmp = (HBITMAP)SelectObject(hdc, hbm);

    unsigned x, y;
    for (y = 0; y < y_dim; ++y)
      for (x = 0; x < x_dim; ++x)
      {
        video::SColor pixel = img->getPixel(x, y);
        COLORREF clr;
        clr = ((pixel.color & 0x000000ff) << 16) |
            ((pixel.color & 0x0000ff00)) |
            ((pixel.color & 0x00ff0000) >> 16);
        SetPixel(hdc, x, y,clr);
      }

CuteAlien
Admin
Posts: 9716
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Hm, I did that recently when doing the cursors. If you checkout latest trunk (you can also browse svn online) you can look at CIrrDeviceWin32::TextureToCursor.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply