Portability

Started by
21 comments, last by swiftcoder 16 years, 2 months ago
OpenGL is supposed to be multi-platform. How come I have to include windows.h for it to work? How would I solve this to become multi platform?
Advertisement
Use GLUT for windowing. http://www.opengl.org/resources/libraries/glut/
I do not want to use GLUT.

Both that I heard it's bad for game development for some reasons and I also want to be able to do it myself instead of leaving everything to external libraries.

I do it because of the learning experience.
Use preprocessor commands?
http://3d.benjamin-thaut.de
sounds good, how would you go about doing it ?

Can you give me a small (pseudo) code example?
OpenGL is platform independent. However, the layer between OpenGL and the operating system is not. For example, the layer between OpenGL and Windows, wgl, requires Win32-platform dependent code. The layer between OpenGL and X, glx, requires X-platform dependent code.

You need platform dependent code to setup a window, create frame buffers, create a rendering context and so on. Once that is done, OpenGL kicks in and your platform independent code begins.
But when I want to use OpenGL code anywhere in my program, I need:
#include "Windows.h"#include "GL/gl.h"#include "GL/glu.h"


Without the windows I'll get tons of errors.
That's because you're using Windows, and the OpenGL implementation for Windows requires some parts from windows.h. If you're compiling on another platform, you don't need windows.h, but likely some other platform specific header.
ahh alright cool thanks.

So does every platform has it's own gl.h? because I think I see some references to windows in mine.

WINGDIAPI void APRIENTRY glFunction(params);

Or am I wrong?
You could use QT, but most people do something along the lines of

#ifdef _WIN32
#include <windows.h>
endif

#ifdef _MAC_OSX
//#include mac stuff
#else //Must be a Linux Type
//include xll stuff
#endif

I'm not sure on the exact code, but something like that will work. Have a look at the GLEE source code and it should have the right preprocessor stuff because its supported on pretty much every operating system.

Neutrinohunter

This topic is closed to new replies.

Advertisement