Jump to content
  • Advertisement
Sign in to follow this  
Dolf

OpenGL Portability

This topic is 3869 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
sounds good, how would you go about doing it ?

Can you give me a small (pseudo) code example?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!