I want to do some graphics programming with gcc, and am wondering which is the best graphics libary to use.
Cheers Mick
Printable View
I want to do some graphics programming with gcc, and am wondering which is the best graphics libary to use.
Cheers Mick
C standard library != graphics library. You already have a c standard library, most of your system depend on it. For graphics library check SDL for 2D and OpenGL for 3D. If you want to write GUI, read about Qt (C++, used by KDE) or Gtk (C, used by Gnome, pain in arse).
I used synaptic to download libsdl1.2-dev and tried to compile a sample file, but the headers were not recognised.
:|
Cheers Mick
Are the headers located in some directory which is in your include path?
There is a pretty good guide for setting up and creating a simple test program at lazyfoo.net.
Just skip the part about downloading and installing the rpm since you have already installed the deb.
If your using automake && autoconf
Then just copy
to your Makefile.amCode:<insert_var_here>_LDADD = -lSDL
I believe SDL is a C++ API.
If you want to use C, just use openGL (which is the 3D graphics part of SDL) with "glut".
Nope, it's a C graphics API, so you can use it with C or C++.
Well, okay, I meant freeglut, since yes, the original glut is defunct. I've used it with all the standard docs that refer to glut (inc, eg, the OGL superbible, AND the red book). It is maintained and it works perfectly. I believe everything that was in glut is in freeglut*, I've seen this stated a number of times and never heard anything to the contrary, so you are are full of tish on this. If you go to the official openGL forum and make this claim, you will get laughed off the page. Sorry. Freeglut is widely used, and it functions identically w/r/t any documentation that includes glut (which is most or all OGL documentation for beginners).
@mickpc: you need to use linker flags, eg for OGL/glut:
gcc test.c -lglut -lGLU -lGL -lXext -lX11 -lm
Maybe some nice person will post the flags for SDL; if not I am sure they are on page one of the intro tutorial or whatever...
* in any case, IMO you might as well keep your use of glut to a minimum; all it has to do is manage a window and an event loop. This way, when you want to really polish up and handle your own loop and window management, you will not find you have written something that involves a lot of higher-level functions from a secondary toolkit. The point of glut is just to allow you to do pure OpenGL programming easily. It is not to add a whole bunch of features like sound effects or whatever. It is a "low level" approach vs. the "high level" of SDL, which is it's own thing that potentially includes OGL -- whereas glut doesn't do anything except provide a cross-platform for OGL. It is and should be minimal. I have nothing against SDL, just this is apples and oranges. AFAICT (I have written a simple patch for tuxpaint, which is an SDL kid's game), you can do all kinds of stuff with SDL that really have absolutely nothing to do with 3D graphics programming.
kennedy != graphics programmer PERIOD!!!
. . . but, I thought that GTK was considered the "standard"?
SDL is written in C, but it has bindings for frigging many languages. But basically it's a C library.
GTK is "standard" widget toolkit on GNU, because it's used by GNOME.
Portable graphics programming => SDL with OpenGL.
Non-portable graphics programming for Unix-likes => Xlib, GLX, GLUT or whatever you want.
Portable GUI => if you want C++, Qt, if you don't, just do it or suffer.
Qt is not the only portable C++ gui toolkit. I use wxWidgets almost exclusively for gui stuff, and it's everything I need and more. it includes OpenGL stuff as well, and is certainly worth looking into if you want a truly cross-platform gui toolkit with OpenGL capability.
Actually GTK is cross-platform as well. AFAIK, glut is not tho [edit: wrong]. The GTK openGL extension does not appear to use glut.
YES! Sorry, you are correct. All those books were not written just for linux users!
I was mixed up slightly because of course the chapters on "OGL without glut" are divided into linux, windows, and mac. I had it in my head I'd just been following the linux part, silly me.
So yeah, that is the further point of glut -- to provide a uniform standard for the window management...however, this may be where the glut/freeglut distinction became an issue, since originally freeglut may not have been available for windows (methinks it is now), qv:
http://freeglut.sourceforge.net/index.php#download
Which basically explains that it is a 100% compatible replacement AND that it is an improvement. In my experience, there are no issues there. zacs7 is just a silly fool.
Oh come on. If you are worth your salt, you can deal with the treeview! After that it is mostly tea and crumpets.
Plus Qt is butt-ugly :p
Vis, "so much more", GTK is build on glib which is built with pthreads, I think these are portable too. glib is quite a monster if you like built in complex datatypes, threaded timers, threaded file handle/socket monitors, etc.
Qt looks almost like I want my C++ class libraries look like. But this is just matter of taste.
I'm rather positive that glut works on Linux, Mac, and Windows (maybe others, IDK).
@OP
To compile via command line without make just use
However, I suggest you get acquainted with an IDE or learn to use automake && autoconfig as they will make your life much easier.Code:g++ -o myprogram mysource.cpp -lSDL
Check out lazyfoo for great SDL tutorials.
Checkout VTR for good Glut/OGL tutorials.
Also, I'm just starting to learn c++, so I would not call myself a graphics expert (or any other sort of expert). So take any advice I give you with caution ;)
cs_student
2D graphics with the SDL: The SDL is a cross-platform C library with bindings to other languages. One of my favourites.
I'll recommend the Lazy Foo tutorials a third time. Compiling an SDL program is usually done with a command line like
If you're lazy like me, you could probably get away withCode:$ gcc `sdl-config --cflags` *.c -o program `sdl-config --libs`
The command-line suggested above, namelyCode:$ gcc -I /usr/include/SDL *.c -o program -lSDL
works too if you #include <SDL/SDL.h>, but not if you use <SDL.h> or "SDL.h". The latter is recommended.Code:g++ -o myprogram mysource.cpp -lSDL
3D graphics with OpenGL: OpenGL is just the way to go if you want 3D graphics.
You can use [free-]glut if you like, or the SDL, or Qt to provide a wrapper around your OpenGL code. Those three are just the ones I've used, there are certainly others. Freeglut is definitely the simplest, I'd suggest starting there.
Compiling an OpenGL program can usually be done with a command-line like
Add -lGLu if you're using GLu, and add -lglut if you're using [free-]glut.Code:$ gcc *.c -o program -lGL
GUI programming with Qt: I must say I've never used Qt 4 to any large degree, but I have used Qt 3, and it's a very nice toolkit. Qt is C++, cross-platform, and with a large number of available widgets built-in. Qt 3 is apparently a pain to get to work on Windows, but I assume Qt 4 is easier.
GUI programming with GTK+ or wxWidgets: Sorry, never tried those, I can't really help you there. GTK+ is a C library, and wxWidgets is a C++ one.
Yes, everyone does. But those are C++ tutorials, the OP is asking about C.Quote:
I'll recommend the Lazy Foo tutorials a third time.
There is very little material on SDL in C on the web, beyond their official stuff (which is good):
http://sdl.beuc.net/sdl.wiki/HelpContents
I also have a long, well put together, very in-depth HTML'ified thing called the "SDL Library Documentation", but I do not know where I got it -- the only thing I've done with SDL was the tuxpaint patch hack, and that helped much there.
I notice that if you google "SDL Library Documentation" there are some possible online & pdf versions around.
I have a suspicion the people who did that (SDLdoc) created the help wiki since some of the text is word for word, while the old SDLdoc address is defunct.
And, once again, if you are using OGL with glut on linux, you need to link to X as well:
gcc test.c -lglut -lGLU -lGL -lXext -lX11