-2
\$\begingroup\$

I'm sorry if this has been asked recently and I'm not Googling it right, but I've been digging all week for something.

I've got a game prototype I made in Unity, and I have some decent experience with SDL (1.2 I believe, but the 2.0 stuff is familiar) so I thought I'd take a crack at SDL 2.x + OpenGL while I've got a simple "sprite" based game that could take advantage of some of the blending features OpenGL offers, if nothing else but to practice with it so I'll be more prepared when trying to make a 3D game down the road. Honestly I'd probably be half done with it by now if multi-platform wasn't an issue.

I really want to put this game on Android, I think it's perfect as a mobile app. But nearly every tutorial I can find on SDL+OpenGL seems to include something like GLEW or freeglut or bucks SDL altogether for something like GLFW (which I actually kind of liked). All of these seem like great tools, but they typically don't have much in the way of tutorials or guides on how to get things over to the mobile side... and I'm not quite at the level where I know anything about porting these kinds of tools to Android unless it's a pre-existing build, honestly I don't really feel confident even building development libraries for Windows.

So I'm in some serious need of somebody who maybe has experience with at least Windows+Android or Linux+Android multiplatform development or can at least point me in the right direction for a tutorial/guide/tool/idc that can better explain the porting or cross-development from desktop to Android. Honestly I'd probably even shell out for a good book recommendation or fairly priced paid utility at this point. Heck, I'd probably try a Python or Lua type scripting solution (like that could bind to C/C++ and Java) if it's viable, my only problem there is a limited knowledge of embedding scripting languages into native code.

To clarify: I'm well aware there's not really a write once, deploy everywhere solution for native code like C++. What I'm looking for is some sort of reference how to handle- at least -one of these desktop platforms and Android in OpenGL, whatever windowing/input/etc. tool can be layered with it in a semi-platform independent way. Because, to me at least, it seems to be well under documented or my wheelhouse of SDL experience is crippling me from actually taking advantage of OpenGL and learning it properly.

Thanks for any help you can give, cheers~!

\$\endgroup\$

closed as off-topic by Kromster, MAnd, congusbongus, Alexandre Vaillancourt, Josh Jan 19 '16 at 17:06

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about "how to get started," "what to learn next," or "which technology to use" are discussion-oriented questions which involve answers that are either based on opinion, or which are all equally valid. Those kinds of questions are outside the scope of this site. Visit our help center for more information." – Kromster, MAnd, congusbongus, Alexandre Vaillancourt, Josh
If this question can be reworded to fit the rules in the help center, please edit the question.

-1
\$\begingroup\$

This is a very broad question. I'm assuming you have seen the answer from Kieran Chandler about platform abstraction.

You've mentioned the SDL Library that you want to use. I've used it myself for such a OpenGL cross-platform project. The library provides most of the platform abstraction. Use its functions for all input and output, like accessing files, getting user input and displaying. It provides build files for all the mentioned platforms. Start there with a minimal app, just some 2d graphic output and try to build it on android. Since SDL itself and your code are written in C++, you'll need the Android NDK to compile it. The documentation is sparse, the basic steps are:

  1. Write Android.mk build files
  2. Compile them with ndk-build

There are some tutorials on this, i.e. here: http://www.dinomage.com/2013/01/howto-sdl-on-android/ Some things may be outdated, and you'll need to put some work into getting it right.

After you have managed to build a minimal example application for all platforms, add OpenGL. SDL has calls to create an OpenGL window for you, after that you are on your own. I have used OpenGL 2.1 for the desktop, and OpenGL ES 2.0 for Android. For Android, I included "SDL_opengles2.h" and GLES2/gl2.h. For Windows, I used the OpenGL Loader generator (glLoadGen) to create header files for me and included those.

Most calls were the same on mobile and desktop, only some parts needed #ifdefs to differentiate the platforms, for example:

#ifdef ANDROID
    glClearDepthf(1.0f);                     //Depth Buffer Setup
#else
    glClearDepth(1.0f);                     //Depth Buffer Setup
#endif

I hope this helped so far.

Some of my code can be found here in case you want to take a look: https://github.com/tm4n/t3d Look especially at the gameRenderer.cpp file. Build files for android are unfortunately missing in the repository. Note that this is not a finished engine and the code is not very well structured and documented, but it works on all three platforms.

\$\endgroup\$
  • \$\begingroup\$ Thanks this cleared up a lot of confusion I had, and why overall this was probably too a broad question. One of the things that confused me was Unity and Visual Studio kinda obfuscate the fact the ndk is both a binding for Android functions to C/++ AND a compiler, which is the main thing I wasn't aware of. I think between your example and the idea to look at low level APIs (idk about Xlib tho lmao) I have some new ideas now. Just one question, am I right in assuming that gl_core_2_1.h/c code is part of GLEW? I saw it included in the header, I just assume you probably didn't write that. \$\endgroup\$ – AniMerrill Jan 19 '16 at 6:37
  • \$\begingroup\$ gl_core_2_1.h/c are not from GLEW, they were generated by the glLoadGen tool. I have only tested this with a few grafic cards and drivers, but it worked on windows and linux. On Android, not even this is needed. Just include the two headers I mentioned above and link to the GLES library. EDIT: Also, technically ndk is not a compiler, just the build tool. It compiles with gcc. \$\endgroup\$ – Tilman P. Jan 19 '16 at 9:03
-1
\$\begingroup\$

It doesn't sound like you are ready to take on a large task like this. You need to learn about the underlying concepts and make some smaller projects before you can really move on to making a cross-platform game.

The main point to make about cross-platform games is that you need to have a "Platform Abstraction Layer" which will allow your game to perform tasks without knowing what platform it is running on or knowing anything about the platform. the STL library can do most of this for you, but you'll find that things like the game loop and window creation may need to be handled differently for your different platforms

Simply googling: platform abstraction

should yield sufficient results to get you started, but you will need to have experience in low-level programming, possibly with the Win32 API.

Hope this helps

\$\endgroup\$
  • \$\begingroup\$ While I think I have a little more confidence in myself than you do, knowing that people call it "platform abstraction" and the idea to use Win32 and Xlib (and whatever the Android version is..) helped me a lot. If anything the low level window functions and stuff look kinda fun to learn. \$\endgroup\$ – AniMerrill Jan 19 '16 at 6:40
  • \$\begingroup\$ Im glad that helped. The way you put your question made it seem like you hadn't done anything like this before so i was just suggesting you take an approach to it in smaller steps instead of the one big step. The Win32 API can be fun, but you'll find there are some stuff that will drive you mad :D \$\endgroup\$ – Kieran Chandler Jan 19 '16 at 10:15
  • \$\begingroup\$ lmao I can only imagine. \$\endgroup\$ – AniMerrill Jan 19 '16 at 15:14

Not the answer you're looking for? Browse other questions tagged or ask your own question.