Using OpenGL commands in static initialization block

Started by Whackjack, January 27, 2006, 23:03:12

Previous topic - Next topic

Whackjack

The subject is the question.  Can/should I do any OpenGL work in a static initialization block of a class, e.g.

static
{
    GL11.glGenLists(1);
    // do more gl stuff
}


My question, more directly, is, will the OpenGL libraries be fully loaded by the time my class has been loaded by the classloader and the static block runs?

WiESi

You can only do this if a display was created before.

WiESi

Whackjack

Okay, I guess that makes sense.  It can be presumed that nothing OpenGL related can be done until Display.create() is called, yes?
That would certainly preclude any OpenGL commands in a class static code block.
I do have a work around, in that case, but it's not as elegant as a static block.

darkprophet

The static block is only called when anything from that object is called.


I.e. "SomeObject.SomeField" or "SomeObject.someMethod" or even a constructor...

If you can be sure that a valid context* is available before doing anything with that class, your ok.

DP

Whackjack

So the question then becomes... How can I make sure that a valid context exists before the class loads?  And the answer will be, don't reference the class until Display.create() has been called.
That all seems way too JVM specific for me.  I think I'll stick to the alternative, a static init flag.

Evil-Devil

You might add an if conditional like

if (Display.isCreated())

and then call your static init stuff.
And to make sure that it really init a init variable might be usefull or a reference to the class that calls Display.create() so your static block may be able to call it too.