You are not logged in.

#1 2005-03-01 15:12:16

ovihc
Member
Registered: 2004-06-16
Posts: 62

OPENGL & gcc

I found a Nene Tutorial for opengl on his website. he has written a tutorial on learning OPENGL. however, his tutorials cover opengl in windows environments, not linux. therefore, he doesn't go through the steps of creating the developing environment for OPENGL.

he has an example that is easy (example1), the code is simple, probably just 20 lines or so. however, when i compile with gcc, i get errors. i'm in school right now, not at home so i can't remember what I typed. my question is just this:

what packages and sources do I need to compile opengl source?
-mesa?, glut? (btw, what is glut? i read descriptions but i just can't understand.)

if anyone has had experience compiling opengl source code, what are the arguments *generally* given to gcc?

Offline

#2 2005-03-01 15:42:16

i3839
Member
Registered: 2004-02-04
Posts: 1,185

Re: OPENGL & gcc

It's probably best to use something like SDL.

Offline

#3 2005-03-01 16:09:52

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: OPENGL & gcc

gcc -o file -Wall -lglut -lGL -lGLU file.c

the GL headers should be there with X

Offline

#4 2005-03-02 14:32:36

ovihc
Member
Registered: 2004-06-16
Posts: 62

Re: OPENGL & gcc

to i3839:
if i use SDL, i probably need to rewrite the code, right?

to phrakture:
i used the command that you supplied. when i run it as:

gcc -o example1 -Wall -lglut -lGL -lGLU open1.c

i get:

/usr/bin/ld: cannot find -lglut
collect2: ld returned 1 exit status

i ran ldconfig as root and i still got the same error.

my system:
gcc 3.4.3-1
2.6.10-ARCH

Offline

#5 2005-03-02 15:48:56

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: OPENGL & gcc

ovihc wrote:

to phrakture:
i used the command that you supplied. when i run it as:

gcc -o example1 -Wall -lglut -lGL -lGLU open1.c

hmm, well you only need lib flags for the libraries you're using... are you using glut? (probably not, I never have) try just -lGL and -lGLU

Offline

#6 2005-03-02 17:05:44

i3839
Member
Registered: 2004-02-04
Posts: 1,185

Re: OPENGL & gcc

ovihc wrote:

to i3839:
if i use SDL, i probably need to rewrite the code, right?

You probably need to do that anyway, but mostly the init stuff like getting a graphical context and opening a window etc.

Offline

#7 2005-03-02 17:21:28

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: OPENGL & gcc

i3839 wrote:
ovihc wrote:

to i3839:
if i use SDL, i probably need to rewrite the code, right?

You probably need to do that anyway, but mostly the init stuff like getting a graphical context and opening a window etc.

Writing in OpenGL or SDL doesn't matter - use what you want...

Offline

#8 2005-03-02 17:30:07

i3839
Member
Registered: 2004-02-04
Posts: 1,185

Re: OPENGL & gcc

As far as I know, SDL doesn't replace anything from the OpenGL API, it just adds general functionality which is needed anyway and platform specific, like opening windows, configuring a graphical context, sound, mouse/keyboard input, etc. and other things not done by OpenGL.

The question is wether to use SDL or Glut, if the example code uses glut anyway, which is unclear.

Offline

#9 2005-03-02 17:38:18

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: OPENGL & gcc

For the record, there are NeHe tutorial for Linux/SDL as well. For example:

http://nehe.gamedev.net/data/lessons/li … n02.tar.gz

Dusty

Offline

#10 2005-03-03 10:05:39

ovihc
Member
Registered: 2004-06-16
Posts: 62

Re: OPENGL & gcc

i'm reading the OPENGL RED BOOK. all their examples use GLUT.

for example:

/*
/*
 * hello.c
 * This is a simple, introductory OpenGL program.
 */
#include <GL/glut.h>

void display(void)
{
/* clear all pixels  */
   glClear (GL_COLOR_BUFFER_BIT);

/* draw white polygon (rectangle) with corners at
 * (0.25, 0.25, 0.0) and (0.75, 0.75, 0.0)  
 */
   glColor3f (1.0, 1.0, 1.0);
   glBegin(GL_POLYGON);
      glVertex3f (0.25, 0.25, 0.0);
      glVertex3f (0.75, 0.25, 0.0);
      glVertex3f (0.75, 0.75, 0.0);
      glVertex3f (0.25, 0.75, 0.0);
   glEnd();

/* don't wait!  
 * start processing buffered OpenGL routines 
 */
   glFlush ();
}

void init (void) 
{
/* select clearing color  */
   glClearColor (0.0, 0.0, 0.0, 0.0);

/* initialize viewing values  */
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
}

/* 
 * Declare initial window size, position, and display mode
 * (single buffer and RGBA).  Open window with "hello"
 * in its title bar.  Call initialization routines.
 * Register callback function to display graphics.
 * Enter main loop and process events.
 */
int main(int argc, char** argv)
{
   glutInit(&argc, argv);
   glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
   glutInitWindowSize (250, 250); 
   glutInitWindowPosition (100, 100);
   glutCreateWindow ("hello");
   init ();
   glutDisplayFunc(display); 
   glutMainLoop();
   return 0;   /* ANSI C requires main to return int. */
}

then i type in:

gcc -o hello -Wall -lglut -lGL -lGLU hello.c 

RESULT:

/usr/bin/ld: cannot find -lglut
collect2: ld returned 1 exit status

then i type in:

gcc -o hello -Wall  -lGL -lGLU hello.c

RESULT:

/tmp/ccGHDkOj.o(.text+0x15c): In function `main':
: undefined reference to `glutInit'
/tmp/ccGHDkOj.o(.text+0x168): In function `main':
: undefined reference to `glutInitDisplayMode'
/tmp/ccGHDkOj.o(.text+0x17c): In function `main':
: undefined reference to `glutInitWindowSize'
/tmp/ccGHDkOj.o(.text+0x190): In function `main':
: undefined reference to `glutInitWindowPosition'
/tmp/ccGHDkOj.o(.text+0x19c): In function `main':
: undefined reference to `glutCreateWindow'
/tmp/ccGHDkOj.o(.text+0x1ad): In function `main':
: undefined reference to `glutDisplayFunc'
/tmp/ccGHDkOj.o(.text+0x1b2): In function `main':
: undefined reference to `glutMainLoop'
collect2: ld returned 1 exit status

then i type in:

gcc -o hello -Wall  -lGL  hello.c

RESULT:

/tmp/ccay73p0.o(.text+0x15c): In function `main':
: undefined reference to `glutInit'
/tmp/ccay73p0.o(.text+0x168): In function `main':
: undefined reference to `glutInitDisplayMode'
/tmp/ccay73p0.o(.text+0x17c): In function `main':
: undefined reference to `glutInitWindowSize'
/tmp/ccay73p0.o(.text+0x190): In function `main':
: undefined reference to `glutInitWindowPosition'
/tmp/ccay73p0.o(.text+0x19c): In function `main':
: undefined reference to `glutCreateWindow'
/tmp/ccay73p0.o(.text+0x1ad): In function `main':
: undefined reference to `glutDisplayFunc'
/tmp/ccay73p0.o(.text+0x1b2): In function `main':
: undefined reference to `glutMainLoop'
collect2: ld returned 1 exit status

however, i tried the nehe tutorial that uses sdl, and it works perfectly!!
am i stuck with SDL(not a bad thing of course)?
-am i typing in the wrong GCC command?
-what are the differences in sdl and glut? is sdl better? would it help me -more to learn sdl instead of glut?[/b]

Offline

#11 2005-03-03 16:00:25

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: OPENGL & gcc

SDL is better than glut, but that's just opinion... the compilation is failing because it can't find glut... try a "pacman -Ss glut" and see if it's a seperate package (I don't know if it is...)

Offline

#12 2005-03-03 16:05:09

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: OPENGL & gcc

phrakture wrote:

SDL is better than glut, but that's just opinion... the compilation is failing because it can't find glut... try a "pacman -Ss glut" and see if it's a seperate package (I don't know if it is...)

glut is a separate package, yes.

Offline

Board footer

Powered by FluxBB