imgui 画线
时间: 2023-07-26 16:03:39 浏览: 131
Dear user, to draw lines using imgui, you can use the function `ImDrawList::AddLine()` which is a part of imgui's low-level rendering API. Here's an example of how you can use it:
```c++
ImGui::Begin("My Window");
ImDrawList* draw_list = ImGui::GetWindowDrawList();
ImVec2 p1(50.0f, 50.0f);
ImVec2 p2(200.0f, 200.0f);
ImU32 color = ImColor(255, 255, 0, 255); // yellow color
draw_list->AddLine(p1, p2, color, 2.0f);
ImGui::End();
```
In this example, we are first getting the `ImDrawList` associated with the current window using `ImGui::GetWindowDrawList()`. We then define two points `p1` and `p2` and a color `color`. Finally, we call `draw_list->AddLine(p1, p2, color, 2.0f)` to draw a line between the two points with the specified color and thickness (2.0f in this case).
Note that this is just a basic example and there are many other parameters you can use to customize the line's appearance, such as anti-aliasing, rounding, and dash patterns. For more information, I recommend checking out the official imgui documentation.