# How to not call the same Dear ImGui function several times per frame

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:

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

• "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? Nov 22 at 19:34
• Why is this function called several times a frame? A function which is supposed to render should be called exactly once per frame. Nov 22 at 19:57
• 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 :) Nov 22 at 20:23
• 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? Nov 22 at 20:34
• 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. Nov 22 at 20:47