Search code examples
opengllibgdxrender

libgdx: where to put Gdx.gl.glClearColor()


on all tutorials I have seen about libgdx, this method is placed in the renderloop, so every loop it is 'executed'.

Isn't it better to put it in render?

I thought it was the Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

Doesn't Gdx.gl.glClearColor(0.1f, 0.1f, 0.1f, 1);

just set the color to clear the screen?

It works as expected if I put it in create


Solution

  • render is in the render loop.

    And you're right: If you only want to call glClearColor once, you can put it in create or resize.

    A single call to it per frame is negligible anyway. This isn't even worth your effort to cut and paste it to some other method. The examples you mentioned probably all put it in render right before glClear for clarity. Clarity is more important than performance if the performance difference is negligible.