[c++] glew doesn't work

Started by
5 comments, last by Gyiove Sparkle 9 years, 4 months ago

Hello everyone!

I downloaded glew from

  • [08-11-14] GLEW 1.11.0 adds support for OpenGL 4.5, new extensions

then i added glew.c to my project also called glewInit() it returned 1 but after using any opengl function what glew includes the app crash.

I think it doesn't initialize those functions, tried to debug it but it won't let me include iostream for cout, after i include it cmath starts to show random errors ...

i also: #define GLEW_STATIC

What is going on guys?

Thanks!

Advertisement

Not sure if it's the problem but have you tried to set glewExperimental = true before initialize?

http://glew.sourceforge.net/basic.html

"GLEW obtains information on the supported extensions from the graphics driver. Experimental or pre-release drivers, however, might not report every available extension through the standard mechanism, in which case GLEW will report it unsupported. To circumvent this situation, the glewExperimental global switch can be turned on by setting it to GL_TRUE before calling glewInit(), which ensures that all extensions with valid entry points will be exposed."

now i did it and still crashing...


	glewExperimental = true;
	cout << "s:" << (int)glewIsSupported("glCreateShader") << endl;
	cout << "state:" << glewInit() << endl;
	cout << "u:" << glGetString(GL_VERSION) << endl;

// cout

s:0
state:1

u:

// crash

Why are you calling a glew* function before glewInit? Don't do that.

Do you have a GL context created and set active for the current thread for the gl* functions? Those only work with a context.

While not necessarily the problem with the specific example above, also be aware that GLEW doesn't magically make GL 4.5 work. Your driver still has to actually support it, which only one single driver on a small range of recent hardware does (NVIDIA on Kepler or Maxwell). If you tried to create a 4.5 context and assumed that it worked, there's a good chance it didn't and that you don't actually have a valid context.

Sean Middleditch – Game Systems Engineer – Join my team!


	cout << "state:" << glewInit() << endl;
	cout << "s:" << (int)glewIsSupported("glCreateShader") << endl;
	cout << "u:" << glGetString(GL_VERSION) << endl;

state:1

s:0

u:

My computer support the latest opengl, it was working with GLee or something.
Anyways, i was able to use all those latest functions and everything worked fine.

https://www.opengl.org/registry/specs/NV/blend_equation_advanced.txt

that worked fine.
Also getting those opengl func manually work fine but because there are just so many functions i wanted to include glew.

First, glewInit is failing. 1 is not a good return value in most C-like APIs, as it's normal for C functions to return 0 on success and some non-zero value to indicate a specific error (or -1 for general errors). glewInit should be returning GLEW_OK if everything is working. The return value of 1 however corresponds to GLEW_ERROR_NO_GL_VERSION which means that most likely you did not create or bind a GL context properly before calling glewIinit (which also explains why a simple glGetString is crashing, as you cannot call gl* functions without a bound context in the current thread).

You need to be sure you're creating a context in the appropriate way for your platform (or using a helper library like GLFW, SDL, SFML, etc.) and that it's bound to the current thread (again, platform-dependent or via a helper library).

If you already are creating a context created somewhere else in code you're not showing us, just remember: create GL context /first/, initialize GLEW /second/.

Minor additional pointer: your use of glewIsSupported is wrong. It checks for extensions, not for entry points. glewIsSupported is correctly returning 0 as 'glCreateShader' is not the name of an extension (it would be 'GL_ARB_shading_language_100' or something like that, if you had any reason to check for it, which you don't). glCreateShader is a core function in GL 2.0+ so if you've created a context of that version or higher it's guaranteed to be present and there's no reason to check for it.

Sean Middleditch – Game Systems Engineer – Join my team!

Yay! that was what i was looking for.

wglMakeCurrent became after that glewinit, now its working.
@SeanMiddleditch thank you so much <3

This topic is closed to new replies.

Advertisement