I am trying to write opengl code that works everywhere, but not too limiting myself.
I wanted to use opengles2 on devices that support it, and opengl core, where they are supported.
In addition, I would like to be able to choose which one to use at runtime (if available, of course).
My questions: If I link my code to the OpenGL library every time it is available and then either creates the main GLES2 or GL context, will the GLES2 context behave exactly like the GLESv2 library? What will be the implications of this headline? For example, GLESv2 does not define BGRA texture formats, so I think I will have to convert everything to RGBA. This is not so much hassle, but I'm interested in learning about alternatives.
I was thinking of dynamically loading the library and loading all pointers to the functions used, but this is a huge job for something that might be easier to answer. In this case, I would just include glext.h and declare all function pointers for the functions used and populate them. The problem here is that glext does not define data types (glenum, etc.), so I always need to enable gl.h. Including both, I get a gl.h function declaration and my own function pointer declaration, so I couldn’t just use a common namespace for function pointers ... And even then some functions (e.g. glGetError) do not seem to have an associated typedef for their pointer functions.
I know about GLEW, but unfortunately most Linux distributions distribute a version of GLEW that is still not compatible with GLES2 (debian, I'm looking at you). These are just segfaults.
How do you guys do this? Any other approaches to linking the opengl function?
source
share