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

How can i show an image in imgui window #1848

Closed
coderboyisongithub opened this issue May 30, 2018 · 2 comments
Closed

How can i show an image in imgui window #1848

coderboyisongithub opened this issue May 30, 2018 · 2 comments

Comments

@coderboyisongithub
Copy link

You may use the Issue Tracker to ask for help and submit bug reports, feature requests or suggestions.

PLEASE CAREFULLY READ THIS DOCUMENT before doing so:
CONTRIBUTING.md.

SELECT "PREVIEW CHANGES" TO TURN THE URL ABOVE INTO A CLICKABLE LINK.

(Delete everything above this section before submitting your issue. Please read the CONTRIBUTING.md file!)


Version/Branch of Dear ImGui:

XXX

Back-end file/Renderer/OS: (if the question is related to inputs/rendering/build, otherwise delete this section)

XXX

My Issue/Question: (please provide context)

Standalone, minimal, complete and verifiable example: (see CONTRIBUTING.md)

ImGui::Begin("Example Bug");
MoreCodeToExplainMyIssue();
ImGui::End();

Screenshots/Video (you can drag files here)

@ocornut
Copy link
Owner

ocornut commented May 30, 2018

** EDIT: We know also have a tutorial for loading textures with different graphics API:
https://github.com/ocornut/imgui/wiki/Image-Loading-and-Displaying-Examples **


Please read the FAQ and the documentation of the rendering API you are using.

 Q: How can I display an image? What is ImTextureID, how does it works?
 A: ImTextureID is a void* used to pass renderer-agnostic texture references around until it hits your render function.
    Dear ImGui knows nothing about what those bits represent, it just passes them around. It is up to you to decide what you want the void* to carry!
    It could be an identifier to your OpenGL texture (cast GLuint to void*), a pointer to your custom engine material (cast MyMaterial* to void*), etc.
    At the end of the chain, your renderer takes this void* to cast it back into whatever it needs to select a current texture to render.
    Refer to examples applications, where each renderer (in a imgui_impl_xxxx.cpp file) is treating ImTextureID as a different thing.

       // The example OpenGL back-end uses integers to identify textures. 
       // You can safely store an integer into a void* by casting it. e.g. (void*)(intptr_t)MY_GL_UINT to cast to void*.
       GLuint my_opengl_texture;
       glGenTextures(1, &my_opengl_texture);
       // [...] load image, render to texture, etc.
       ImGui::Image((void*)(intptr_t)my_opengl_texture, ImVec2(512,512));

       // The example DirectX11 back-end uses ID3D11ShaderResourceView* to identify textures.
       ID3D11ShaderResourceView* my_texture_view;
       device->CreateShaderResourceView(my_texture, &my_shader_resource_view_desc, &my_texture_view);
       ImGui::Image((void*)my_texture_view, ImVec2(512,512));

    To display a custom image/texture within an ImGui window, you may use ImGui::Image(), ImGui::ImageButton(), ImDrawList::AddImage() functions.
    Dear ImGui will generate the geometry and draw calls using the ImTextureID that you passed and which your renderer can use.
    You may call ImGui::ShowMetricsWindow() to explore active draw lists and visualize/understand how the draw data is generated.
    It is your responsibility to get textures uploaded to your GPU.

This is not the first time you post a question without even filling the required form. While I am happy to help users this is not a hand-holding forum. Please refrain from asking questions without providing full details and what you have tried/learned.

@ocornut
Copy link
Owner

ocornut commented May 30, 2018

Updated FAQ with some clarification. Closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants