OpenGL under linux

Hi everyone,

Does anyone know of any site that teaches you OpenGL under Linux without using the GLUT library?

All the tutorials that I have seen uses the GLUT library and I need to avoid using it due to certain constraints.

Thanks and cheers,
xargy

there are many tutorials, for example at http://nehe.gamedev.net
many tutorials were ported to different platforms, libs, etc.
take a look at: http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=07
at the bottom of the page you 'll find a version for
‘Linux/GLX’ and ‘Linux/SDL’.

http://www.libsdl.org
is a very handy lib for writing portable apps with OpenGL.

Yes, but they use the GLUT library.

I am not interested in platform independence. I just want to see how to initialize OpenGL under LINUX without using 3rd party libraries.

frohes fest…

#include<stdlib.h>
#include<X11/Xlib.h>
#include<GL/glx.h>
#include<GL/glu.h>

Display                 *dpy    = XOpenDisplay(NULL);
Window                  root    = DefaultRootWindow(dpy);
GLint                   att[]   = { GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None };
XVisualInfo             *vi     = glXChooseVisual(dpy, 0, att);
GLXContext              glc     = glXCreateContext(dpy, vi, NULL, GL_TRUE);
Colormap                cmap    = XCreateColormap(dpy, root, vi->visual, AllocNone);
int                     cmask   = CWColormap | CWBorderPixel | CWEventMask;
int                     emask   = ExposureMask | KeyPressMask;
Window                  win;

void DrawAQuad() {
 XWindowAttributes      gwa;

 XGetWindowAttributes(dpy, win, &gwa);

 glViewport(0, 0, gwa.width, gwa.height);
 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_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();

 glXSwapBuffers(dpy, win); }

void ExitProgram() {
 glXMakeCurrent(dpy, None, NULL);
 glXDestroyContext(dpy, glc);
 XDestroyWindow(dpy, win);
 XCloseDisplay(dpy);
 exit(0); }

int main(int argc, char *argv[]){
 XSetWindowAttributes   swa;

 swa.colormap           = cmap;
 swa.border_pixel       = 0;
 swa.event_mask         = emask;
 win                    = XCreateWindow(dpy, root, 0, 0, 400, 400, 0, vi->depth, InputOutput, vi->visual, cmask, &swa);
 XStoreName(dpy, win, "VERY SIMPLE");
 XMapWindow(dpy, win);

 glXMakeCurrent(dpy, win, glc);
 glEnable(GL_DEPTH_TEST);
 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(true) {
        XEvent  xev;

        XNextEvent(dpy, &xev);

        if(xev.type == Expose) {
                DrawAQuad(); }

        else if(xev.type == KeyPress) {
                ExitProgram(); } } }

//
// gcc -I/usr/X11R6/include/ -L/usr/X11R6/lib -o Simple Simple.cc -lX11 -lGL -lGLU
//
 

Originally posted by xargon:
[b]Yes, but they use the GLUT library.

I am not interested in platform independence. I just want to see how to initialize OpenGL under LINUX without using 3rd party libraries.[/b]
rubbish - the Linux/GLX example DOES NOT use GLUT nor any other “3rd party libraries”.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.