Starting OpenGL In Linux

Recommended Posts

Halsafar    205
http://www.opengl.org/resources/faq/getting_started.html This page is confusing me. What do I need to start programming for OpenGL using C++ in Linux. It says I may need some Mesa OpenGL-Work-Alike... But I know my current configuration can run openGL apps just fine (Cedega tests for example). I assume I need an SDK of somesort... Otherwise I'm beginning with the all-to-famous NEHE tutorials :)

Share on other sites
rip-off    10976
if other GL apps work fine i think all is in order.

check /usr/include for GL headers. if they're not there then you will need them

just remember the includes and (if using gcc on command line) the relevant -l things.( i cant quite remember them... )

Share on other sites
Halsafar    205
Well I checked that directory and there are no includes files which start with GL or resemable anything like openGL.

I do know I have OpenGL up and running tho, Cedega demands an OpenGL test before running, it showed a window up and some gears turning, this ran at 1000fps on my system.

By relevant -l commands, care to elaborate?

Thanks,
Halsafar

Share on other sites
MaulingMonkey    1728
Quote:
 Original post by HalsafarWell I checked that directory and there are no includes files which start with GL or resemable anything like openGL.

They'd all be in a subfolder labeled GL (GL/gl.h, GL/glu.h, GL/glut.h are common ones)
Quote:
 By relevant -l commands, care to elaborate?

These tell GCC what to link. For example, if I wanted to do some programming using libglut.so, I'd comple using something like:
gcc -lglut example.cpp -o example

-L flags may also be necessary to specify where a library file is, for example:
gcc -L/usr/X11R6/lib -lX example_xwindows_program.cpp -o example

Share on other sites
rip-off    10976
i havent tested this, im under windows at the minute, but something like this

(if anyone does know, please post )

g++ -o program source.cpp -lGL -lGLU

the second one is if you use GLutilites.

i think theres one for the GLaux utilites but im not 100% sure...

Share on other sites
markr    1692
NeHe's tutorials mostly are targetted at wgl hence use user32 and are win32 gui apps.

But the principles apply, and many have been ported to Linux, with or without the use of SDL or something else.

The easiest way to get apps working is to use glut. glut is not really very good for games, but works.

The exact libraries you need to link a GL application might vary slightly, but the following works for me:

LIBRARIES = -lX11 -lXi -lXmu -lSDL -lGL -lGLU -lm
LIBDIR = -L/usr/X11R6/lib -L/usr/local/lib

Some of these are probably unnecessary. Don't use -LSDL if you're not using SDL.

Mark

Share on other sites
erissian    727
There seems to be a little debate, but it really isn't too complex.

If you need the gl library (which you most definitely do), then use:
#include <GL/gl.h>
-lGL
to the compiler flags. (If you link manually, then do it then)

If you need the glu library, use:
#include <GL/glu.h>
and
-lGLU

For glut:
#include <GL/glut.h>
-lglut

That's it for the OpenGL library. If you use additional libraries, then you have to include those too, of course.

Share on other sites
Halsafar    205
Well to be honest I'm not getting anywhere with this heh.
Its not the compiling, I just cannot find a tutorial which even answers my simple questions... Like how do I create the window, what do I use to do it... Well and I cannot compile any of the source I do find :)
missing gltk.h on most.

Edit:
Okay I need GLUT.... I cannot find the Linux download on the opengl main webpage... I can only locate the Win32 Source.

Share on other sites
Richy2k    313
What distro of linux are you using? I didnt have a problem getting GL up and running fine in Arch or Gentoo, some distros fiddle with where the files are put (SuSE..)

Share on other sites
Halsafar    205
I am using Mandriva 2006.
OpenGL is installed and all its headers are there.
I found GLUT, installed it.

All the headers exist in /usr/inclue/GL/.

Anything I plainly compile gives me tons of missing reference errors. Which is where I came back here to find the flags you guys dicussed.

None of them work, I've tried everything here and all I get is missing reference errors on every call to a GL or GLUT function. This leads me to believe I do not have the OpenGL Libraries... the Devel I guess. But I know opeNGL works, Mandriva 2006 has a test feature for it, and Cedega works 'kinda' well.

Share on other sites
Halsafar    205
Do I HAVE to use MESA to program for openGL?

Share on other sites
erissian    727
Glut is in kind of a weird place. If you are downloading Mesa, then make sure to download the source AND the demo package. Glut is in the demo package. Extract both tars into the same directory, and then ./configure && make && su -c "make install"

It's really not obvious at all, so it was a little frustrating for me until I finally found it myself.

Share on other sites
Halsafar    205
Okay:

gcc lesson1.c -L/usr/local/lib -L/usr/lib -lglut
gcc -o homer lesson1.o -L/usr/local/lib -L/usr/lib -lglut

'homer' booted just fine. Given lesson1, all it did was show up a blank screen, escape closing it.

SO, my FINAL question:

Why the heck did adding ONLY glut and removing the openGL libraries FIX THIS!!!

All the other methods posted in here produced nothing but missing reference or missing library '/usr/bin/ld the linker was freakin out'

Edit: AND NOW MY COMPILER OF CHOICE, Intel 'icc' won't work.
IPO Error: unresolved : glClearColor() for example.

Share on other sites
Halsafar    205
HAHAHA I THINK I SOLVED IT!!!

All the OpenGL libraries where located in
/usr/X11R6/lib/

So I copied the libG*.so (which ended up being about 8 openGL named files) to:
/usr/lib

Now I can link the libraries properly like you guys have been informing me at least.

Share on other sites
RobTheBloke    2553
use -L/usr/X11r6/lib/ before any -lglut or -lGL flags. Most of my openGL examples contain linux makefiles, you might find some of them kinda useful link

Share on other sites
Halsafar    205
Hey thanks, nice site.
I'll be sure to include it in my learning curve :)