The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Cross Platform (Mobile + PC) SDL2 + OpenGL setup
phildo


Joined: 08 Dec 2014
Posts: 5
Is this kind of setup possible? plausible?

I have it setup so that I can pretty seamlessly create an SDL2 game simultaneously for Mac and Android. But I'm finding any documentation regarding integrating with openGL across platforms with SDL either outdated or totally lacking... (maybe I'm just looking in the wrong places?)

So, I'm up for any advice/examples people have regarding a project of this nature. But also, more specifically, I have a few example questions:

- What is SDL2's philosophy regarding integration with SDL2? Is it just "technically not incompatible with" also using OpenGL? Or are you expected to access the OpenGL API THROUGH the SDL2 API?
- How would I go about integrating openGL with SDL2 across platforms? There are different include files/compile flags/etc... depending on platform- does SDL wrap their inclusion/compilation within ITS inclusion/compilation?
- Even more than different include/compile flags, there are different VERSIONS of OpenGL available to different platforms... I think I read that OpenGLES2 (supported on most mobiles) is just a subset of OpenGL2 (supported on most desktops), so might an #ifdef on platform around the inclusion of which openGL version be enough (assuming I am careful to only use the ES API).
- Are there any straightforward walkthroughs regarding getting this kind of setup (inclusion/compilation with SDL + OpenGL into some codebase across mobile and desktop)?
- Really ANY advice you'd be willing to give me on the subject would be so greatly appreciated. If there's some key intuition you think I'm missing... or even if it's something like "start reading here <link>"- I'm kinda at the stage where "I don't know what I don't know".

Any help or direction would be greatly appreciated! Thanks!
phildo


Joined: 08 Dec 2014
Posts: 5
Ok, so still working on figuring this stuff out. I'll try to answer my previous questions to the best of my knowledge for future travelers. I would still LOVE to be corrected or made more clear, because I still haven't found anything particularly straightforward...

- What is SDL + OpenGL philosophy?
SDL does the correct include for you by simply "#include <SDL_opengl.h>"ing. From there, after init-ing, you need to SDL_GL_SetAttribute a couple of GL-ish things to let SDL know what GL version you want 'n such. You then SDL_CreateWindow with the SDL_WINDOW_OPENGL flag set, and then use SDL_GLContext gl = SDL_CreateContext with the window you've just created. From there, you have a GL window and a GL context set up and just use openGL calls as though you had set up openGL straight up.
tl;dr: Need to use specific SDL calls in generating/ setting up your window to init a GL context, but then SDL is hands off.

- How to set it up across platforms?
I have #ifdefs for platform around what version of openGL I'm requesting via SDL's SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, ...). But if you are using compatible versions of openGL across platforms, you're fine. For example, I'm planning on using OpenGL 2.1 for desktop, and OpenGL ES 2.1 for mobile. I HAVEN'T TESTED HOW WELL THIS WORKS YET!!
- Are there different versions?
Kind of answered above
- Any straightforward walkthroughs?
Oh god no. There are tons of references/documentation for specific API calls on either SDL or OpenGL, but no "Hey, here's conceptually what you need to ensure you are doing to get a damn triangle on screen". There are a couple examples on github 'n such that "display a triangle", but they are all using wildly different versions of this or that and it's all a mess. If you find anything good, tell me!
macrofeet


Joined: 29 Apr 2012
Posts: 20
I recently worked on some sprites for a project (Gigalomaina)

homepage.ntlworld.com/mark.harman/comp_gigalomania.html

This is SDL2 Open source and on the android store

Hope this helps + anyone reading this think about contributing to this project as its awesome.