Why Does Glgetstring(Gl_Version) Return Null/Zero Instead of the Opengl Version

Why does glGetString(GL_VERSION) return null / zero instead of the OpenGL version?

glutInit() doesn't create a GL context or make one current. You need a current GL context for glewInit() and glGetString() to work.

Try this:

#include <GL/glew.h>
#include <GL/glut.h>
#include <cstdio>

int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutCreateWindow("GLUT");

glewInit();
printf("OpenGL version supported by this platform (%s): \n", glGetString(GL_VERSION));
}

glGetString(GL_VERSION) returns 1.1.0, even though card supports 2.1

Things to try:

  1. Remove all your SDL_GL_SetAttribute() calls. You may be over-constraining the pixel format. Add them back in one at a time to figure out where you overstepped.

  2. Remove only the SDL_GL_CONTEXT_* calls since you aren't trying to request a GL 3.x context.

OpenGL Version is not getting printed

Start from here: http://open.gl/context (learn about context creation, getting a basic, modern OGL program running)

Use a debugger.

Which version does glGetString(GL_VERSION) get?

From the spec (copied from 3.3 spec document):

String queries return pointers to UTF-8 encoded, NULL-terminated static strings describing properties of the current GL context.

So it's the version supported by the current context. There's a subtle aspect if you're operating in a client/server setup:

GetString returns the version number (in the VERSION string) that can be supported by the current GL context. Thus, if the client and server support different versions a compatible version is returned.

The way I read this, it will return the minimum between the client and server if the two versions are different.

It's generally easier to use glGetIntegerv() to check the version. This way, you don't have to start parsing strings, and you can also get additional detail:

GLint majVers = 0, minVers = 0, profile = 0, flags = 0;
glGetIntegerv(GL_MAJOR_VERSION, &majVers);
glGetIntegerv(GL_MINOR_VERSION, &minVers);
glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &profile);
glGetIntegerv(GL_CONTEXT_FLAGS, &flags);

if (profile & GL_CONTEXT_CORE_PROFILE_BIT) {
...
}

if (profile & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) {
...
}

if (flags & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT) {
...
}

glActiveTexture causes has stopped working error

You need to create an OpenGL rendering context before calling glewInit:

glutInit(&argc, argv);
glutCreateWindow("My Program");
GLenum err = glewInit();

See here for details.

Why Could glGetString(GL_VERSION) Be Causing a Seg Fault?

I doubt you can call even something as simple as glGetString without an OpenGL context.

Static call to glGetString() returns null in Android 5.0

First of all, this is probably not an upgrade issue, but a device-specific issue. Maybe (yours truly does not have enough statistical data across the thousands of device models), this kind of behavior of glGetString() is less likely to happen on older models, but such knowledge is not worth to seek, it doesn't help to resolve the problem anyway.

The khronos wiki explains that a live rendering GL context is required for all OpenGL functions to work, but it is not a violation for some of these functions to return non-NULL when called without such context.

You can find examples of initialization code here and here.

Even then, we have encountered some devices that returned NULL for glGetString(GLES20.GL_RENDERER); these have different manufacturers, platform levels, etc. Our Crashlytcis data does not suggest that this behavior is consistent for the same device.

Therefore, we had to employ a fallback so that the app does not crash when this function returns null.

How can i know which opengl version is supported by my system

See GLFW guid - Window creation hints which clearly says:

GLFW_CONTEXT_VERSION_MAJOR and GLFW_CONTEXT_VERSION_MINOR specify the client API version that the created context must be compatible with. The exact behavior of these hints depend on the requested client API.


OpenGL: GLFW_CONTEXT_VERSION_MAJOR and GLFW_CONTEXT_VERSION_MINOR are not hard constraints, but creation will fail if the OpenGL version of the created context is less than the one requested. It is therefore perfectly safe to use the default of version 1.0 for legacy code and you will still get backwards-compatible contexts of version 3.0 and above when available.


While there is no way to ask the driver for a context of the highest supported version, GLFW will attempt to provide this when you ask for a version 1.0 context, which is the default for these hints.



This means, if you want to get the highest possible OpenGL context, then you can completely skip glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, ) and glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, ).

After you have created a context, you can ask for the context version, with glGetString(GL_VERSION).

But if your application requires a minimum OpenGL version, you need to tell that to GLFW, with:

glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, required_major);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, required_minor);

glfwCreateWindow will fail, if the requirements cannot be fulfilled.



The answer to your question

How can i know which opengl version is supported by my system?

is:

You have to create an OpenGL context first, then you can ask for the version by glGetString(GL_VERSION).


Correction to the answer

As mentioned in the comment, this approach is going to fail when you try to create a core profile context.

This means you cannot use:

glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);


Related Topics



Leave a reply



Submit