0
\$\begingroup\$

I'm using this Dear ImGui code in a function called several times per frame, resulting in duplications of the called UI element.

ImGui::Begin("Hello World");
ImGui::SliderFloat("test", &foo, 0.0f, 100.0f);
ImGui::End();

Result:

enter image description here

How to correct this behaviour? Can Dear ImGui be set to avoid this, or do I have to take care of this myself?

\$\endgroup\$
9
  • 1
    \$\begingroup\$ "do I have to take care of this myself?" Yep. We're not yet ready for having programs design themselves from "what we want them to do". Did you try to put this in an if( not flag ) { /* draw your thing */ flag = true; } and reset the flag every frame? \$\endgroup\$
    – Vaillancourt
    Nov 22 at 19:34
  • 1
    \$\begingroup\$ Why is this function called several times a frame? A function which is supposed to render should be called exactly once per frame. \$\endgroup\$
    – tkausl
    Nov 22 at 19:57
  • \$\begingroup\$ Thanks for your answers. I asked that because ImGUI knows when there is a new frame (ImGui_ImplOpenGL3_NewFrame), so it could maybe have deal with it. @Vaillancourt: yes this is what I thought :) \$\endgroup\$
    – Hermann
    Nov 22 at 20:23
  • 1
    \$\begingroup\$ I'm talking about I'm using this Dear ImGui code in a function called several times per frame. Why is this function called several times per frame? \$\endgroup\$
    – tkausl
    Nov 22 at 20:34
  • 1
    \$\begingroup\$ It looks to me like we don't have enough context to help you call this function only once per frame. You'll need to expand your code example so we can see where the multiple calls arise. \$\endgroup\$
    – DMGregory
    Nov 22 at 20:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.