Use opengl commands without the opengl version

Started by msacco, June 12, 2018, 19:31:09

Previous topic - Next topic

msacco

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 :)

KaiHH

Quote from: msacco on June 12, 2018, 19:31:09
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.

msacco

Quote from: KaiHH on June 12, 2018, 19:42:49
Quote from: msacco on June 12, 2018, 19:31:09
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.

KaiHH

Quote from: msacco on June 12, 2018, 20:07:18
And generally speaking, is it a bad practice using it that way? Or its fine? Thanks.
It's generally fine.

msacco

Quote from: KaiHH on June 12, 2018, 20:12:31
Quote from: msacco on June 12, 2018, 20:07:18
And generally speaking, is it a bad practice using it that way? Or its fine? Thanks.
It's generally fine.

Awesome, thanks!

spasi

Quote from: msacco on June 12, 2018, 20:07:18And 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.