Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defining GL_GLEXT_PROTOTYPES vs getting function pointers

Tags:

opengl

I am writing a program which depends on OpenGL 2.0 or above. Looking at the specs of GL 2.0 I see that the extension defined in ARB_shader_objects has been promoted which I suppose mean that the ARB prefix is no more required for GL version 2.0 and above and any implementation supporting > GL2.0 will have this as part of the core implementation.

Having said that when I compile my program gcc on Linux gives warning: implicit declaration of function. One way to get these functions is to declare them in the program itself and then get the function pointers via *GetProcAddress function.

The other way is to define GL_GLEXT_PROTOTYPES before including glext.h which circumvents the problem of getting the function pointers for each of the functions which are by default now present in GL2.0 or above. Could someone please suggest if that is a recommended and right way? The base line is that my program requires OpenGL 2.0 or above and I don't want to support anything less than GL2.0.

Just in case someone suggests to use glee or glew, I don't want to use/ have option to use glee or glew libraries for achieving the same.

like image 257
Divick Avatar asked Jul 08 '13 10:07

Divick


1 Answers

There are two issues here.

GL_ARB_shader_objects indeed was promoted to core in GL2.0, but the API has been slightly changed for the core version, so it is not just the same function names without the ARB prefix, e.g. there is glCreateShader() instead of glCreateShaderObjectARB(), and the two functions glGetShaderInfoLog() and glGetProgramInfoLog() replacing glGetInfoLogARB() and some other minor differences of this sort.

The second issue is assuming that the GL library exports all the core functions. On Linux that is usually the case (not only for core functions, but basically for everything), but there is no standard guaranteeing that. The OpenGL ABI for Linux just requires:

3.4. The libraries must export all OpenGL 1.2, GLU 1.3, GLX 1.3, and ARB_multitexture entry points statically.

There are proposals for an update but I haven't heard anything about that recently.

Windows only exports OpenGL 1.1 core, as the opengl32.dll is part of the OS and the ICD is in a separate dll. You have to query the function pointers for virtually everything there.

So the most portable way is definitively to query the stuff, no matter if you do it manually or use some library like glew.

like image 94
derhass Avatar answered Jun 09 '23 23:06

derhass