Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: run opengl on Linux

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2005
    Location
    Dhaka
    Posts
    1

    run opengl on Linux

    I am working on redhat 9.1. But, I don't know how to add opengl file on linux.

  2. #2
    Intern Contributor
    Join Date
    Apr 2002
    Location
    Spain
    Posts
    66

    Re: run opengl on Linux

    Originally posted by Iqbal_Hossain:
    I am working on redhat 9.1. But, I don't know how to add opengl file on linux.
    Include the files <GL/gl.h>, <GL/glu.h> as usual and link with -lGL and (if you need GLU) -lGLU

  3. #3
    Advanced Member Frequent Contributor
    Join Date
    Aug 2004
    Location
    munich, germany
    Posts
    658

    Re: run opengl on Linux

    if you only want to run an opengl prog, you just need the libraries. to test if the libs are properly installed, try to run glxgears (hopefully installed on your system).

    if glxgears doesn't work, try

    ldd /usr/X11R6/bin/glxgears

    ldd shows you which libraries you need to run a program.

    if you want to develop, you additionally need the header files (gl.h, glx.h, glu.h).

    if you have an nvidia card, go to www.nvidia.com and download the latest linux driver. you'll find the header files in

    /usr/share/doc/NVIDIA_GLX-1.0/include/GL/

    when you've installed the driver.

    an alternative is using MESA, which is a non-accelerated software GL lib. it should be included in your redhat distribution.

  4. #4
    Guest

    Re: run opengl on Linux

    is there a hello world example for opengl? i'm an experienced program just wanting to fool with it for fun. thnx

  5. #5
    Advanced Member Frequent Contributor
    Join Date
    Aug 2004
    Location
    munich, germany
    Posts
    658

    Re: run opengl on Linux

    there you are...

    Code :
    #include<X11/Xlib.h>
    #include<GL/glx.h>
    #include<GL/glu.h>
     
    Display			*dpy 	= XOpenDisplay(NULL);
    Window			root 	= DefaultRootWindow(dpy);
    GLint                   att[] 	= {GLX_RGBA, None};
    XVisualInfo             *vi   	= glXChooseVisual(dpy, 0, att);
    GLXContext              glc   	= glXCreateContext(dpy, vi, NULL, False);
    Visual                  *vis  	= DefaultVisual(dpy, 0);
    Colormap                cmap  	= XCreateColormap(dpy, root, vis, AllocNone);
    unsigned int		w 	= XDisplayWidth(dpy, 0) / 2;
    unsigned int		h 	= XDisplayHeight(dpy, 0) / 2;
    int                     dep   	= DefaultDepth(dpy, 0);
    int                     cmask 	= CWColormap | CWBorderPixel | CWEventMask;
    int                     emask 	= ExposureMask;
    XEvent			xev;
    XSetWindowAttributes	swa;
    XWindowAttributes	gwa;
    Window			win;
     
    int main(int argc, char *argv[]){
     
     swa.colormap     	= cmap;
     swa.border_pixel 	= 0;
     swa.event_mask   	= emask;
     win              	= XCreateWindow(dpy, root, 0, 0, 400, 400, 0, dep, InputOutput, vis, cmask, &amp;swa);
     XStoreName(dpy, win, "SIMPLE GL QUAD");
     XMapWindow(dpy, win);
     
     glXMakeCurrent(dpy, win, glc);
     glClearColor(0.00, 0.00, 0.60, 1.00);
     
     glMatrixMode(GL_PROJECTION);
     glLoadIdentity();
     glOrtho(-1., 1., -1., 1., 1., 100.);
     
     glMatrixMode(GL_MODELVIEW);
     glLoadIdentity();
     gluLookAt(0., 0., 10., 0., 0., 0., 0., 1., 0.);
     
     while(1) {
    	XNextEvent(dpy, &amp;xev);
     
    	if(xev.type == Expose) {
     
    		XGetWindowAttributes(dpy, win, &amp;gwa);
    		w = gwa.width;
    		h = gwa.height;
     
     		glViewport(0, 0, w, h);
    		glClear(GL_COLOR_BUFFER_BIT);
     
    		glBegin(GL_QUADS);
    		 glColor3f(1., 0., 0.); glVertex3f(-.75, -.75, 0.);
    		 glColor3f(0., 1., 0.); glVertex3f( .75, -.75, 0.);
    		 glColor3f(0., 0., 1.); glVertex3f( .75,  .75, 0.);
    		 glColor3f(1., 1., 0.); glVertex3f(-.75,  .75, 0.);
    		glEnd();
     
    		glFlush(); } } }
    //
    // gcc -I/usr/X11R6/include/ -L/usr/X11R6/lib -o SimpleQuad SimpleQuad.cc -lX11 -lGL -lGLU
    //

  6. #6
    Senior Member OpenGL Pro
    Join Date
    Jul 2001
    Location
    France
    Posts
    1,749

    Re: run opengl on Linux

    The example RigidBody gave doesn't say 'hello world' but that's it

  7. #7
    Junior Member Newbie
    Join Date
    Jun 2005
    Posts
    3

    Re: run opengl on Linux

    Also you can test GLUT to avoid direct interaction with X.

    To use glut,

    #include<GL/glut.h>

    and
    -lgut when linking.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •