-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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 to draw on an ImGui window? #984
Comments
You can: 1- Render your scene in a texture and then render the texture in imgui. For the second part read about comments related to ImTextureId and check the code in your imgui_impl_xxxx.cpp renderer. Check the Image() functions, and ImDrawList::AddImage() etc. 2- Add a Callback to the current window ImDrawList and perform your full rendering within this callback at the right point during rendering. The first one is simple and convenient and this is what most people would do. |
Thanks I'll try to do it! Isn't it possible to draw in the default framebuffer?? Because I create a rendering pipeline to the drawing default framebuffer myself. |
You can draw wherever you want to draw, at is all under the control of your application. If you want to avoid intermediate buffers you can use ImDrawList::AddCallback(). |
Thanks again! I'll try to do it later! |
@morizotter in my engine I create a plus one more buffer for my engine and I let ImGui draw on backbuffer. So this one more buffer is actually the "backbuffer" for my engine, since then I do postprocessing over the image, so it makes sense to make it like this. So just make your engine backbuffer a RenderTargetView or FBO (or whatever you fancy) and pass it to ImGui control as image. Easy, no hassle and quite clean solution |
I'm also new to C++... I's a bit difficult for me..
and,
produces: I want to a draw red triangle in the window.. Sorry for easy question.. |
The callback won't know anything about windows. If you want to draw at a certain screen position you may use eg GetCursorScreenPos() and transfer that information into your callback.
|
I could pass window info to callback. I have problems. Something wrong with my way..
If you have a simple demo code 😅 . Anyway, thank you for your help! I'll try to do it.. |
This is not an imgui problem anymore but a problem with your OpenGL rendering state.
It may be easier/healthier to support render targets, but either way to will need to evolve your code/engine to setup all render state correctly.
|
Note you might use the ImDrawList api as a primitive renderer if you can rely on using the ImDrawVert type for all your vertices. You can then change shaders/uniform/constantbuffers using callback. Of course this is only a solution if your rendering needs are simple and you can't/don't want to create a full fledge renderer.
|
I know it. I try to brush up my knowledge about OpenGL and ImGui! 😺 |
@morizotter you need to brush up C++/OpenGL not ImGui. Sorry to be harsh sounding, but ImGui is 99% not the reason why your rendering is bad. Also, don't care about imgui yet, you don't need it. We switched to ImGui after like 7 months of engine development, where we figured that let's say editing XML files don't cut it anymore |
@citruslee I partly disagree - there's no reason you shouldn't use ImGui from Day 1 of engine development. Engine = tools, auditing, debugging, tests, interactions, they all need some form of UI, why waiting 7 months! |
@ocornut valid point, but he should learn programming in the language and graphic API first, then bother about UI |
also for the very reason, it was quicker to edit the XML file directly, and yeah, we had this hot reload of built code and assets, including XML-s, which made content management quite a breeze, but then we incorporated 3D artists and designers so we suddenly needed a UI |
@citruslee UI can help people learn programming by visualizing and understanding what they are doing better (e.g visualizing algorithms). Either way it is a tool, there's no rule of thumb but if its worthwhile for you no reason of delaying its use. I also have similar systems (except without xml, because I respect my eyes ;)) as I think editing text files is super convenient. I personally mostly use dear imgui for visualization, testing, debugging tooling more than actual content authoring. Some of my in-engine tools are here #772 (comment) |
yes, they can, but I still think, if you are not familiar with the language or the api, it won't help you that much, because if you can't visualize the data by yourself, you would not do it even with ImGui. Also, to make UI actually work for you and not the other way around takes practice, even if it is ImGui, which is my favourite UI library (yaaaay! :D), but still, first IMHO he should learn vanilla C++ and then if he is comfy with the language should use ImGui. A few words to end my seemingly passive agressive and harsh dialogue, I encourage everyone to program, because programming is fun, and the result is greatly rewarding. I also teach programming for university students, but I find one thing recurring year by year. Everyone just wants to suddenly make games, or they are digging their head into stuff they don't understand at all. While if someone's IQ is above the speed of light and he had a programming experience before, they can get things up pretty quickly, but usually it takes time to do advanced stuff. And until then you should stick to simple things. This is why I developed Minerva with no GUI and with XML's. Because I have my own pretty damn kickass xml lib and I had routines built into the engine which helped me to reduce the number of builds and increase the content creation. And probably I still don't need any UI libs, neither ImGui, because I can change the code during the runtime (hotreloadable plugins) and also the data (change xml, bam). Of course since then we began to use console inside Minerva and that is damn comfy, but still nothing what you couldn't do with your fiat windows console. Still, hope ImGui will be growing steadily and it won't go away, because this lib is the only usable lib where I can make fast prototypes for our designers and graphicians, so thank you @ocornut for Dear ImGui, keep up the good work and get docking into ImGui API ASAP! :D |
May be you can create a different viewport to 3D scene and set its position and size as your ImWindow? Customize they background as transparent and its be look as 3D scene inside ImWindow? |
@morizotter Have you solved this problem? Using callbacks and rendering without an intermediary target is harder to get right. |
If you render after ImGui::Render(); you will overwrite any ImGui window without transparencies ;) |
I may have found a solution, at least for the OpenGL 3 examples, see my pull request #1639. |
Better late than never @morizotter Found a reason for flickering! In my fragment shader I used a vec3 output color. I changed it to vec4 and set alpha to 1, this resolved flickering in my case. Thanks for your code, it helped a lot! |
Do you know how to draw gl in the ImGui window?
https://github.com/ocornut/imgui/releases
I'd like to do like above.
The text was updated successfully, but these errors were encountered: