How to render 3D scene within UI Element ? #475

Closed
opened 2016-01-08 06:25:00 +00:00 by tanb0065 · 4 comments
tanb0065 commented 2016-01-08 06:25:00 +00:00 (Migrated from github.com)

Hi,

I am new to imgui. After done some reading, I notice there is a way to render 3D scene in UI Element which is using ImDrawCallBack. However, I still have no clue on how to use this function.

Can show me an example on how to use this function ? Or is there any other simple way to do it.

Using OpenGL/GLFW.

Hi, I am new to imgui. After done some reading, I notice there is a way to render 3D scene in UI Element which is using ImDrawCallBack. However, I still have no clue on how to use this function. Can show me an example on how to use this function ? Or is there any other simple way to do it. Using OpenGL/GLFW.
emoon commented 2016-01-08 07:46:25 +00:00 (Migrated from github.com)

The easiest way is likely to setup a new render target before you render the UI element and then use that render target later in your rendering which you want to render.

The easiest way is likely to setup a new render target before you render the UI element and then use that render target later in your rendering which you want to render.
ocornut commented 2016-01-08 10:09:01 +00:00 (Migrated from github.com)

If you use the callback system the render loop code will just call your function in the right order (ImGui render window back-to-front). What the callback does is all up to you. Typically you'd want to pass data in the void*, what to render, where to render it, etc. And then the callback can act upon that.

Another solution is to render your scene in a texture/buffer and then use facilities such as ImGui::Image() to just draw this buffer within your UI. This is generally easier to play with, if you can get your scene in a texture first. (Using a callback would technically have the advantage that you can avoid an additional transfer of the pixels, if you are only rendering to a texture for imgui and it isn't needed by your game, but it may probably a bearable cost for flexibility).

If you use the callback system the render loop code will just call your function in the right order (ImGui render window back-to-front). What the callback does is all up to you. Typically you'd want to pass data in the void*, what to render, where to render it, etc. And then the callback can act upon that. Another solution is to render your scene in a texture/buffer and then use facilities such as ImGui::Image() to just draw this buffer within your UI. This is generally easier to play with, if you can get your scene in a texture first. (Using a callback would technically have the advantage that you can avoid an additional transfer of the pixels, if you are only rendering to a texture for imgui and it isn't needed by your game, but it may probably a bearable cost for flexibility).
emoon commented 2016-01-08 10:50:33 +00:00 (Migrated from github.com)

I realise that I read the question wrong. I though the question was on how to render a UI element in a 3D world. Sorry about the confusion reply then :)

I realise that I read the question wrong. I though the question was on how to render a UI element in a 3D world. Sorry about the confusion reply then :)
tanb0065 commented 2016-01-08 13:17:06 +00:00 (Migrated from github.com)

No problem emoon and thanks for the suggestions ocornut.

I will do offscreen rendering to texture using Frame Buffer Object(FBO) since its much more easier for me. I will close this now.

No problem emoon and thanks for the suggestions ocornut. I will do offscreen rendering to texture using Frame Buffer Object(FBO) since its much more easier for me. I will close this now.
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#475
No description provided.