Using GLEW and Core Profile without glError


I’m using the function glewInit() with a OpenGL context in core profile (3.3 or 3.1) and this function return a glError 1280 (with glGetError();).
I try with glewExperimental = GL_TRUE; but the result is the same.

How can I use GLEW with a core profile context ?


Don’t use glGetError to check the result of glewInit; GLEW is just a convenience wrapper for loading OpenGL function pointers, but is nothing to do with actual OpenGL execution.

Read the GLEW documentation for the correct way to test initializing GLEW: - check that glewInit returns GLEW_OK.

In my application, glewInit returns GLEW_OK.
But the initialization of glew create an opengl error (1280).
I read that “GLEW has a problem with core contexts” here (
So how used GLEW without OpenGL error ?

For the moment my app works but it isn’t clean in my opinion.

Last time I checked GLEW was using glGetString(GL_EXTENSIONS) to obtain the supported extensions. That is not supported on core profile contexts (and causes an OpenGL error), where you must use glGetStringi(GL_EXTENSIONS, i) to obtain the supported extensions individually. You can set glewExperimental = GL_TRUE before calling glewInit() and do a glGetError() call afterwards to swallow the error caused by glewInit() - that seems to work for me. Use the return value of glewInit as mhagain says to check if glewInit succeeded.

Is not good for me.

GLuint err = glGetError(); //0
glewExperimental = GL_TRUE;
if (glewInit() != GLEW_OK) {
	std::cout << "ERROR: GLEW Failed to init." << std::endl;
	return false;
err = glGetError(); //1280

The question is : I need to modify glew to force it to use glGetStringi(GL_EXTENSIONS, i) ?

Thanks for your reply

What exactly is not working? Do you exit early after printing “GLEW Failed to init”?
The GL error after glewInit is expected, you just ignore it (it is not a problem in practice). That way you can distinguish “real” GL errors caused by your application from this one.

To avoid the error GLEW would need to be modified to use glGetStringi - on core profile contexts. On OpenGL 3.1 and earlier contexts (or whenever glGetStringi was introduced - I don’t remember off-hand) it would have to continue to use glGetString. I looked into it once and sent a patch, but it was causing problems on the authors system, so was not ready to be accepted.

Ok so I simply use glGetError() to reset OpenGL error.
I’m going to wait GLEW 2.0 ^^

Thanks a lot !

You’re quite correct, by the way - this is not clean.

However it’s the way GLEW currently works so, unless we each make our own custom versions of GLEW, it’s what we have to live with.

Use GLAD instead, it lets you choose what extensions you need.

I didn’t know GLAD. It seen good :slight_smile: