libgdx / gdx-liftoff

A modern setup tool for libGDX Gradle projects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use ScreenUtils.clear() instead of glClear in templates

SonicGDX opened this issue · comments

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);
}

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.