Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImGui::Image example DX9 ? #510

Closed
MINIONBOTS opened this issue Jan 26, 2016 · 8 comments
Closed

ImGui::Image example DX9 ? #510

MINIONBOTS opened this issue Jan 26, 2016 · 8 comments
Labels

Comments

@MINIONBOTS
Copy link

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
Copy link
Owner

ocornut commented Jan 26, 2016

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
Copy link
Author

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
Copy link
Owner

ocornut commented Jan 26, 2016

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
Copy link
Author

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
Copy link
Author

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
Copy link
Owner

ocornut commented Jan 26, 2016

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
Copy link
Author

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 😍

@ocornut
Copy link
Owner

ocornut commented Jan 26, 2016

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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants