PDA

View Full Version : [C/C++] glGetString before configuring



Dennis
11-16-2011, 01:25 PM
Hello everyone,

I'm having a problem with calling OpenGL function before OpenGL is configured.

Because I want to import OpenGL libraries dependent on the running OpenGL version, I should like to get the OpenGL version first. With:

glGetString(GL_VERSION)

But to call such function OpenGL has already to be configured, but I want to know the version before configuring.

So I don't know how to do this.
Could someone help me with this problem?

Thanks,

Dennis

Alfonse Reinheart
11-16-2011, 02:05 PM
Because I want to import OpenGL libraries dependent on the running OpenGL version

What do you mean by "import OpenGL libraries"?

Until you have created an OpenGL context, there is no "running OpenGL version" because OpenGL is not running yet. You could conceivably get any version.

In general, you pick a basic minimum version that your code supports. And then you code to that minimum. You can add different codepaths if the version you get exceeds that minimum, but you have your basic fallback for a specific minimum. If the current renderer does not support your application's basic minimum, then you halt execution with an error of some form.

Dennis
11-16-2011, 02:10 PM
With "import OpenGL libraries" I meant loading all static libraries runtime (in Windows that are dll's).

But so you mean I have to configure OpenGL, get the version, "import" my own dll's created for that version, and configure again (with those libraries)?

Alfonse Reinheart
11-16-2011, 03:34 PM
With "import OpenGL libraries" I meant loading all static libraries runtime (in Windows that are dll's).

No, DLLs are not static libraries. That's why they're called "Dynamically Linked Libraries"; to differentiate them from "Statically Linked Libraries".


But so you mean I have to configure OpenGL, get the version, "import" my own dll's created for that version, and configure again (with those libraries)?

I don't know; you didn't really explain what exactly it is you're trying to do. Are you creating a DLL for each version of OpenGL you want to support? If so, those DLLs likely have the same interface, yes? So you will have to dynamically load them and their function pointers based on the runtime OpenGL version and extensions.

mhagain
11-16-2011, 05:52 PM
You seem to have some deep confusion about how OpenGL actually works on Windows. There is no need whatsoever to "import libraries" for OpenGL; there is precisely one statically linked library that you need to set up your program to link to, and that is opengl32.lib, which comes pre-installed with any Windows progamming environment worth using.

You don't need to distribute this library to end-users, and you definitely should not be distributing any "OpenGL DLLs" to end-users either. Instead there is opengl32.dll, which is pre-installed on every Windows machine, and which in turn will dynamically link to the hardware vendor's driver (which gets installed as part of the standard driver installation).

In other words there is absolutely nothing special whatsoever that either you or the end-user needs to do so far as getting basic OpenGL operation up and running.

Once you have your context created, it will by default be an OpenGL 1.1 context. From there you use the extension mechanism in order to access higher functionality. Figure out which GL_VERSION the end-user has, decide on the minimum version you're going to support, and code fallback paths in your own program as required for features that are unsupported.

Dennis
11-17-2011, 08:09 AM
Maybe I was a bit unclear.
And yes I was confused about static and dynamic libraries.

I know how OpenGL normally works on Windows(32).

The real thing I should like to do is:

I've a main program, which the user starts up.
If the user has only OpenGL 1.1 capabilities I want to "import" my own dynamic libraries for this version.
So if the user should have OpenGL 2.1 (supported on the video-card) I want to import my own created dynamic libraries for this version, which makes use many more capabilities.

So for (a simple) example:
OpenGL 1.1: Every time on draw:

glBegin(GL_QUAD);
glVector2d(-1, 1);
glVector2d( 1, 1);
glVector2d( 1, -1);
glVector2d(-1, -1);

OpenGL 2.1: global-variables:

#define VERTICES 0
#define INDICES 1
#define NUM_BUFFERS 2
GLuint buffers[NUM_BUFFERS];
OpenGL 2.1: init:

GLdouble vertices[][2] = {{-1, 1},
{ 1, 1},
{ 1, -1},
{-1, -1}};
GLubyte indices[][4] = {0, 1, 2, 3};

glGenBuffers(NUM_BUFFERS, buffers);
glBindBuffer(GL_ARRAY_BUFFER, buffers[VERTICES]);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glVertexPointer(2, GL_DOUBLE, 0, ((GLubyte*) NULL + 0));
glEnableClientState(GL_VERTEX_ARRAY);

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[INDICES]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
OpenGL 2.1: Every time on draw:

glDrawElements(GL_QUADS, 1, GL_UNSIGNED_BYTE, ((GLubyte*) NULL + 0));

So you see, for every version I could make an other library which works. How newer the OpenGL version of the user is, how better the program could make use of the newest functions. But it has also to support lower versions.

So it should be nice to first know which library for running it has to take, and than run with it, to make full use of all capabilities.

Alfonse Reinheart
11-17-2011, 10:27 AM
If the user has only OpenGL 1.1 capabilities I want to "import" my own dynamic libraries for this version.
So if the user should have OpenGL 2.1 (supported on the video-card) I want to import my own created dynamic libraries for this version, which makes use many more capabilities.

So do that. In order to do what you're talking about, you have to have some mastery of LoadLibrary and GetProcAddress. So... just do that.

What you can't do is check the version before you create the OpenGL context. Just do the version check and DLL loading after. There's nothing that says you have to load your renderer DLL before creating the window.

Dennis
11-18-2011, 08:53 AM
Yes... I think that should be the best solution.

The thing I really wanted was putting the OpenGL context part also in the dynamic library.
But now I see that will not be possible for this.

Thanks you all for your help!