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

Draw graphics in the background #2391

Closed
Riccsson opened this issue Mar 1, 2019 · 3 comments
Closed

Draw graphics in the background #2391

Riccsson opened this issue Mar 1, 2019 · 3 comments

Comments

@Riccsson
Copy link

Riccsson commented Mar 1, 2019

Hi.

Have used:

auto globalDrawlist = ImGui::GetOverlayDrawList();
globalDrawlist->AddRectFilled(pos1, pos2, ThemeColors.WindowBackground, 8.0f);

and so on to draw some loading progress bar and status in front of everything.

But now I am trying to draw some rectangles and circles in the main background but have no clue how to do that. I was trying something like this:


ImDrawList drawList(ImGui::GetDrawListSharedData());
drawList.AddRectFilledMultiColor(ImVec2(), ImGui::GetIO().DisplaySize, ThemeColors.MainBackground1, ThemeColors.MainBackground2, ThemeColors.MainBackground3, ThemeColors.MainBackground4); ImGui::AddDrawList(&drawList);

But I cant get it to work. Is there anyone how know how to do that? Thanks

@ocornut
Copy link
Owner

ocornut commented Mar 4, 2019

There's no function called ImGui::AddDrawList(&drawList); in imgui so you seem to be omitting information from your use case.

Indeed you need to be rendering this draw list in your render function.
You may just construct a ImDrawData structure and call your render function twice, that would be the easiest way at the moment.

This is a fairly common request so I may just go and add a helper GetBackgroundDrawList() function. I was hesitant with adding it because the GetOverlayDrawlist() function doesnt' have a trivial 1-to-1 equivalent in the multi-viewport branch, but think this already needs to be solved for GetOverlayDrawlist I may add the new function anyway.

ocornut added a commit that referenced this issue Mar 4, 2019
…wList that will be rendered behind every other windows. (#2391)
ocornut added a commit that referenced this issue Mar 4, 2019
…cy. Kept redirection function (will obsolete). (#2391)

Demo: Using GetBackgroundDrawList() and GetForegroundDrawList() in "Custom Rendering" demo.
@ocornut
Copy link
Owner

ocornut commented Mar 4, 2019

@Riccsson I have added a GetBackgroundDrawList() function now.
And GetOverlayDrawList() was renamed to GetForegroundDrawList() for consistency.

@ocornut ocornut closed this as completed Mar 4, 2019
@Riccsson
Copy link
Author

Riccsson commented Mar 5, 2019

Work greats! Thanks!

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