In the GL30
interface, both the methods glClear()
and glClearColor()
are absent. I tried to call the method Gdx.gl30.glClear(GL30.GL_COLOR_BUFFER_BIT)
inside render()
but it threw me a null pointer exception. So I checked the interface. There's no glClear()
method in GL30
. Only in GL20
. But OpenGL documentation says that they are supported in both v2.0 and v3.0. Why is it not included in LibGDX?
2 Answers
LibGDX is primary written in java, so it binds OpenGL functions to java methods. In the process of binding LibGDX is not required to keep original namespaces (java's equivalent of c/c++ namespace is package). LibGDX has a few classes which contain bindings to OpenGL functions and fields. Those classes extend each other: class containing bindings to the most recent supported version of OpenGL inherits a class with a prior version.
Lastly, GDX instantiates the last subclass so you can call any GL function from there not bothering about which specification of OpenGL implements it.
Also ,as said in another answer, you should config GDX to enable functions of OpenGL 3.0:
config.useGL30 = true;
You must configure GDX to use GL30 prior to calling functions on Gdx.gl30
:
config.useGL30 = true;
com.badlogic.gdx.graphics.GL30
does not contain glClear
and glClearColor
in its interface because it is a subclass of com.badlogic.gdx.graphics.GL20
and those functions are inherited from GL20
therefore there is no need to define them in GL30
's interface.
See the Gdx docs for Methods inherited from interface com.badlogic.gdx.graphics.GL20.
-
\$\begingroup\$ This solved the null pointer exception. Thanks! But it doesn't really answer the question I asked. \$\endgroup\$– NeerkoliJul 26, 2016 at 17:56
-
\$\begingroup\$ I've added the additional answer for those elements in your question. \$\endgroup\$– user5665Jul 26, 2016 at 18:05
LIB.gl.glClear()
? \$\endgroup\$Gdx.gl30.glClear(GL30.GL_COLOR_BUFFER_BIT);
insiderender()
but it threw me a null pointer exception. So I checked the interface. There's noglClear()
method inGL30
. Only inGL20
. \$\endgroup\$gl
inGdx
is aGL20
object. \$\endgroup\$config.useGL30 = true
? \$\endgroup\$