Why are extensions available as function pointers?

Im new and Im interested to know why are the opengl extensions available as function pointer and not as some c style API or as some exported class?

Well, function pointers are a “c style API”. I don’t really understand what you’re trying to say there. And they don’t use an “exported class” because OpenGL is a C API. An “exported class” would by definition not be C.

Because the availability of the extensions depends on the combination of the driver version and GPU capabilities.

They have to be discovered dynamically (ie at runtime) by any program that wants to use them. If an extension is advertised by the driver (ie if the extension exists in the string returned by glGetString(GL_EXTENSIONS) ), then the functions defined by this specific extension exists and you can retrieve their pointers by a call to a wgl-specific or glx-specific or mac-specific flavor of getprocaddress() (which the glew lib can hide for you).

Thanks Overlay, now I understand.

Alfonse, Thanks for the reply. I wanted to understand why these extensions are available as function pointers and not as some functions/classes which can be in a Dll or something.

thanks.

Alfonse,

thanks, I now realize what I asked and what you wrote in the post.

thanks again.

Hi, one Extension i want to use is not returned by glGetString(GL_EXTENSIONS), But i’m able to retrieve a function pointer that is defined by that Extension. How is that possible? if an extension is not available then the function defined by the extension could not be used right ?

Please don’t revive ancient threads with (somewhat) related questions; just start a new thread.

Are you sure it is a valid function pointer and not just some non-zero (vaguely pointer looking) value, e.g. does it point to memory that is mapped in your process and marked as executable, is the sequence of instructions it points to valid (as per your platforms ABI) for the start of a function, does it do what it is supposed to do according to the GL spec, etc.?

Anyway, if the implementation does not advertise the extension you are not supposed to use functionality from that extension (including calling any its functions). Sometimes implementations use the same function to implement (same or very similar) functionality from multiple extensions (e.g. a vendor extension and a later EXT, or ARB/KHR variant) or standard versions. To simplify the implementation wgl/glXGetProcAddress will probably just give you that function pointer even if it should not.
It’s also possible that the vendor is still working on implementing the extension, but the patch to the function pointer retrieval code is already in a released driver (maybe for testing or by mistake).
Finally, the extension string could be incomplete, i.e. the implementation has a bug.