Skip to main content
Participant
May 19, 2016

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

Inspiring
May 22, 2016
There is no such thing as a HBITMAP texture, why not simply make a texture out of it?
Participant
May 22, 2016
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?
Inspiring
May 22, 2016
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);
}
Inspiring
May 22, 2016
But I see no DX11 in your sample, seems to be wrapped in classes somehow
Participant
May 24, 2016
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?
Participant
May 28, 2016
you need to access the bits of the bitmap and squirt them into a directx texture as thewhiteambit explained above.


Getting the bits from an HBITMAP is a pain as it's a legacy GDI function. You'd be better off avoiding all that stuff.

If you really must do it that way, this explains how to access the bitmap data from the handle.

https://msdn.microsoft.com/en-us/library/windows/desktop/dd183402%28v=vs.85%29.aspx