Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Check if GLEW already initialized?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 TooMuchCoffee   Members   -  Reputation: 144

Like
0Likes
Like

Posted 22 July 2014 - 01:06 AM

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...


Edited by TooMuchCoffee, 22 July 2014 - 01:13 AM.


Sponsor:

#2 Misantes   GDNet+   -  Reputation: 1193

Like
0Likes
Like

Posted 22 July 2014 - 01:25 AM

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


Edited by Misantes, 22 July 2014 - 01:29 AM.

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


#3 TooMuchCoffee   Members   -  Reputation: 144

Like
0Likes
Like

Posted 22 July 2014 - 02:29 PM

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.



#4 3TATUK2   Members   -  Reputation: 730

Like
0Likes
Like

Posted 22 July 2014 - 10:08 PM

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)



#5 TooMuchCoffee   Members   -  Reputation: 144

Like
0Likes
Like

Posted 25 July 2014 - 01:10 AM

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(). 


Edited by TooMuchCoffee, 25 July 2014 - 01:10 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS