Page 1 of 1

How do I...Image to win32 HBITMAP

Posted: Sat Jul 10, 2010 11:48 am
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);
      }


Posted: Sat Jul 10, 2010 11:52 am
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.