Setting the glClearColor, as Josh Petrie said, is only necessary to do every frame if you do not know if another part of your program is changing it. Although, usually you would be drawing your own background, which would cover the entire background, so the color should not matter. (Of course, you still need to clear the screen every frame to prevent possible ghosting, but you understand that)
As for setting the projection matrix, it is important that you call this every frame, if you have a moving camera. If you never need to call camera.update()
, which is done after you change one of the camera's attributes, then you also need to update the batch's projection matrix. This is because the batch, or as I would assume for your case, specifically the SpriteBatch does not directly use the camera's projection matrix, instead it sets its own projection matrix to the same values as the camera's matrix, like so:
//within SpriteBatch
@Override
public void setProjectionMatrix (Matrix4 projection) {
if (drawing) flush();
projectionMatrix.set(projection); <-- this line
if (drawing) setupMatrices();
}
And the camera's projection matrix, or in your case, the combined matrix, is changed in every camera.update()
call:
//this is in OrthographicCamera
@Override
public void update (boolean updateFrustum) {
projection.setToOrtho(zoom * -viewportWidth / 2, zoom * (viewportWidth / 2), zoom * -(viewportHeight / 2), zoom
* viewportHeight / 2, near, far); <-- this line
view.setToLookAt(position, tmp.set(position).add(direction), up);
combined.set(projection); <-- this line
Matrix4.mul(combined.val, view.val); <-- and this line
if (updateFrustum) {
invProjectionView.set(combined);
Matrix4.inv(invProjectionView.val);
frustum.update(invProjectionView);
}
}
So, unless your not ever moving your camera or changing any of its attributes, then it is safer for you to set the projection matrix every frame.
For example, the Scene2D's Stage resets it every frame:
public void draw () {
Camera camera = viewport.getCamera();
camera.update(); <-- updates the camera
if (!root.isVisible()) return;
Batch batch = this.batch;
if (batch != null) {
batch.setProjectionMatrix(camera.combined); <-- resets the matrix
batch.begin();
root.draw(batch, 1);
batch.end();
}
if (debug) drawDebug();
}