ImGui::Image example DX9 ? #510

Closed
opened 2016-01-26 15:29:16 +00:00 by MINIONBOTS · 8 comments
MINIONBOTS commented 2016-01-26 15:29:16 +00:00 (Migrated from github.com)

Not really an issue, but rather a noob question.
Does anyone have a tiny example how I can load and use my own textures in dx9 with imgui:image ?

I'm not very experienced in dx drawing stuff and only managed to get a white empty rectangle showing up in imgui..so I guess I'm missing something.

In my Init func, I'm loading the texture from the file into memory:
static LPDIRECT3DTEXTURE9 pTexture= NULL;
D3DXCreateTextureFromFile(g_pD3DDevice, "something.jpg", &pTexture)
...
now I guess I'm missing something here ?
...

and later calling the ImGui:Image((void*)pTexture, .... ) to add the image to my window.

I guess I'm missing the part where the texture gets loaded into the renderpipeline, but I'm not so sure where to do this... ImGui:Image adds the required vertices to it's own buffer from what I saw, but somewhere a direct3DDevice->SetTexture (0, texture); is missing I guess ?

Thanks for a quick slap on my head ;)

(does anyone have experience with loading quite a few textures (let's say 50 icons or so) + running imgui in terms of FPS ?)

Not really an issue, but rather a noob question. Does anyone have a tiny example how I can load and use my own textures in dx9 with imgui:image ? I'm not very experienced in dx drawing stuff and only managed to get a white empty rectangle showing up in imgui..so I guess I'm missing something. In my Init func, I'm loading the texture from the file into memory: static LPDIRECT3DTEXTURE9 pTexture= NULL; D3DXCreateTextureFromFile(g_pD3DDevice, "something.jpg", &pTexture) ... now I guess I'm missing something here ? ... and later calling the ImGui:Image((void*)pTexture, .... ) to add the image to my window. I guess I'm missing the part where the texture gets loaded into the renderpipeline, but I'm not so sure where to do this... ImGui:Image adds the required vertices to it's own buffer from what I saw, but somewhere a direct3DDevice->SetTexture (0, texture); is missing I guess ? Thanks for a quick slap on my head ;) (does anyone have experience with loading quite a few textures (let's say 50 icons or so) + running imgui in terms of FPS ?)
ocornut commented 2016-01-26 15:35:10 +00:00 (Migrated from github.com)

Everything should be documented if you read the comment about TextureId, the code in direct9_example/ and the "Image" example in the imgui demo.

Basically ImTextureId is a void* where you can store anything you want. Whatever you pass to Image() is passed down the pipeline to your render function in the end, which can change texture according to this void*.

Everything should be documented if you read the comment about TextureId, the code in direct9_example/ and the "Image" example in the imgui demo. Basically ImTextureId is a void\* where you can store anything you want. Whatever you pass to Image() is passed down the pipeline to your render function in the end, which can change texture according to this void*.
MINIONBOTS commented 2016-01-26 15:37:12 +00:00 (Migrated from github.com)

That is what confused me, the "Image" example in the imgui demo was using the Textureid from the FontAtlas. And in the header was something written with "SetTextID(..)" , but that just set the current TextureID of the fontatlas instance....which afaik is not meant for drawing nor handling other images ?

That is what confused me, the "Image" example in the imgui demo was using the Textureid from the FontAtlas. And in the header was something written with "SetTextID(..)" , but that just set the current TextureID of the fontatlas instance....which afaik is not meant for drawing nor handling other images ?
ocornut commented 2016-01-26 15:38:37 +00:00 (Migrated from github.com)

It is doing that because that's the only texture that the demo application has access to.
You can use your own texture obviously.

It is doing that because that's the only texture that the demo application has access to. You can use your own texture obviously.
MINIONBOTS commented 2016-01-26 15:42:38 +00:00 (Migrated from github.com)

Yes I read these comments, but I fail to make it "use" my texture for that, I guess because I fail to see the connection between my custom texture, FontAtlas's SetTextID and how imgui's drawing works.

That's why I asked for a tiny code example, since I lack some important part I assume ^^

Yes I read these comments, but I fail to make it "use" my texture for that, I guess because I fail to see the connection between my custom texture, FontAtlas's SetTextID and how imgui's drawing works. That's why I asked for a tiny code example, since I lack some important part I assume ^^
MINIONBOTS commented 2016-01-26 15:45:53 +00:00 (Migrated from github.com)

Somewhere in the ImGui_ImplDX9_RenderDrawLists, // Render command lists I assume it will be passing back my Texture ID and I have to handle the rendering for that texture ?

Somewhere in the ImGui_ImplDX9_RenderDrawLists, // Render command lists I assume it will be passing back my Texture ID and I have to handle the rendering for that texture ?
ocornut commented 2016-01-26 15:46:26 +00:00 (Migrated from github.com)

The code in imgui_impl_dx9.* assume that ImTextureId == LPDIRECT3DTEXTURE9
g_pd3dDevice->SetTexture( 0, (LPDIRECT3DTEXTURE9)pcmd->TextureId );
That's all. Just pass your LPDIRECT3DTEXTURE9 and cast it to (void*) when calling Image.

The code in imgui_impl_dx9.\* assume that ImTextureId == LPDIRECT3DTEXTURE9 `g_pd3dDevice->SetTexture( 0, (LPDIRECT3DTEXTURE9)pcmd->TextureId );` That's all. Just pass your LPDIRECT3DTEXTURE9 and cast it to (void*) when calling Image.
MINIONBOTS commented 2016-01-26 15:51:22 +00:00 (Migrated from github.com)

Hmm, from all I know, I did that in my code, I used the pointer to the texture as TextureId, passing it as void_:
ImGui:Image((void_)pTexture,....)
It drew only a blank white rectangle, that what made me waste 2 hours and then give up to ask here.
I'll try again tomorrow I guess :)
thanks a lot, I am in LOVE with ImGUI 😍

Hmm, from all I know, I did that in my code, I used the pointer to the texture as TextureId, passing it as void_: ImGui:Image((void_)pTexture,....) It drew only a blank white rectangle, that what made me waste 2 hours and then give up to ask here. I'll try again tomorrow I guess :) thanks a lot, I am in LOVE with ImGUI :heart_eyes:
ocornut commented 2016-01-26 15:55:51 +00:00 (Migrated from github.com)

I don't know what pTexture is, it is a LPDIRECT3DTEXTURE9 (aka DIRECT3DTEXTURE9*)? it may be invalid, or at least it has to be valid until rendering happen.
Or make sure your UV are correct.
You can also set a breakpoint in the imgui_impl_dx9.cpp renderer and cast it back to LPDIRECT3DTEXTURE9 and inspect from there.

Thanks! Sorry I can't help a lot those questions are overwhelming and I'm trying to shut them down as fast as I can :)

I don't know what pTexture is, it is a `LPDIRECT3DTEXTURE9` (aka `DIRECT3DTEXTURE9*`)? it may be invalid, or at least it has to be valid until rendering happen. Or make sure your UV are correct. You can also set a breakpoint in the imgui_impl_dx9.cpp renderer and cast it back to LPDIRECT3DTEXTURE9 and inspect from there. Thanks! Sorry I can't help a lot those questions are overwhelming and I'm trying to shut them down as fast as I can :)
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ocornut/imgui#510
No description provided.