libgdx / gdx-liftoff

A modern setup tool for libGDX Gradle projects
Apache License 2.0
529 stars 50 forks source link

Use ScreenUtils.clear() instead of glClear in templates #169

Closed SonicGDX closed 3 months ago

SonicGDX commented 3 months ago

This might be in other templates too, but I noticed in the classic template of liftoff that to clear the screen, this code is used:

Gdx.gl.glClearColor(0.15f, 0.15f, 0.2f, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

gdx-setup on the other hand, uses ScreenUtils.clear() instead and I think that is a much better way to do it. It's easier to understand (abstracts away gl stuff), uses one less line of code and is consistent with the libgdx.com tutorial.

I'm unaware of any advantages with using the gl methods directly as ScreenUtils.clear appears to call those anyway.

public static void clear (float r, float g, float b, float a, boolean clearDepth) {
        Gdx.gl.glClearColor(r, g, b, a);
        int mask = GL20.GL_COLOR_BUFFER_BIT;
        if (clearDepth) mask = mask | GL20.GL_DEPTH_BUFFER_BIT;
        Gdx.gl.glClear(mask);
}
tommyettinger commented 3 months ago

I've considered this before, and it could easily be time to change. If creating a project with a much older libGDX version (I think somewhere earlier in the 1.9.x version series), then ScreenUtils.clear() doesn't exist. That said, I don't think there's much reason to make such an old project; breaking changes have been few. Using ScreenUtils does seem much cleaner, so I think I'll update the templates.