Can Static import benefit?

Sorry to bother with a doubtlessly noob question, but I read about how in LWGJL you can use the “import static *” keywords to allow you simply to make gl calls, like “glVertex3f()” rather than having to use a class’s submethod. I can’t see how that would work in jogl, as you have to get the gl commands from an object and I don’t believe they are static, but the capitalized ones (GL_COLOR_BUFFER_BIT) look like they’re all static members, so could I (should I?) use a static import with jogl to make the code a little simpler?

Is there a big reason I shouldn’t? (having to type ‘gl’ twice just seems a waste, though I don’t despize it)

Thanks,
–Lareon

I use it, and I like it. There are some concerns, if it is clean from the theoretical perspective, but they sure are handy. For the extra ‘gl’, just dont use ‘GL gl = drawable.getGL()’, use something like ‘GL view= drawable.getGL()’, so you can write:


view.glBegin(GL_QUADS);
{
  view.glTexCoord2f(0.0f, 0.0f); view.glVertex3f(-1.0f, -1.0f,  1.0f);
  view.glTexCoord2f(1.0f, 0.0f); view.glVertex3f( 1.0f, -1.0f,  1.0f);
  view.glTexCoord2f(1.0f, 1.0f); view.glVertex3f( 1.0f,  1.0f,  1.0f);
  view.glTexCoord2f(0.0f, 1.0f); view.glVertex3f(-1.0f,  1.0f,  1.0f);
}
view.glEnd();

looks much better, huh ? :wink:

I like static imports for ‘java.lang.Math’ a lot, since


sqrt(pow(x,2),pow(y,2),pow(z,2))

is so much more readable than


Math.sqrt(Math.pow(x,2),Math.pow(y,2),Math.pow(z,2))

cya
cylab