Reputation: 3340
I'm working with the libgdx framework and I'm not sure what is the preferred way to access the opengl API, My application uses OpenGl 2.0 (the useGL20 flag is set to true). Now to clear for example the screen I can do:
Gdx.gl20.glClearColor(0, 0, 0, 0xff);
Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT);
but I can also do:
Gdx.gl.glClearColor(0, 0, 0, 0xff);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);*
Of course both have the same result, but is one way preferred above the other? What is the resulting difference when using Gdx.gl20
vs Gdx.gl
?
Note that in the latest version of libgdx, openGl 1.x is completely removed and Gdx.gl
is simply an interface wrapping of Gdx.Gl20
. However I'm using an older version (v.0.9.9) of libgdx which still has support for openGl 1.x
Upvotes: 1
Views: 1532
Reputation: 49
Basic functionality supported by all versions of OpenGL, but each new version of openGL has some extensions and improvments. Run following code and see what you can do on your PC.
if( app.getGraphics().isGL20Available() )
app.log( "my app", "yay, we can do shaders!" );
if( app.getGraphics().isGL11Available() )
app.log( "my app", "yay, we can use vertex buffer objects" )
if( app.getGraphics().isGL10Available() )
app.log( "my app", "oh crap, stone age time" );
OpenGL ES 1.1 is backward compatible with OpenGL 1.0, so if 1.1 is available so will 1.0. NOTE: if OpenGL ES 2.0 is available neither OpenGL ES 1.1 nor 1.0 will be available and vice versa as 1.x and 2.0 are not compatible!
Note again: when OpenGL ES 2.0 is available then Graphics.getGL10() and Graphics.getGL11() will return null and vice versa. If OpenGL ES 1.1 is available then you can either get a GL10 or a GL11 interface. If only OpenGL ES 1.0 is available you can only get a GL10 interface.
The interface GL10, GL11 and GL20 implement the full OpenGL ES specifications.
Upvotes: 3
Reputation: 93759
It doesn't matter, since it references the same object. If you want to support GLES 3.0 down the road (when it's fully implemented in libgdx), I'd go with gl
so you won't have to refactor as much code later. Then in your AndroidLauncher class, you can select which one you want (2.0 or 3.0) in your ApplicationConfiguration, based on the device capabilities. Most of your core code won't even need to know which one's being used; you would only need to worry about checking in places where you use 3.0-specific features.
Upvotes: 3
Reputation: 37063
edit: this reflects version 1.5 and clashes with an edit OP made, yet the part about dealing with the versions holds true
you are free to use whatever in this special case, as you can see in https://github.com/libgdx/libgdx/blob/3f49a73ae24014964db439cd7d98a935dc30f13e/gdx/src/com/badlogic/gdx/Gdx.java they are of the same type GL20
. *)
But as you see, there is also gl30
. What it means is, that different GL version support different functions and in java all this functions are bundled in this different interfaces and backed by some class. In reality for such a simple and decade old function like glClear
this means on machine level most likely nothing, as the same functions in the driver sooner or later will be called. But you using the one interface over the other is stating in your code, that your application expects a certain version of GL.
TL;DR: if you need gl2.0 features, that are not in 3.0, and you want to be on the safe side, then use gl20
, because nobody knows, what the libgdx authors change gl
to in newer versions. But right now, it's the baseline and using gl
will safe you some keystrokes.
*) beeing of the same interface; this does not mean, that they are really identically initialized or backed by the same instance.
Upvotes: 3
Reputation: 49
it depends what opengl features you are going to use, please check out following thread: How do I support OpenGL ES GL10, GL11, and GL20 in Libgdx?
Upvotes: -1