Reputation: 379
Folowing by THIS LINK In DirectX I can simply add this lines:
#include <d3d11.h>
#include <d3dx11.h>
#include <d3dx10.h>
#pragma comment (lib, "d3d11.lib")
#pragma comment (lib, "d3dx11.lib")
#pragma comment (lib, "d3dx10.lib")
...
to specify 'up to date' DX version that I want to code in. How can this be achieved in OpenGL so I can be sure that I am using the latest GL libraries while coding. Should I #define
something or my GL functions that I use in code determine the version of OpenGL?
Is there a method in c++ or other software that can tell what version of openGL my .exe program is using?
Upvotes: 0
Views: 133
Reputation: 473232
That's not how OpenGL works; OpenGL is not something you statically link to (or rather, that's not all you have to do). You have to (generally speaking) dynamically load the OpenGL functions you work with. This is typically done by employing an OpenGL loading library of some kind, thus reducing this to #including a header and calling a function during initialization (after creating the OpenGL context).
The "version" of OpenGL you use depends on what version is supported by your implementation and what functions/enums you choose to use. If your code is written against OpenGL 3.3, but your implementation supports 4.1, that's fine; it's backwards compatible with 3.3.
There are ways to ask which OpenGL version of OpenGL is being provided, but this is a runtime query, not a compile-time construct. You can explicitly request a version (greater than or equal to what you ask for) at context creation time, which will cause the context creation to fail if that version is not supported by the implementation.
This makes your code a bit more flexible. For example, you can write optional parts of your program that can provide more features if, for example, OpenGL 4.1 is available, but will default to 3.3. You won't have to work with two (somewhat) different APIs, or build an abstraction that merges their common elements. You just have a conditional somewhere in your code that verifies that 4.1 is provided, and if it is, you call a few other functions. Otherwise, you do the 3.3 stuff.
Upvotes: 5