Hello Guest

Why do we need to invoke functions from different OpenGL version?

  • 2 Replies
  • 265 Views
For example the following code (I copied from a tutorial site) invokes gl fucntions from GL30, GL20 and GL11.

Code: [Select]
GL30.glBindVertexArray(model.getVaoID());
GL20.glEnableVertexAttribArray(0);
GL11.glDrawElements(GL11.GL_TRIANGLES, model.getVertexCount(),  GL11.GL_UNSIGNED_INT, 0);
GL20.glDisableVertexAttribArray(0);
GL30.glBindVertexArray(0);             

I played with the code myself a little bit and found that if I change everything to GL30, the program still runs fine.
I understand that some functions were introduced in earlier version of OpenGL, but since the same functions are
also supported by the later versions of OpenGL, why do we still invoke them from the earlier versions of OpenGL?


Thanks in advance!
Pan

*

Offline KaiHH

  • ****
  • 207
The tutorial probably was written against LWJGL < 3.2.0. Before 3.2.0, a GLxx classes did not inherit from the GLyy class where yy denoted the previous GL version prior to version xx. There you had to invoke the static methods of the GLxx class where the particular function/method you wanted to invoke was introduced in GL version xx.
Starting with LWJGL 3.2.0 you can just use GL functions introduced prior to and including version xx by calling static methods of class GLxx.
So it's just a question of which LWJGL version that particular tutorial was written against and whether the author actually knew about the added class hierarchy.

You are are right, the tutorial was created in 2014, so the author did not have access to LWJGL  3.2.0 or later.

Now I can simply import the the highest version of GL classes in my code, and it works like a charm:

Code: [Select]
      //import the highest version of GL classes
      import static org.lwjgl.opengl.GL46.*;

      glBindVertexArray(model.getVaoID());
      glEnableVertexAttribArray(0);
      glDrawElements(GL_TRIANGLES, model.getVertexCount(),  GL_UNSIGNED_INT, 0);
      glDisableVertexAttribArray(0);
      glBindVertexArray(0);

It also saves quite bit of typing too :-)
« Last Edit: June 02, 2019, 01:38:09 by phu004 »