Hello Guest

Use opengl commands without the opengl version

  • 5 Replies
  • 5442 Views
Use opengl commands without the opengl version
« on: June 12, 2018, 19:31:09 »
Hello, Im new to lwjgl and opengl, and I was just wondering if there is any other way to write the opengl methods without the opengl version(for example glBegin(mode); instead of GL11.glBegin(mode); ). I know you can import the opengl package in a static way like so: "import static org.lwjgl.opengl.GL11.*;" But I've heard its not good because two classes might have static fields with the same name and it can cause compiling errors. I've found one more method for that, and it is by simply adding those packages to the content assist and then when you write a method, it simply imports that specific method, it should work just fine, but I think it'll look very messy if you'll have dozens, or even hundreads of single method imports. Anyway, I'd like to get some suggestions about it, if its possible, whats the best practice, etc. Thanks for the help :)
« Last Edit: June 12, 2018, 20:07:44 by msacco »

*

Offline KaiHH

  • ****
  • 334
Re: Use opengl commands without the opengl version
« Reply #1 on: June 12, 2018, 19:42:49 »
Im new to jwgjl...
You are new to what?
Anyway, using static star imports like import static org.lwjgl.opengl.GL11.* is totally fine in LWJGL. There won't be any problems with members defined in multiple classes.

Re: Use opengl commands without the opengl version
« Reply #2 on: June 12, 2018, 20:07:18 »
Im new to jwgjl...
You are new to what?
Anyway, using static star imports like import static org.lwjgl.opengl.GL11.* is totally fine in LWJGL. There won't be any problems with members defined in multiple classes.

Eh..I assume its not hard to realize what I meant, but I meant lwjgl, so no matter how many different versions of opengl I use, there won't be compiling errors? And generally speaking, is it a bad practice using it that way? Or its fine? Thanks.

*

Offline KaiHH

  • ****
  • 334
Re: Use opengl commands without the opengl version
« Reply #3 on: June 12, 2018, 20:12:31 »
And generally speaking, is it a bad practice using it that way? Or its fine? Thanks.
It's generally fine.

Re: Use opengl commands without the opengl version
« Reply #4 on: June 12, 2018, 20:16:34 »
And generally speaking, is it a bad practice using it that way? Or its fine? Thanks.
It's generally fine.

Awesome, thanks!

*

Offline spasi

  • *****
  • 2261
    • WebHotelier
Re: Use opengl commands without the opengl version
« Reply #5 on: June 12, 2018, 20:18:53 »
And generally speaking, is it a bad practice using it that way? Or its fine? Thanks.

All LWJGL bindings are designed to be used with static imports. It's perfectly fine.

There are some exceptions with OpenGL though. Normally extensions are introduced with ARB/EXT/etc suffixes and the suffixes are dropped when an extension is promoted to core. So normally there are no conflicts. In later OpenGL versions, the extension and core functionality were introduced at the same time, both without suffixes. Importing both will cause conflicts, but (if you ever need to do that) it's easy to workaround/isolate with the right abstractions.