Is there a high level shape drawing API for C or C++?
I am starting a new project (Windows application), which needs a simple graphical interface. The graphics are not the main point of the application, the algorithms behind them are, so I'd like to spend as little time as possible thinking about graphics.
I need to draw simple shapes, connect them with lines, and label both the shapes and the edges. My ideal API would look something like
n1 = Rectangle(width, height, center1);
n1->label("Node1");
n2 = Circle(radius, center2);
l = Line(n1->rightEdge()->midpoint()), (n2->center()-Point(n2->radius,0));
l->label("pathway",BELOW);
I know I could certainly use a low-level library to build up to th开发者_如何转开发is level of abstraction. But I'd rather not, if it has already been done. Does a graphics library with this level of abstraction exist? I'd be equally happy with C/C++. C# would be an option too.
Due to the general ease of writing that kind of high-level system, given a low-level drawing API, you generally don't see this kind of 2D scene graph library. The kind where there are explicit objects in the scene, and you move the objects around on the level of objects.
The closest I can think of is the way WPF handles drawing, where you create graphics objects and attach them to windows. And that's .NET only.
Everything else, whether Cairo, AGG, Direct2D, etc are all immediate drawing APIs. There are no "objects" that you manipulate or attach labels to. You simply draw stuff in a location. If you want to move something, you have to draw the stuff in that new location.
I use SDL for my graphics needs. I only use it for the OpenGL context (which it handles great) but it's quite friendly for getting efficient and portable graphics to work. There are software drawing routines available if you don't want to deal with OpenGL.
There is the new Direct2D API for Windows by Microsoft, mainly aimed at vector graphics.
perhaps AGG would work for you. if you step back a few revs, you will also find a license which is better for commercial development.
You can also try with qt lib qt is a great toolkit and multiplatform
精彩评论