Sign in to follow this  

c++/SDL2 and various platforms rendering

This topic is 1196 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have been starting to learn SDL2 within Visual C++ the past couple of weeks. I have currently gotten to a point where I am rendering some scaling buttons (with states: mousehover, down, etc). I am doing this with the use of the OpenGL flag on the window creation.

 

However, what concerns me is what happens on other platforms? Will SDL2 use whatever version of OpenGL is on the machine, or if none available (like on some phones) will it choose the ES versions or another rendering option (with last fallback of software rendering)? What happens if I call an OpenGL function that is from a higher version than exists on the machine (it might work on my machine but not another)?

 

*Yes I have tried searching the net but could not find anything about using the OpenGL flag and the different OpenGL versions All I could really find is people that just iterate using the flag to use OpenGL*

Share this post


Link to post
Share on other sites

Will SDL2 use whatever version of OpenGL is on the machine, or if none available (like on some phones) will it choose the ES versions or another rendering option (with last fallback of software rendering)?

I have not used SDL on anything but PCs yet. On PCs, I believe SDL2 defaults to OpenGL 1.2 but you can specify the version you want. This works the same on all (PC) platforms. I don't actually know what happens, when you specify a version that isn't supported by your driver. But that should be easy to find out.
 

What happens if I call an OpenGL function that is from a higher version than exists on the machine (it might work on my machine but not another)?

Every OpenGL function that wasn't already in OpenGL1.2 is a function pointer that must be initialized "manually" where manually means you usually use a library for it. When you use such a library it will have tons of those function pointers, even ones for versions your game doesn't need or your driver doesn't support. However, the library will only initialize the function pointers that belong to the supported versions. If you call any of the unitilialized function pointers, the program should crash immediately with a null pointer access violation.

Note that you can (and probably should) query beforehand which OpenGL versions and which extensions are supported.

Share this post


Link to post
Share on other sites

Creating modern OpenGL context with SDL:

http://www.opengl.org/wiki/Tutorial1:_Creating_a_Cross_Platform_OpenGL_3.2_Context_in_SDL_(C_/_SDL)

 

Use GLEW to determine what you can and cannot use:

http://glew.sourceforge.net/

 

Note that if you need a modern context, you need to set the global variable glewExperimental to GL_TRUE before initializing GLEW with glewInit().

Edited by Kaptein

Share this post


Link to post
Share on other sites

However, what concerns me is what happens on other platforms? Will SDL2 use whatever version of OpenGL is on the machine, or if none available (like on some phones) will it choose the ES versions or another rendering option (with last fallback of software rendering)?

If the version of OpenGL you specify in the context flags is not available, you get a failure.
 
The default context in libSDL2, for a device that supports OpenGL, is OpenGL 2.1.  That's most desktop devices these days.  Most desktops provide binary support for later versions, too, even if it requires software rendering.  An extension wrangler will help with forward-support on older contexts.
 
The default context on a device that does not support OpenGL but supports OpenGL|ES 1 is OpenGL|ES 1.1.
 
The default context on a device that does not support OpenGL or OpenGL|ES 1 is OpenGL|ES 2.0.  That's most mobile devices these days.
 
The default is to not use EGL for OpenGL and to use EGL for OpenGL|ES.  Some platforms (eg. Wayland and Mir on Linux) you want to use EGL for everything otherwise you'll get failure, some it doesn't matter (X11) and others (Microsoft Windows) will fail if you try to use EGL for OpenGL..  You may need to probe to see what's supported.
 
Your best bet is to explicitly set the desired OpenGL version before opening the window, and write to that version.  You may want to use an extension wrangler, and you may want compile-time selection between Gl and GL|ES code paths where the two are API-divergent.

Share this post


Link to post
Share on other sites

If you just want to target PCs you should be fine using OpenGL 3.1 or later

See: http://store.steampowered.com/hwsurvey/videocard/

Even the potatoes these days have dx10 GPUs as can be seen by the 97% coverage. Unless you include china, where it's mostly XP. According to Valve though, their hardware is good enough, so it's just an operating system & directX issue. If you want max PC coverage 3.1 is safe, and core 3.3 (or even 4.x) is beneficial for learning modern graphics programming.

Edited by Kaptein

Share this post


Link to post
Share on other sites

I want to thank everyone for their posts and input.

 

I have migrated to Code::Blocks and Mingw for cross-compatibility when compiling instead of using MSVC++.

 

The main thing is with all the comments here I have added some initial functionality for testing what major/minor versions of OpenGL can be set for a context window to be created. I will be adding some testing for ES versions down the road to cover all bases.

 

I have to say I like this approach a lot so far. Been experimenting with creating a brand new framework to encapsulate SDL's window creation so I can dynamically create extra windows on the fly to render too. It really allows a lot more flexibility than I imagined.

 

I am also looking at Glew as mentioned earlier, seems like something important.

Share this post


Link to post
Share on other sites

This topic is 1196 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this