#### Archived

This topic is now archived and is closed to further replies.

# whats needed for true platform independent?

## Recommended Posts

Will a console application using GLUT and OpenGL in MSVC++6 be able to run, un-changed and not recompiled, on a different system than Windows? If not, than what is needed to do this?

##### Share on other sites
Hmmm, your program must be recompiled for the different
platforms. You can''t avoid that.

My GLUT programs can compile with no modification
on Windows, Linux, and Solaris. And yes, they run identically
on all 3 platforms (appearance, not performance).

The only thing I need is this:

#ifdef WIN32#include <windows.h>#endif#include <GL/gl.h>#include <GL/glut.h>

That and the sleep function. I use Sleep
for Windows and nanosleep for Linux/Solaris.

Kami no Itte ga ore ni zettai naru!

##### Share on other sites
That''s tight, my game is so platform dependent it makes me sick Unless you consider the XBox another platform, then its portable lol

Mindgamez Entertainment

##### Share on other sites
How do you set your compiler for the multiple systems? Can it be done easily in MSVC?

##### Share on other sites
Either go to the other platform and compile it on a native compiler, or use a cross-compiler. I believe you can''t do this with MSVC.

##### Share on other sites
I''d have tried to make a platform independent engine but I''m using DirectX so no dice lol

Mindgamez Entertainment

##### Share on other sites
I recently discussed this actually, and one thing I didn''t think of is that you have to take endian-ness into account. Make sure that you convert to the right endian for the OS, otherwise your program will be garbage ( thinking about loading files from disk now ). There are functions to convert "network endian" into native OS endian though, which you will most likely need to use. I forget the names.

Death of one is a tragedy, death of a million is just a statistic.

##### Share on other sites
"How do you set your compiler for the multiple systems? Can it be done easily in MSVC"

no

Why would microsoft want to make a compiler that works for non-ms operating systems?

##### Share on other sites
quote:
Original post by neurokaotix
That''s tight, my game is so platform dependent it makes me sick Unless you consider the XBox another platform, then its portable lol

Mindgamez Entertainment

wow... the last i heard they were just making theorys on how to make apps for the xbox! although that was about 3 months ago... -PmanC

##### Share on other sites
My engine (Avangion) is platform-independant (Works on Windows and Unix based systems). The matter concerning little and big endian is annoying but can be resolved quite easily. First, find out what system your engine is compiled on by using #ifdef. Windows works with little endian while Linux works with big endian. Then, simply #define some macros that automatically convert the data if it is necessary. Here is some pseudo-code:

#ifdef LITTLE_ENDIAN
#define SWAP16LE(x) (x)
#define SWAP32LE(x) (x)
#define SWAP16BE(x) Swap16(x)
#define SWAP32BE(x) Swap32(x)
#endif

#ifdef BIG_ENDIAN
#define SWAP16LE(x) Swap16(x)
#define SWAP32LE(x) Swap32(x)
#define SWAP16BE(x) (x)
#define SWAP32BE(x) (x)
#endif

The Swap16 & Swap32 functions simply switch the high order byte(s) with the low order one(s) using bitwise ops.

Hope that helps!

##### Share on other sites
quote:
Original post by PyroMeistar
My engine (Avangion) is platform-independant (Works on Windows and Unix based systems). The matter concerning little and big endian is annoying but can be resolved quite easily. First, find out what system your engine is compiled on by using #ifdef. Windows works with little endian while Linux works with big endian. Then, simply #define some macros that automatically convert the data if it is necessary. Here is some pseudo-code:

#ifdef LITTLE_ENDIAN
#define SWAP16LE(x) (x)
#define SWAP32LE(x) (x)
#define SWAP16BE(x) Swap16(x)
#define SWAP32BE(x) Swap32(x)
#endif

#ifdef BIG_ENDIAN
#define SWAP16LE(x) Swap16(x)
#define SWAP32LE(x) Swap32(x)
#define SWAP16BE(x) (x)
#define SWAP32BE(x) (x)
#endif

The Swap16 & Swap32 functions simply switch the high order byte(s) with the low order one(s) using bitwise ops.

Hope that helps!

Linux is little endian on little endian architectures and big endian on big endian ones. It is little endian on x86 for instance, and big endian on PPC.

There is also much more to portability than endianness (binary representation of floating point values, threads, networking and other system calls, file I/O, etc). Now if your project is small, you can probably just forget this, as long as you avoid storing 3D data in binary files and don''t use sizeof(structure) to read from a file (because of padding).

Hope this helps.

##### Share on other sites
Most windows programs will run on the XBox without changeing anything, but to actually see stuff on the screen you must change data types(and it must use directx of course), and because the size of tv''s are different the drawing functions have to be a little different

But you gotta love XBox Dev kits, fun to play with

quote:
Original post by PmanC
[quote]Original post by neurokaotix
That''s tight, my game is so platform dependent it makes me sick Unless you consider the XBox another platform, then its portable lol

<a href="http://www.mindgamez.com/~neuro/me/" target="_none">Mindgamez Entertainment</a>

wow... the last i heard they were just making theorys on how to make apps for the xbox! although that was about 3 months ago... -PmanC

• ### Forum Statistics

• Total Topics
628354
• Total Posts
2982231

• 10
• 9
• 11
• 24
• 11