You are not logged in.

#1 2015-01-26 08:33:29

niva
Member
Registered: 2014-11-29
Posts: 6

What graphic library should I use for a c++ program?

Hey guys!

I'm working on a c++ program that should produce some simple graphic output. It just needs to draw polygons and lines in different colors. But it should be fast.
I don't really know how to google this question.
What I found so far is, I could use the X libraries directly or I could use SDL.
To me SDL looks more usable/easier then using X libraries.

What would you recommend? Or is there something simpler then SDL that I could use?

Also if you know any good online guides that might get me started, that would be great.

Thanks in advance!

Last edited by niva (2015-01-26 08:46:33)


Don't panic!

Offline

#2 2015-01-26 09:54:02

dolik.rce
Member
From: Czech republic
Registered: 2011-05-04
Posts: 43

Re: What graphic library should I use for a c++ program?

Hi,

You could also use U++, it is fast and easy too use. See this reference example for some simple drawing code. It is a complete, multiplatform framework, that provides much more than just drawing.

Last edited by dolik.rce (2015-01-26 09:54:17)

Offline

#3 2015-01-26 13:27:23

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,331
Website

Re: What graphic library should I use for a c++ program?

Personally I find Xlib to be much easier to use than SDL (or cairo which is another you should consider).  But if you need efficent drawing of anything elaborate, then definitely don't use Xlib drawing functions - they're just not cut out for that.

Further, I've learned quite a bit about Xlib over the past few years - and if the wayland fans are right, that knowledge may soon become useless.  SDL and cairo are still perfectly suited to be used with wayland, thus getting experience with those tools is much more 'future proof' over spending time learning how to do Xlib drawing well.

I've also found the documentation for cairo to be excellent.  I've tinkered with SDL and not found the documentation to be as useful for me.  That said, cairo is written in C, and most of the API documentation is for C or python.  There are C++ bindings as well, but I've never used them.

EDIT: another point in favor of cairo is that it "plays well with others".  SDL can do quite a lot, but most of this is accomplished by reinventing wheels to have SDL functions/modules/classes for everything under the sun.  Cairo, in contrast, just makes it very easy to interact with other libraries (xlib surfaces for drawing to windows, poppler surfaces for reading/writing/rendering pdfs,  Freetype for fancier fonts, etc).

Last edited by Trilby (2015-01-26 13:33:30)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#4 2015-01-26 14:00:21

thiagowfx
Member
Registered: 2013-07-09
Posts: 586

Re: What graphic library should I use for a c++ program?

niva wrote:

I'm working on a c++ program that should produce some simple graphic output. It just needs to draw polygons and lines in different colors. But it should be fast.

I used SDL2 in the past, I'd say it fits your needs. And, as far as I know, it is fast. Also, I would recommend it over Xlib, because it is cross-platform.

Offline

#5 2015-01-26 14:08:42

progandy
Member
Registered: 2012-05-17
Posts: 5,279

Re: What graphic library should I use for a c++ program?

If you need to produce graphics, does that have to be interactive or could you just create an imagefile? In that case you might consider creating writing an svg file, for simplistic shapes you can do that with only a header file: https://code.google.com/p/simple-svg/


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#6 2015-01-26 15:09:24

nomorewindows
Member
Registered: 2010-04-03
Posts: 3,409

Re: What graphic library should I use for a c++ program?

I guess you could go lazy and write it in java.


I may have to CONSOLE you about your usage of ridiculously easy graphical interfaces...
Look ma, no mouse.

Offline

#7 2015-01-26 15:29:14

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: What graphic library should I use for a c++ program?

niva wrote:

What would you recommend? Or is there something simpler then SDL that I could use?

Look through the List of Game Engines and find one that meets your needs. They all have different features and benefits. Some focus on ease of use, some on feature completeness, and so on. As you can see, many of them use SDL as a backend, which means they will be as fast as using SDL by itself.

What are you making?

Offline

#8 2015-01-27 14:42:44

hipersayan_x
Member
Registered: 2014-12-09
Posts: 36
Website

Re: What graphic library should I use for a c++ program?

Qt has all features you want.

Offline

#9 2015-01-27 16:48:20

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,344

Re: What graphic library should I use for a c++ program?

This sort of topic always bugs my inner Systems Engineer.   There are many solutions, as you have found out.   Gtk, Gtkmm, Qt, Tk, FLTK, wxWidgets.  Heck, there is even MFC.

What do you need from a tool kit besides simple graphics? 

Do you need cross platform capability? (Qt, FLTK, wxWidgtets, Tk.  Gtk Claims it -- I disagree)

Do you care about license? Are you going to distribute this?  Is this going to be Free or proprietary?

Define simple. 
Small foot print? Easy learning curve?  (wxWidgets, FLTK, Tk)
Do you want a GUI tool for designing your interface or is okay to do it all in code or XML files? (Qt, Gtk, Gtkmm)
Would a fully integrated IDE dedicated to the tool kit be of interest (Qt has this)
Do you want to use pure C++, or do you care about extensive extensions to the language based on macros? (One of the critiques of Qt)


So, let me throw in my suggestions for Tk and wxWidgets.  Both are dirt simple to use.  Tk is ubiquitous -- it has a high probability of already being installed on Macs, BSDs, Linux and even Windows.
A usable application with a drawing area and a couple buttons can be implemented in much less than 100 lines of code.

Last edited by ewaller (2015-01-27 16:49:07)


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#10 2015-01-27 23:14:48

niva
Member
Registered: 2014-11-29
Posts: 6

Re: What graphic library should I use for a c++ program?

First: Thanks a lot for all your replies and suggestions!
Second: Ahhh! So many options!   :)

To be more clear, as I said, I only need simple graphics output. I don't need an interface.
That's why I did not consider GTK or QT. I'm sure the gimp tool kit can do simple graphics :)
... but I thought there should be something simpler, easier to use.

I really like the suggestion of progandy. The idea to just produce text output to an svg file and then "watch" this file with an other program is really neat.
It would perfectly fit my needs, if it would be fast :)
But I will keep that in mind, maybe for some other project.

ewaller wrote:
"What do you need from a tool kit besides simple graphics? "

Nothing

"Do you need cross platform capability?"

No.

"Do you care about license? Are you going to distribute this?  Is this going to be Free or proprietary?"

It is just a personal project I do for fun/interest. I don't expect anybody else ever run it. So it only needs to run on my arch 64bit system.
But it has actually potential ... if I finally manage to write it :)

drcouzelis wrote: "What are you making?"

It is a simulation of simple life forms in a simple world. It is a simulation of evolution, as the lifeforms can reproduce and mutate by doing this. They can also die of course (by hunger, by dotage or by getting killed and maybe eaten). So there you have mutation and selection.

The graphics I need is only to watch little triangles of different colors wander around and eat green hexagons or each other, basically.
... or keep running against a wall till they die in earlier stages, or after some unlucky mutation :)

I would like to be able to watch bigger populations (several thousand) of these triangles moving around. That's why I need it to be fast.

Last edited by niva (2015-01-27 23:33:27)


Don't panic!

Offline

#11 2015-01-27 23:55:50

thiagowfx
Member
Registered: 2013-07-09
Posts: 586

Re: What graphic library should I use for a c++ program?

I believe you already know this, but...here it is: https://en.wikipedia.org/wiki/Conway's_Game_of_Life
It could help or inspire you somehow.

Offline

#12 2015-01-27 23:57:28

hipersayan_x
Member
Registered: 2014-12-09
Posts: 36
Website

Re: What graphic library should I use for a c++ program?

niva wrote:

To be more clear, as I said, I only need simple graphics output. I don't need an interface.
That's why I did not consider GTK or QT. I'm sure the gimp tool kit can do simple graphics smile
... but I thought there should be something simpler, easier to use.

You don't need a GUI to render a frame in Qt, and probably is the same with GTK.

Offline

#13 2015-02-02 19:02:52

niva
Member
Registered: 2014-11-29
Posts: 6

Re: What graphic library should I use for a c++ program?

Thanks again for your feedback!

I have decided to use SDL 2, seem to me most fitting for this purpose and also something I might use in the future, when I need some graphics.

@ thiagowfx: Yes I know about Conways "Game of live". It is quite different from what I  want to do. It has not much to do with live. Conways himself does not think the name is fitting ( nice interview with him: https://www.youtube.com/watch?v=E8kUJL04ELA ).

@ hipersayan_x: Sure I know. But I also don't want to install GTK or Qt on my system. I would guess at least it is far bigger then SDL 2.

Ok, will work on it now. Can't wait to see it running, to see my simple life forms on my screen smile

Cheers
niva


Don't panic!

Offline

#14 2015-02-02 19:20:31

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: What graphic library should I use for a c++ program?

Thanks for following up. I agree, SDL is a good choice, and I like how SDL is available for pretty much everything. I forgot SDL 2 had even been released. tongue

...on a side note, how do you use your computer without GTK or Qt??

Offline

#15 2015-02-02 19:46:26

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,331
Website

Re: What graphic library should I use for a c++ program?

drcouzelis wrote:

how do you use your computer without GTK or Qt??

Quite happily, I suspect wink

At the moment I'm using firefox as my main browser, but that is the only thing on my computer that requires one of the toolkits.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#16 2015-02-06 21:03:38

DraKoN
Member
Registered: 2015-02-06
Posts: 1

Re: What graphic library should I use for a c++ program?

For C++ graphic Library:
      for 3D you can use OpenGL
      else to SDL you can use SFML witch the C++ equivalent for SDL.
      Indeed Qt is mainly use for graphic interfaces but not just for it. You can do all what you want in Qt using QGraphicScene etc...

Offline

#17 2015-02-07 06:43:01

mpan
Member
Registered: 2012-08-01
Posts: 1,371
Website

Re: What graphic library should I use for a c++ program?

If you truly want to stick to C++ or using C library from within C++, I would vote for SDL too. I don't think you can find better choice for a native library that is very easy, well documented, stable and cross-platform.

However, I would consider two other options.

First, if you don't need live output, think about progandy's suggestion of outputting an image to a file. And the image file may be as simple as PBM/PGM/PPM. You need no external library for that.

Second, if you don't need to stick to C++ only: consider Processing2. A pretty good quick-and-dirty visualisation language based on Java, with capability to seamlessly interface with any other JVM language and technology (including JNI, if you truly need it).


Sometimes I seem a bit harsh — don’t get offended too easily!

Offline

Board footer

Powered by FluxBB