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

Extension to clipping #1420

Closed
berkay2578 opened this issue Nov 8, 2017 · 2 comments
Closed

Extension to clipping #1420

berkay2578 opened this issue Nov 8, 2017 · 2 comments

Comments

@berkay2578
Copy link

berkay2578 commented Nov 8, 2017

Hello once again. I was looking into PushClipRect() and PopClipRect() and needed some extra functionality for what I'm trying to do. Let me explain it as fast as I can.

I have a circle for my background and sometimes I only want a certain region of it rendered. For example, I want to clip-out the black colored area:
image

With the current rectangular clip I can only achieve it linearly, like so:
image

This may sound like the world's most unnecessary feature request, and it probably is. Adding a function like PushClipRectEx which would make it possible to define all 4 corners of the rectangle or maybe a trapezoid clip area should solve this issue. I've just started messing around with ImDrawList but I'll take a crack at it anyway after my mid-terms. Let me know of your thoughts.

@ocornut
Copy link
Owner

ocornut commented Nov 8, 2017

I don't think it would be easy or practical to support arbitrary clipping shapes, the clipping rectangle is processed both on CPU side and GPU side (typically using the Scissor functionality of GPU driver which is essentially axis-aligned clipping), and imgui typically rely on a single shader to batch draw calls.

Also if you clipped the polygons on CPU side it will be harder to get nice anti-aliasing on those shapes.

Really, for your example and many other uses cases it would be much much easier to just generate the right shape/polygons in the first place. So you can perform all the polygon manipulation and clipping on your side and then submit that as convex shapes to ImDrawList. But the complexity of that code depends on what you ACTUALLY need to render.

Here you are showing a rotated half circle and if that's what you really want to draw, that's very easy to do. In fact you can already do it with 2 function calls:

draw_list->PathArcTo(center, radius, angle_min, angle_max);
draw_list->PathFillConvex(IM_COL32(255,0,0,255));

Done!
As long as your 2 angles that not more than PI radians apart then your shape is convex. Otherwise you can draw it with two shapes instead of one.

@berkay2578
Copy link
Author

Wish it was that simple in my case. Think of the red part as a 'breathing' UI, it constantly clips out some region from its bottom-right to hide/show information, so it's not only the background UI. I think what I'm asking is way too much from ImGui though, supporting something like this natively would be redundant. I'll detach this portion of the application from ImGui and just use shaders/post-processing to get what I want. Thanks for your input.

You can close the issue if you wish. :)

@ocornut ocornut closed this as completed Nov 9, 2017
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