Skip to main content
GameDev.net gamedev.net
🔒 Locked

including windows.h but cross-platform?

Started by NewBreed Oct 6, 2006 at 4:12 PM 11 replies 3.5k views
Original Post
NewBreed
NewBreed
Hi all, I'm attempting to make my game easier to port when it comes to different platforms other than Windows. Although, to use OGL I need to include . Is there a way I can include through my compiler rather than the source code, so that the source code won't need to be modified to be recompiled on another platform. All the platform specific code (setting up the window etc...) is in a seperate project. I'm using VC2k5. Thank you! (: NB
NewBreed
NewBreed
What happened to my question!?!?! Ok... try again:

I'm wanting to make my game easier to port to different platforms other than Windows. To use OGL I need to include , although this then removes the cross platform idea of the game code. Is there a way I can include the header from the compiler without changing the code, so that way I can recompile the game code to a static library for whatever OS? My compiler is VS2K5, the platform specific code (setting up the window etc..) is in a seperate project.

Thank you! (:
NB
IFooBar
IFooBar
I don't know about including it through the compiler, but there is a way to include it through source code and not worry about changing the code when you're on a different compiler.

For msvc, you can include like this:

#ifdef _MSC_VER#  include <windows.h>#endif


_MSC_VER is only defined with visual studio, so the include will only be processed if that is defined.
[size=2]aliak.net
NewBreed
NewBreed
Hrm... some reason viewing the question only shows my reply, I'm viewing this through the "reply to topic" screen. :S

One thing, maybe I could do this:

#define WIN32_VS2K5#ifdef WIN32_VS2K5#include <windows.h>#endif#ifdef WIN64_VS2K5#include <windows.h>#endif#ifdef LINUX32_SOMELINUXCOMPILER#include SOMELINUXHEADER#endif#ifdef LINUX64_SOMELINUXCOMPILER#include SOMELINUXHEADER#endif
Conner McCloud
Conner McCloud
Or do away with preprocessor defines all together. Include one file, unconditionally. Setup your compiler to include the version of that file appropriate for the current environment.

CM
CmpDev
CmpDev
The above posted define will work for VS, but this is a better method

Quote:
#if (defined(__WIN32__) || defined(_WIN32) || defined(WIN32))
#include
#endif
Charles B
Charles B
Else you can take a look at the glut.h header file. It totally removes the windows.h dependency.

glut.h only defines the few Windows specifics required, and saves noticeable compilation time even when you work in the Windows context. This used to be a great advantage some years ago, but nowadays CPUs and compilers are so fast, it's not really an argument anymore ...

Still if you do such a choice, which seems rather drastic, you must see it on a broader scale, as a discipline. Be accustommed to separate dependencies (concepts, compilation and linking) and split the project in well formed modules, well interfaced. I'd say it really pays on medium term.

I have created many decent multi OS projects based on GL, and this scheme works quite well. It's very impressive and enjoyable to recompile a complex project developped many weeks on Windows and have it working fine on MAC OS in 5 minutes !

Anything OS dependent put separately in a library, with a modular approach (minimalist system server) and you have clean totally OS independent stuff for your core game engine project.

"Coding math tricks in asm is more fun than Java"
NewBreed
NewBreed
Hmm... Ok, thanks everybody for your replies. A lot of things there to look over here...

I'm quite interested in glut.h as well; never really thought anything of that other than an outdated wrapper. I'll take a good butchers.

Thanks again all,
NB (:
IFooBar
IFooBar
Quote:
Original post by CmpDev
The above posted define will work for VS, but this is a better method

Quote:
#if (defined(__WIN32__) || defined(_WIN32) || defined(WIN32))
#include
#endif


That depends... For example if you're using gcc even on a windows platform, you don't need to include windows.h to use opengl.
[size=2]aliak.net
CmpDev
CmpDev
Quote:
Is there a way I can include ...

I was only answering the OP's question, I didn't mention GL.
rip-off
rip-off
If you want completely platform independant access to opengl, you should look into SDL.

It can create a window and handle input and more in a platform independant manner.
NewBreed
NewBreed
Quote:
Original post by rip-off
If you want completely platform independant access to opengl, you should look into SDL.

It can create a window and handle input and more in a platform independant manner.


SDL was something I originally looked at, although while I can't deny it's a powerful library, I don't find it overly suitable for my needs. My Windows code I use (I don't use sound at the moment) at the moment is no more than 500 lines long, which does precisely what I want and I know exactly what is happening in it. I just find using such a library will be overkill for my needs. Thanks anyways for your suggestion! :)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.