#include window.h replacement for linux

Hello everyone,

Thanks for your time.

I am taking a course in openGL where the teacher is providing all his source code examples with the following include and comment.

#include <windows.h> // use proper includes for your system

Which includes will replace the windows.h?

I am running fedore core 3 in KDE 3.

Thanks again.

you’ll need at minimum <X11/Xlib.h> for the
x-windows functions plus <GL/glx.h>, which
contains the interface functions between X11 and
OpenGL, and finally <GL/gl.h> with the platform-
independent GL functions.

on some implementations, you may not need to
include Xlib.h, because it is included in glx.h .

depends heavily on what gui library you want to use:

for all:
// console output, very usefull for debugging with printf
#include <stdio.h>
// string handling functions, also usefull
#include <string.h>
// std c lib. a must for a good program
#include <stdlib.h>
// if you do 3d you will mostly use sin/cos, here it goes
#include <math.h>
// for opengl this goes here (glu optional)
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glx.h>

Xlib (the lowest most possibility):
#include <X11/Xlib.h>

Gtk:
#include <gtk/gtk.h>
#include <gdk/gdkx.h>

FOX-toolkit (replace 1.4 with your version or use a macro through automake):
#include <fox-1.4/fx.h>
#include <fox-1.4/fx3d.h>

for qt i don’t know, never used it, google is your friend.

and if you want to get rid of the entire cross platform problems either use

GLUT:
#include <GL/glut.h>

or SDL, which i also didn’t use so far hence i don’t know out of my head what the headers are.

well, which libs and headers you really need
depends on the windows prog that you want to
port to linux.

i suppose the windows prog uses some functions
defined in <gl.h> (glVertex, glBegin, glEnd etc.).
those are platform independent.

what you have to care about is the windows-specific
stuff. CreateWindow for example is equivalent
to XCreateWindow (defined in <X11/Xlib.h>) in
linux. most wglFUNC have an equivalent
glXFUNC in linux (defined in <GL/glx.h>, for
example: wglMakeCurrent has to be
replaced with glXMakeCurrent.

for a simple linux opengl framework, look at this

Awesome. Thanks for the help. I was able to compile and execute my teachers openGL.

I did have a problem executing the Simple quad program you linked Rigid.

[gav@localhost week2]$ gcc quad.cpp -I/usr/X11R6/include/ -L/usr/X11R6/lib -o SimpleQuad -lX11 -lGL -lGLU
[gav@localhost week2]$ SimpleQuad
X Error of failed request: BadMatch (invalid parameter attributes)
Major opcode of failed request: 143 (GLX)
Minor opcode of failed request: 5 (X_GLXMakeCurrent)
Serial number of failed request: 19
Current serial number in output stream: 19

Any ideas?

Thanks again,

hmm…i have to admit that my prog is really bad
style :stuck_out_tongue:

instead of

Display *dpy = XOpenDisplay(NULL);

you should better use

Display  *dpy;

int main(...) {
 dpy = XOpenDisplay(NULL);

 if(dpy == NULL) {
   printf("error: no display
");
   exit(0); }

and in the same way you should check if your
XVisualInfo, GLXContext etc. are ok. i used the
short versions in the example, because the always
worked on my machine…the problem occurs when
calling glXMakeCurrent, so I think your GLXContext
is not valid.

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