Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
BlueLeopard543's avatar
BlueLeopard543
Honored Guest
9 years ago

Apply a texture from a HBITMAP to a wall in the sample DirectX11 room

Hi,

is it possible using the code from the sample OculusTinyRoom(DX11) to apply a texture to a solid from a HBITMAP?

The sample code is

TriangleSet walls;
        walls.AddSolidColorBox(-10.1f, 0.0f, -20.0f, -10.0f, 4.0f, 20.0f, 0xff808080);  // Left Wall
        Add(new Model(&walls, Vector3f(0, 0, 0), new Material(new Texture(false, Sizei(256, 256), Texture::AUTO_WALL))));

Let's say that I want apply a HBITMAP texture on this wall, how can I do it in a simple way?

Thanks

6 Replies

  • There is no such thing as a HBITMAP texture, why not simply make a texture out of it?
  • What? I want to know how to make a texture using a HBITMAP but mostly I want to know how to integrate it with the already existing code of the sample. can you help me?
  • I found a sample for OpenGL
    http://stackoverflow.com/questions/23301171/loading-and-converting-a-hbitmap-to-an-opengl-texture

    but i guess you can also use the buffer for something like this

    ID3D11Texture2D *tex;
    D3D11_TEXTURE2D_DESC tdesc;
    D3D11_SUBRESOURCE_DATA tbsd;

    tbsd.pSysMem = (void *)bits;
    tbsd.SysMemPitch = w * 4;
    tbsd.SysMemSlicePitch = w*h * 4; // Not needed since this is a 2d texture

    tdesc.Width = w;
    tdesc.Height = h;
    tdesc.MipLevels = 1;
    tdesc.ArraySize = 1;
    tdesc.SampleDesc.Count = 1;
    tdesc.SampleDesc.Quality = 0;
    tdesc.Usage = D3D11_USAGE_DEFAULT;
    tdesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
    tdesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
    tdesc.CPUAccessFlags = 0;
    tdesc.MiscFlags = 0;

    if (FAILED(myDevice->CreateTexture2D(&tdesc, &tbsd, &tex))) {
    delete[] buf;
    return(0);
    }
  • Hi,

    Sorry but I don't see any HBITMAP in your code in the DirectX part, this just looks like the sample code from Oculus Tiny Room Directx11. How do I create a texture from a HBITMAP?