This is my first question. I have tried to look at the source (link) Searched stackoverflow and read some general explanations. But i don't get any wiser as to how to set it up (or understand) it correctly.
I don't understand projection-matrices or much of the GL terms. I don't know what happens when you set camera (camera.setToOrtho()) when you should update the camera or when to set the batch's projection matrix. Up to now my only use of this was limited to the code used in the draw() method shown below.
I have a tile-based game with layers. i would like to use a FrameBuffer to draw the water-layer to a TextureRegion. So i can later try to manipulate it with shaders. I Think that would be the way to do this.
(I am not using any "Scene2d" or "Tiled" classes)
Example of what the layer looks like
How i draw my layers:
public void draw(OrthographicCamera camera) {
Gdx.gl.glClearColor(0, 0, 0, 0);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA,GL20.GL_ONE_MINUS_SRC_ALPHA); // [1]
BATCH.setProjectionMatrix(camera.combined);
BATCH.begin();
for (int i = 0; i < NUM_LAYERS; i++) {
if (RENDER[i]) {
if (SORT[i]) Collections.sort(LAYERS.get(i));
for (DrwDat dat: LAYERS.get(i)) { // [2]
dat.draw(BATCH);
}
}
}
BATCH.end();
}
1. Not sure what this does but i don't seem to need it. [2]. DrwDat is just a class that holds the drawable objects. In this case these are the tiles.
Ok. So in the draw loop i place a method to be called when i draw the water-layer. For now i would like to draw every tile that's supposed to be shown on screen and instead draw them to the buffer. Then: draw the buffer to the screen.
Question: What can i put in the "renderFBO()" method below to make it work? And why? To basically have the screen show exactly what it would show without using the FrameBuffer
(The current code is pure desperation and is the way it is because i tried to use a youtube tutorial as a template without understanding it.)
private void renderFBO(OrthographicCamera camera, int layer) {
BATCH.end();
frameBuffer.begin();
Gdx.gl.glClearColor(0, 0, 0, 0);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
BATCH.begin();
camera.setToOrtho(false);
camera.position.set(FocusPoint.position.x,FocusPoint.position.y,0); // [3]
camera.update();
BATCH.setProjectionMatrix(camera.combined);
for (DrwDat dat: LAYERS.get(layer)) {
dat.draw(BATCH);
}
frameBuffer.end(); // [4]
BATCH.end();
camera.setToOrtho(false);
//BATCH.setProjectionMatrix(camera.combined);
BATCH.begin();
BATCH.draw(bufferTexture.getTexture(),0,0,Settings.SCREEN_W,Settings.SCREEN_H);
BATCH.end();
camera.position.set(FocusPoint.position.x,FocusPoint.position.y,0);
camera.update();
BATCH.setProjectionMatrix(camera.combined);
BATCH.begin();
}
[3]. FocusPoint is just a point the camera follows (for instance: mouse click position)
[4]. For some reason having framebuffer.end() below batch.end() renders nothing.
Here is how i initialize the FrameBuffer:
private FrameBuffer frameBuffer = new FrameBuffer(Pixmap.Format.RGBA8888,Settings.SCREEN_W,Settings.SCREEN_H,false);
private TextureRegion bufferTexture = new TextureRegion(frameBuffer.getColorBufferTexture());
I'm sorry if this was too general. But any help is appreciated. Any tips for what i could read would also be very helpful.