creating an empty/hollow Rectangle #425
-
lets say i have something like this: let gm: Gm<Rectangle, ColorMaterial> = Gm::new(Rectangle::new(&three_d_backend.context,
vec2(0.0,0.0),radians(0.0),200.0,200.0),
Default::default()); i want the rectange to be empty, in other words I only need the borders to be visible, I could just draw 4 lines connected to each other but that would be a bit complex and much more pain in the ass, Is there a solution to this? thanks |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 12 replies
-
There will be many ways to do this depending on what you want. are you going to draw anything behind the rectangle? If not, then just draw a rectangle. set a clip rect to be just a little bit smaller than the previous rectangle. clear color. If you want a 3D rect transformed by camera, keep a "scratch" texture aside. do the same rect -> clip rect -> clear thing in that texture, and then render that texture into the main framebuffer like a normal two triangled mesh. This will make sure that anything drawn behind the rect will also survive. If the rectangle is 2D, then its probably better to use a gui paint library. egui provides you a painter that can draw a rect (idk if its hollow inside though) or "path" (lines). https://docs.rs/egui/latest/egui/struct.Painter.html#method.rect_stroke If you will be doing these kinds of things a lot, then, its better to embed a dedicated vector graphics library like egui's epaint, femtovg or even the greatest of them all SKIA . https://fiddle.skia.org/c/@Canvas_drawIRect . |
Beta Was this translation helpful? Give feedback.
-
@MrAliSalehi do you want to draw 3D or 2D shapes? epaint/femtovg/skia can only draw 2D shapes. |
Beta Was this translation helpful? Give feedback.
There will be many ways to do this depending on what you want.
are you going to draw anything behind the rectangle? If not, then just draw a rectangle. set a clip rect to be just a little bit smaller than the previous rectangle. clear color.
If you want a 3D rect transformed by camera, keep a "scratch" texture aside. do the same rect -> clip rect -> clear thing in that texture, and then render that texture into the main framebuffer like a normal two triangled mesh. This will make sure that anything drawn behind the rect will also survive.
If the rectangle is 2D, then its probably better to use a gui paint library. egui provides you a painter that can draw a rect (idk if its hollow inside …