Check if GLEW already initialized?

Started by
3 comments, last by TooMuchCoffee 9 years, 8 months ago

I'm working on a small engine that facilitates window handling on Win32, and I need a way to check if GLEW is already initialized. Normally, I would just init GLEW at the start of my application, but my engine doesn't assume anything about what method is used for rendering (or even if it renders at all). OpenGL is utilized through a derivative of a base window class, which attempts to initialize GLEW upon instantiation. However, if GLEW is already initialized, it will throw an error and the window won't be created. So how can I check to see if GLEW is already initialized to avoid trying to init it again? I'd rather not resort to globals, but if I must...

Advertisement

eh, withdrawing post, as I'm really not certain if I'm correct.

Beginner here <- please take any opinions with grain of salt

Upon further thought, I think I'll use a static variable to count the number of windows using GLEW, so that GLEW won't be initialized if it's already present, but won't be closed upon the deletion of the OpenGL context if other contexts still rely on it.

Well, a few things here... First off, I just added an extra glewInit() call after my existing one, and there is no crash or problem whatsoever. Both calls return GLEW_OK and everything works identically.

Furthermore... If you really need this kind of information in your engine - you *should* keep track of it.

Finally, not exactly what you're asking for, as I'm even guessing GLEW doesn't have a flag or way to check whether it's already initialized...

But, glewInit() is *supposed* to be called AFTER a GL context is created.

If you're doing it the proper way. Doing it in that order allows it to be crossplatform. So, assuming you're doing it correctly like this, then that mandates that in order for GLEW to be initialized.. there must be an existing GL context. And you can check this by looking at glGetString(GL_VERSION)

But, glewInit() is *supposed* to be called AFTER a GL context is created.

Right, but Glew doesn't need the context to continue existing to continue providing extension function pointers accurately, so I could create a temporary context, init Glew, then delete the context at the start of the application, but that approach would be impractical if the application being developed doesn't even use OGL.

I just added an extra glewInit() call after my existing one, and there is no crash or problem whatsoever. Both calls return GLEW_OK and everything works identically.

I've run a simple program that creates an OGL 2.1 context and attempts to init Glew multiple times on a few of the systems I have lying around, and on a couple of the older ones it tends to crash while initializing Glew for the second time. So I'd rather play it safe and make sure it's not initialized more than once.

[...] so that GLEW won't be initialized if it's already present, but won't be closed upon the deletion of the OpenGL context if other contexts still rely on it.

Alright, I'll own up to that brain fart. I'm used to using libraries with both fooInit() and fooClose().

This topic is closed to new replies.

Advertisement