background now renders! yay.

This commit is contained in:
Harrison Deng 2018-03-16 17:56:42 -05:00
parent 8fd727e7d6
commit 5ae598db36

View File

@ -6,6 +6,7 @@ import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Pixmap.Format; import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.g2d.TextureRegion;
@ -59,7 +60,10 @@ public class MainMenuScreen extends ScreenAdapter implements AdvancedResizeScree
private TextureRegion fboRegion; private TextureRegion fboRegion;
private int fboSize; private int fboSize;
private int blurlvl; private int blurlvl;
private Batch batch;
private Texture background;
private Batch screenBatch;
private ScreenViewport screenViewport; private ScreenViewport screenViewport;
public MainMenuScreen(RhythmBullet core) { public MainMenuScreen(RhythmBullet core) {
@ -88,7 +92,7 @@ public class MainMenuScreen extends ScreenAdapter implements AdvancedResizeScree
stage.getViewport().apply(); stage.getViewport().apply();
Gdx.gl.glClearColor(0f, 0f, 0f, 1f); Gdx.gl.glClearColor(0f, 0f, 0f, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.draw(); draw();
normalBuffer.end(); normalBuffer.end();
// BEGINNING NORMAL SCREEN RENDER // BEGINNING NORMAL SCREEN RENDER
@ -99,11 +103,11 @@ public class MainMenuScreen extends ScreenAdapter implements AdvancedResizeScree
Gdx.gl.glClearColor(0f, 0f, 0f, 1f); Gdx.gl.glClearColor(0f, 0f, 0f, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
fboRegion.setTexture(normalBuffer.getColorBufferTexture()); fboRegion.setTexture(normalBuffer.getColorBufferTexture());
batch.setShader(brightFilterShader); screenBatch.setShader(brightFilterShader);
batch.setProjectionMatrix(screenViewport.getCamera().combined); screenBatch.setProjectionMatrix(screenViewport.getCamera().combined);
batch.begin(); //BATCH STARTS HERE screenBatch.begin(); //BATCH STARTS HERE
batch.draw(fboRegion, 0, 0, stage.getWidth(), stage.getHeight()); screenBatch.draw(fboRegion, 0, 0, stage.getWidth(), stage.getHeight());
batch.flush(); screenBatch.flush();
lightFilterBuffer.end(); lightFilterBuffer.end();
// //
for (int i = 0; i < blurlvl; i++) { for (int i = 0; i < blurlvl; i++) {
@ -114,32 +118,32 @@ public class MainMenuScreen extends ScreenAdapter implements AdvancedResizeScree
} else { } else {
fboRegion.setTexture(lightFilterBuffer.getColorBufferTexture()); fboRegion.setTexture(lightFilterBuffer.getColorBufferTexture());
} }
batch.setShader(gaussianBlurShader); screenBatch.setShader(gaussianBlurShader);
gaussianBlurShader.setUniformi("horizontal", 1); gaussianBlurShader.setUniformi("horizontal", 1);
batch.draw(fboRegion, 0f, 0f, stage.getWidth(), stage.getHeight()); screenBatch.draw(fboRegion, 0f, 0f, stage.getWidth(), stage.getHeight());
batch.flush(); screenBatch.flush();
hBlur.end(); hBlur.end();
// //Vertical gaussian blur // //Vertical gaussian blur
vBlur.begin(); vBlur.begin();
fboRegion.setTexture(hBlur.getColorBufferTexture()); fboRegion.setTexture(hBlur.getColorBufferTexture());
batch.setShader(gaussianBlurShader); screenBatch.setShader(gaussianBlurShader);
gaussianBlurShader.setUniformi("horizontal", 0); gaussianBlurShader.setUniformi("horizontal", 0);
batch.draw(fboRegion, 0f, 0f, stage.getWidth(), stage.getHeight()); screenBatch.draw(fboRegion, 0f, 0f, stage.getWidth(), stage.getHeight());
batch.flush(); screenBatch.flush();
vBlur.end(); vBlur.end();
} }
Gdx.gl.glClearColor(0f, 0f, 0f, 0f); Gdx.gl.glClearColor(0f, 0f, 0f, 0f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.setShader(combineShader); screenBatch.setShader(combineShader);
fboRegion.setTexture(normalBuffer.getColorBufferTexture()); fboRegion.setTexture(normalBuffer.getColorBufferTexture());
batch.draw(fboRegion, 0f, 0f, fboSize, fboSize); screenBatch.draw(fboRegion, 0f, 0f, fboSize, fboSize);
batch.setShader(null); screenBatch.setShader(null);
batch.end(); //STAGE BATCH ENDS HERE screenBatch.end(); //STAGE BATCH ENDS HERE
} else { } else {
stage.draw(); draw();
} }
if (stage.getCamera().position.x != cameraPosition.x || stage.getCamera().position.y != cameraPosition.y) { if (stage.getCamera().position.x != cameraPosition.x || stage.getCamera().position.y != cameraPosition.y) {
@ -149,6 +153,16 @@ public class MainMenuScreen extends ScreenAdapter implements AdvancedResizeScree
super.render(delta); super.render(delta);
} }
private void draw() {
if (background != null) {
screenBatch.begin();
screenBatch.draw(background, 0, 0);
screenBatch.end();
}
stage.draw();
}
@Override @Override
public void preAssetLoad() { public void preAssetLoad() {
stage.clear(); stage.clear();
@ -160,10 +174,14 @@ public class MainMenuScreen extends ScreenAdapter implements AdvancedResizeScree
dismantleShaders(); dismantleShaders();
setBlurlvl(0); setBlurlvl(0);
background = null;
} }
@Override @Override
public void postAssetLoad() { public void postAssetLoad() {
background = core.getAssetManager().get("backgrounds/mainBG.png", Texture.class);
if (core.getPrefs().getBoolean("glow shader", true)) { if (core.getPrefs().getBoolean("glow shader", true)) {
setupShaders(); setupShaders();
@ -276,7 +294,7 @@ public class MainMenuScreen extends ScreenAdapter implements AdvancedResizeScree
public void setupShaders() { public void setupShaders() {
Gdx.app.debug("Shader", "Loading glow shaders."); Gdx.app.debug("Shader", "Loading glow shaders.");
batch = new SpriteBatch(); screenBatch = new SpriteBatch();
screenViewport = new ScreenViewport(); screenViewport = new ScreenViewport();
screenViewport.update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); screenViewport.update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
((OrthographicCamera) screenViewport.getCamera()).setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); ((OrthographicCamera) screenViewport.getCamera()).setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());