Writing cross-platform code is actually pretty easy. There are just a few things you have to watch for:
1)
Don't use any platform-specific API or platform SDK. In your case, since you are using SDL+OpenGL, you are fine. Just make sure that any function is call is either:
- an SDL function
- an OpenGL function
- a standard C or C++ library function (ie: from <iostream> or whatever)
- a function you wrote yourself.
As long as everything you call is one of those -- you're fine.
2)
Don't make assumptions about system endianness or size of specific variable types:
This is not portable code:
1 2
|
int someint;
file.write( (char*)(&someint), sizeof(int) );
|
The problem with this code is twofold:
- It assumes sizeof(int) is the same across all platforms
- It assumes endianness is the same across all platforms.
And while this code will
work on any system you compile it on, it will generate a different file based on whatever platform you're running. So a file created with this method on a Windows machine may not be able to be opened when run by your program on a Mac.
3)
Don't make assumptions about undocumented behavior in functions.
For example, on Linux you can typically open files with a UTF-8 filename through the standard lib. This is typically not true on Windows. If the function documentation does not specifically say it supports a certain behavior, then you must not assume it will, even if it does when you try it.
That's pretty much it. I can't think of anything else. If you follow those 3 rules your code will be extremely easy to port.