If I make a game on Windows using OpenGL, C++, and some other multiplatform libraries what would I need to do to say port it over to Linux or Mac? What would be some mistakes people make when programming that are OS exclusive? Thanks for any help.
How would I port a game?
Members - Reputation: 1335
Posted 17 January 2014 - 07:18 PM
If your code doesn't depend on platform-specific libraries or headers, you can easily port your application. But you will still need access to the operating systems you want to port to, in this case Linux and Mac, and a compiler on these specific platforms.
There are not really common mistakes aside thinking you can compile for those platforms using only Windows and including platform-specific headers... If you still need platform-specific headers you will need to provide alternatives for all supported platforms. For example, if you would want to include winsock, you would usually use preprocessors to use another header if the code is being compiled on Mac or Linux.
Members - Reputation: 1191
Posted 17 January 2014 - 07:45 PM
First, I'd recommend using the same compiler (or as similar as you can get) for each target platform. Gcc is probably the "normal" choice, but Clang or whatever is fine. It will just minimize the compiler-specific issues. You can learn about cross-compiling if you don't want to compile the code on the actual target OS, although you'd obviously want access to a machine for testing and such. If you do want to build all 3 targets at once, it's probably easiest on Linux just because so many people have build servers and such running on Linux.
Next, I'd recommend SDL2 or some equivalent. I think you were implying you'd be doing that already, so you're likely set in that department.
Once that's going, get a basic program running on all 3 using all the libraries you plan to use. That's going to be the biggest challenge. Once you're up and running, you just need to avoid stupid things like using "C:/..." for a file since obviously that's not going to work on Linux. And avoid things that are obviously OS-specific like wglWhatever or winblahblah. Threading models are also different and might not be as obvious since they're usually just stuff like pthreads, so you'd have to know p is POSIX to know it's OS-specific.
It sounds scarier than it is. Even if you mess up, it usually doesn't take long to get things back to working on every OS.
Crossbones+ - Reputation: 4131
Posted 17 January 2014 - 08:13 PM
The annoying part will probably be setting up all environments while you still don't have experience building, linking and this kind of stuff.
So, to make your life easier, try to use a compiler available on most of your platforms and use some library for file handling for OS abstraction (like PhysFS).