Jump to content
  • Advertisement
Sign in to follow this  
Silverclaw

OpenGL Initializing OpenGL on multiple platforms

This topic is 4409 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

I have a project on MS VC++ and wanted to make it multiplatform. I suppose that VC++ spacial commands such as "__assume()" and "__restrict" won't work on the GCC compiler (is that the name of GNU C++ compiler?). As such, I am removing such references but stumbled on another problem. The OpenGL Linux initialization code, how do I do it? I mean, without having to change code for every release? Is there a #define that the compiler does to identify the current platform? Like:
#ifdef windows
#include "windows.h"
#include "gl/gl.h"
#define allow_VC_specifcs
#endif

#ifdef linux
#include "OpenGL/gl.h"
#include linux headers....
#endif
and during the code I put in some #ifdefs to change the init code. I'd rather not use GLUT or SDL or any SDK because I believe it to be faster (and educative) to make the init code all by myself. Second question, how do I init gl on Linux? I have searched a bit and haven't found anything yet, but I really haven't tried that hard, gonna resume later today. I'm going through all this hasle because I want my porject to have as least dependencies as possible. Btw, to I _have_ to be dependent on X Window System to init HW accelerated OpenGL? Any links will be welcome, thank you for your time. ___________________________________________________

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Quote:
Education is the progressive discovery of our own ignorance....I'd rather not use GLUT or SDL or any SDK because I believe it to be faster (and educative) to make the init code all by myself.

http://nehe.gamedev.net/data/lessons/linuxglx/lesson02.tar.gz

Share this post


Link to post
Share on other sites
There is opengl basecode for Linux on NeHe. Also, if you go to lesson1 there is a link to a linux version. I used this as a base for my project which can be built for linux or windows.
I think that you do need to use the X windows because thats what the drivers are built to use but you don't actually have to startx as a full desktop environment. You can run your application from a shell (in run-level 3 for example) by using the xinit command. This will start X, run your application and then close X when your program finishes.


Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Don't use GLX, instead use something like SDL (libsdl.org), which will handle all your video initialisation (along with event management, etc) on multiple platforms. It has an SDL_opengl.h header that abstracts away inclusion of GL headers on multiple platforms.

Share this post


Link to post
Share on other sites
Thanks a lot! I didn't notice the Linux version of the tutorials! Sorry for that one :P

Anyway can you tell me about the first part of my post, the "#ifdef" stuff?

Share this post


Link to post
Share on other sites
I try to avoid using lots of #define for compiling for multiple platforms. This is a personnal thing as I find the code starts to look really messy. I tend to split the code into multiple files, one to contain code common to all platforms and then one each per platform and then just include the relevant files in your makefile/project. I think it's all down to personnal preference at the end of the day.

If you want to use #define then you can specify a #define to the compiler, I think gcc uses -D so you could add -D_LINUX to your compiler options in your makefile. You can do the same thing in visual studio in the preprocessor section of the project properties.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
Don't use GLX, instead use something like SDL (libsdl.org), which will handle all your video initialisation (along with event management, etc) on multiple platforms. It has an SDL_opengl.h header that abstracts away inclusion of GL headers on multiple platforms.


I totally agree. The people who wrote SDL have already done this work. Also, they have tested it on more than just windows and linux [smile].

Also, the code you write will not be noticeably faster than the SDL code. It doesn't do the platform check at runtime or anything. Besides, you only initialize OpenGL once.

[Edited by - Simian Man on November 16, 2006 2:21:53 PM]

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!