views:

632

answers:

9

I've been looking for a good cross-platform 2D drawing library that can be called from C++ and can be used to draw some fairly simple geometry; lines, rectangles, circles, and text (horizontal and vertical) for some charts, and save the output to PNG.

I think a commercial package would be preferable over open source because we would prefer not to have to worry about licensing issues (unless there's something with a BSD style license with no credit clause). I've looked at Cairo Graphics which seemed promising, but the text rendering looks like crap out of the box, and upgrading the text back-end brings us into murky license land.

I need it for Windows, Mac and Linux. Preferably something fairly lightweight and simple to integrate. I've thought about Qt but that's way too heavy for our application.

Any ideas on this would be awesome.

A: 

Use SDL

Toad
I've used both SDL and SFML, and I would strongly recommend SFML over SDL. It makes use of C++ constructs (OOP, function overlods, ...), and it's much easier and fun. To me the only possible drawback is that it's still a recent library compared to SDL, so it may not be as stable.
Bastien Léonard
also, SDL does not come with functions to draw primitives he listed. You have to find code done by others or code them yourself.
Michaël Larouche
+2  A: 

Have a look at SFML. It's open source but the license is very permissive.

Drawing simple shapes
Displaying text

Bastien Léonard
+2  A: 

Antigrain does high quality primitive rendering and seems to be able to render true type fonts and has a commercial license available upon request.

http://www.antigrain.com/

Laserallan
+4  A: 

Try Anti-Grain Geometry. From the description:

Anti-Grain Geometry (AGG) is an Open Source, free of charge graphic library, written in industrially standard C++. The terms and conditions of use AGG are described on The License page. AGG doesn't depend on any graphic API or technology. Basically, you can think of AGG as of a rendering engine that produces pixel images in memory from some vectorial data. But of course, AGG can do much more than that. The ideas and the philosophy of AGG are:

  • Anti-Aliasing.
  • Subpixel Accuracy.
  • The highest possible quality.
  • High performance.
  • Platform independence and compatibility.
  • Flexibility and extensibility.
  • Lightweight design.
  • Reliability and stability (including numerical stability).
TomA
Thanks, this looks to be right up my alley, I'm going to check it out.
Gerald
Just the other day I noticed my GPS unit was using AGG for map rendering. Neat!
TomA
As an FYI, I tried repeatedly to contact the developers of AGG in relation to obtaining a commercial license, and never got a response. It has also been 2 years since any news was posted on the site, so I'm assuming it's no longer supported. So I ended up just rolling my own custom solution across the 3 platforms that I needed. It's still probably a good solution if using the older version with the non-GPL license, so I will leave this as the best answer, but I just didn't want to deal with an unsupported library.
Gerald
Thanks for the update, good to know.
TomA
A: 

OpenGL?

graham.reeds
A: 

Have you tried FLTK? It is lightweight, cross-platform, has support for 2D/3D graphics and comes with a good widget set (including a charting component). The API is simple and straight forward.

Vijay Mathew
A: 

I would go for AGG or Cairo.

+1  A: 

There is also libgd - simple one, but well-written.

Regarding Cairo Graphics, I can't believe it renders text that looks bad. If you are particularly concerned about text rendering, State of the Text Rendering from Jan 2010 gives quite good overview.

mloskot
I should have been a little more explicit; Cairo Graphics renders large text well, but I needed to render small text labels on charts and graphs, and that's were it looks like crap because it uses vector graphics to render it. As long as the text is large enough for at least 2-pixel lines all the way around it's okay, but try rendering some text at font size 8 or so and see if you can read it ;)
Gerald
A: 

I use CImg: cross platform (self contained single header file), simple, concise. PNG is not natively supported but can be handled if ImageMagick is installed (see supported formats).

See also this related question.

rafak