options have been added back

This commit is contained in:
Harrison Deng 2017-10-10 00:51:36 -05:00
parent 3845b7495b
commit 29e4b7e901
7 changed files with 158 additions and 144 deletions

View File

@ -130,9 +130,11 @@ public class BasicVisualizer extends VisualizerCore {
barWidth = MathUtils.ceil((float) width/(float) barCount); barWidth = MathUtils.ceil((float) width/(float) barCount);
barWidth -= spaceBetweenBars; barWidth -= spaceBetweenBars;
for (int i = 0; i < bars.length; i++) { for (int i = 0; i < bars.length; i++) {
barSpace = i*(barWidth+spaceBetweenBars); barSpace = i*(barWidth+spaceBetweenBars);
if (i == bars.length - 1) {
barSpace -= 2;
}
if (flip) { if (flip) {
bars[i].setRotation(rotation+180); bars[i].setRotation(rotation+180);
} else { } else {

View File

@ -43,8 +43,11 @@ public class MirrorVisualizer {
} else { } else {
bars[i].setRotation(rotation); bars[i].setRotation(rotation);
} }
int barSpace = i*(barWidth+spaceBetweenBars);
bars[i].setPosition(xPos + i*barSpaceMultiplier*rectCoordRot.x, yPos + i*barSpaceMultiplier*rectCoordRot.y); if (i == bars.length - 1) {
barSpace -= 2;
}
bars[i].setPosition(xPos + barSpace*rectCoordRot.x, yPos + barSpace*rectCoordRot.y);
} }
} }

View File

@ -77,7 +77,6 @@ public class MainPage extends Page implements OnDifferentSongListener {
@Override @Override
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
Gdx.app.exit(); Gdx.app.exit();
System.exit(0);
} }
}); });
table.add(quitButton).fillX(); table.add(quitButton).fillX();

View File

@ -15,6 +15,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextField; import com.badlogic.gdx.scenes.scene2d.ui.TextField;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.utils.Align;
import zero1hd.rhythmbullet.RhythmBullet; import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.audio.SongListController; import zero1hd.rhythmbullet.audio.SongListController;
@ -28,18 +29,31 @@ public class OptionsPage extends Page {
private TextField directoryField; private TextField directoryField;
public OptionsPage(RhythmBullet core, Vector3 targetPosition, MoreOptionsPage moreOptionsPage, SongListController sc) { public OptionsPage(RhythmBullet core, Vector3 targetPosition, MoreOptionsPage moreOptionsPage, SongListController sc) {
optionsTable.defaults().spaceLeft(40f).padTop(5f).padBottom(5f).left(); super("General", core.getDefaultSkin());
Label optionGeneralTitle = new Label("General", core.getDefaultSkin(), "large-font", core.getDefaultSkin().getColor("default")); //Back button
optionsTable.add(optionGeneralTitle).left().spaceBottom(10f); TextButton backButton = new TextButton("Back", core.getDefaultSkin());
backButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
targetPosition.x = 0.5f*Gdx.graphics.getWidth();
}
});
backButton.setPosition(10, getHeightBelowTitle() + 5);
addActor(backButton);
addSpaceToTitle(backButton.getWidth() + backButton.getX() + 20);
optionsTable.row(); optionsTable.align(Align.center);
optionsTable.defaults().space(10f).expandY().padBottom(25f);
optionsTable.setPosition(0, 0);
optionsTable.setSize(getWidth(), getHeightBelowTitle() - 5);
addActor(optionsTable);
Label musicVolSliderLabel = new Label("Music Volume: ", core.getDefaultSkin()); Label musicVolSliderLabel = new Label("Music Volume: ", core.getDefaultSkin());
optionsTable.add(musicVolSliderLabel).padRight(12f).left(); optionsTable.add(musicVolSliderLabel).left();
musicVolSlider = new Slider(0, 100, 0.1f, false, core.getDefaultSkin()); musicVolSlider = new Slider(0, 100, 0.1f, false, core.getDefaultSkin());
musicVolSlider.setValue(core.getPrefs().getFloat("music vol", 100f)*100f); musicVolSlider.setValue(core.getPrefs().getFloat("music vol", 100f)*100f);
optionsTable.add(musicVolSlider).prefWidth(790).left(); optionsTable.add(musicVolSlider).spaceRight(15f).prefWidth(0.5f*getWidth()).fillX();
final Label musicVolPercentage = new Label(MathUtils.round(musicVolSlider.getValue()) + "%", core.getDefaultSkin()); final Label musicVolPercentage = new Label(MathUtils.round(musicVolSlider.getValue()) + "%", core.getDefaultSkin());
musicVolSlider.addListener(new ChangeListener() { musicVolSlider.addListener(new ChangeListener() {
@Override @Override
@ -50,15 +64,15 @@ public class OptionsPage extends Page {
core.getPrefs().putFloat("music vol", musicVolSlider.getPercent()); core.getPrefs().putFloat("music vol", musicVolSlider.getPercent());
} }
}); });
optionsTable.add(musicVolPercentage).expandX(); optionsTable.add(musicVolPercentage).center();
optionsTable.row(); optionsTable.row();
Label fxVolSliderLabel = new Label("FX Volume: ", core.getDefaultSkin()); Label fxVolSliderLabel = new Label("FX Volume: ", core.getDefaultSkin());
optionsTable.add(fxVolSliderLabel).padRight(12f).left(); optionsTable.add(fxVolSliderLabel).left();
fxVolSlider = new Slider(0, 100, 1, false, core.getDefaultSkin()); fxVolSlider = new Slider(0, 100, 0.1f, false, core.getDefaultSkin());
fxVolSlider.setValue(core.getPrefs().getFloat("fx vol", 100f)*100f); fxVolSlider.setValue(core.getPrefs().getFloat("fx vol", 100f)*100f);
optionsTable.add(fxVolSlider).prefWidth(790); optionsTable.add(fxVolSlider).spaceRight(15f).prefWidth(0.5f*getWidth()).fillX();
final Label fxVolPercentage = new Label(MathUtils.round(fxVolSlider.getValue()) + "%", core.getDefaultSkin()); final Label fxVolPercentage = new Label(MathUtils.round(fxVolSlider.getValue()) + "%", core.getDefaultSkin());
fxVolSlider.addListener(new ChangeListener() { fxVolSlider.addListener(new ChangeListener() {
@Override @Override
@ -68,7 +82,7 @@ public class OptionsPage extends Page {
} }
}); });
optionsTable.add(fxVolPercentage); optionsTable.add(fxVolPercentage).center();
optionsTable.row(); optionsTable.row();
@ -76,33 +90,18 @@ public class OptionsPage extends Page {
optionsTable.add(musicDirectoryLabel).left(); optionsTable.add(musicDirectoryLabel).left();
directoryField = new TextField(null, core.getDefaultSkin()); directoryField = new TextField(null, core.getDefaultSkin());
directoryField.setText(core.getPrefs().getString("music dir", System.getProperty("user.home")+System.getProperty("file.separator")+"Music")); directoryField.setText(core.getPrefs().getString("music dir", System.getProperty("user.home")+System.getProperty("file.separator")+"Music"));
optionsTable.add(directoryField).prefWidth(810).left(); optionsTable.add(directoryField).fillX();
optionsTable.row(); optionsTable.row();
Label debugCodeLabel = new Label("Debug Code: ", core.getDefaultSkin()); Label debugCodeLabel = new Label("Debug Code: ", core.getDefaultSkin());
optionsTable.add(debugCodeLabel).left(); optionsTable.add(debugCodeLabel).left();
final TextField debugCodeField = new TextField(null, core.getDefaultSkin()); final TextField debugCodeField = new TextField(null, core.getDefaultSkin());
optionsTable.add(debugCodeField).prefWidth(810).left(); optionsTable.add(debugCodeField).fillX();
optionsTable.top(); optionsTable.top();
//Back button
TextButton backButton = new TextButton("Back", core.getDefaultSkin());
backButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
targetPosition.x = 0.5f*Gdx.graphics.getWidth();
}
});
backButton.setPosition(10, getHeight()-backButton.getHeight()-18);
addActor(backButton);
optionsTable.setPosition(backButton.getX()+ 20 + backButton.getWidth(), 0);
optionsTable.setSize(getWidth()-backButton.getWidth()-10-20-10, getHeight());
addActor(optionsTable);
optionsTable.row(); optionsTable.row();
TextButton keybindSettings = new TextButton("Set Controls", core.getDefaultSkin()); TextButton keybindSettings = new TextButton("Set Controls", core.getDefaultSkin());
@ -113,7 +112,7 @@ public class OptionsPage extends Page {
targetPosition.y = -0.5f*Gdx.graphics.getHeight(); targetPosition.y = -0.5f*Gdx.graphics.getHeight();
} }
}); });
optionsTable.add(keybindSettings).colspan(2).fill(); optionsTable.add(keybindSettings).colspan(2).fillX();
optionsTable.row(); optionsTable.row();
@ -125,7 +124,7 @@ public class OptionsPage extends Page {
targetPosition.y = -0.5f*Gdx.graphics.getHeight(); targetPosition.y = -0.5f*Gdx.graphics.getHeight();
} }
}); });
optionsTable.add(graphicsSettings).colspan(2).fill(); optionsTable.add(graphicsSettings).colspan(2).fillX();
addListener(new InputListener() { addListener(new InputListener() {
@Override @Override
public boolean keyUp(InputEvent event, int keycode) { public boolean keyUp(InputEvent event, int keycode) {

View File

@ -33,6 +33,10 @@ public class Page extends Group implements Disposable {
return pageTitle.getY(); return pageTitle.getY();
} }
public void addSpaceToTitle(float space) {
pageTitle.moveBy(space, 0);
}
@Override @Override
public void dispose() { public void dispose() {
} }

View File

@ -6,12 +6,15 @@ import com.badlogic.gdx.Screen;
import com.badlogic.gdx.ScreenAdapter; import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Pixmap.Format; import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.glutils.FrameBuffer; import com.badlogic.gdx.graphics.glutils.FrameBuffer;
import com.badlogic.gdx.graphics.glutils.ShaderProgram; import com.badlogic.gdx.graphics.glutils.ShaderProgram;
import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton; import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import zero1hd.rhythmbullet.RhythmBullet; import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.audio.MusicManager; import zero1hd.rhythmbullet.audio.MusicManager;
@ -37,7 +40,8 @@ public class GameScreen extends ScreenAdapter {
private FrameBuffer hBlur, vBlur; private FrameBuffer hBlur, vBlur;
private TextureRegion fboRegion; private TextureRegion fboRegion;
private int fboSize; private int fboSize;
private Batch batch;
private ScreenViewport screenViewport;
private int blurlvl = 4; private int blurlvl = 4;
/** /**
@ -88,6 +92,9 @@ public class GameScreen extends ScreenAdapter {
*/ */
public void loadShaders() { public void loadShaders() {
if (core.getPrefs().getBoolean("glow shader")) { if (core.getPrefs().getBoolean("glow shader")) {
batch = new SpriteBatch();
screenViewport = new ScreenViewport();
Gdx.app.debug("Shader", "using glow shader"); Gdx.app.debug("Shader", "using glow shader");
brightFilterShader = new ShaderProgram(Gdx.files.internal("shaders/basic.vsh"), Gdx.files.internal("shaders/bright_filter.fsh")); brightFilterShader = new ShaderProgram(Gdx.files.internal("shaders/basic.vsh"), Gdx.files.internal("shaders/bright_filter.fsh"));
if (!brightFilterShader.isCompiled()) { if (!brightFilterShader.isCompiled()) {
@ -125,12 +132,13 @@ public class GameScreen extends ScreenAdapter {
fboSize = 4096; fboSize = 4096;
} }
lightFilterBuffer = new FrameBuffer(Format.RGBA8888, fboSize/4, fboSize/4, false); lightFilterBuffer = new FrameBuffer(Format.RGBA8888, fboSize/2, fboSize/2, false);
normalBuffer = new FrameBuffer(Format.RGBA8888, fboSize, fboSize, false); normalBuffer = new FrameBuffer(Format.RGBA8888, fboSize, fboSize, false);
hBlur = new FrameBuffer(Format.RGBA8888, fboSize, fboSize, false); hBlur = new FrameBuffer(Format.RGBA8888, fboSize/2, fboSize/2, false);
vBlur = new FrameBuffer(Format.RGBA8888, fboSize, fboSize, false); vBlur = new FrameBuffer(Format.RGBA8888, fboSize/2, fboSize/2, false);
fboRegion = new TextureRegion(); fboRegion = new TextureRegion(normalBuffer.getColorBufferTexture());
fboRegion.flip(false, true);
combineShader.begin(); combineShader.begin();
combineShader.setUniformi("u_texture1", 1); combineShader.setUniformi("u_texture1", 1);
@ -161,93 +169,78 @@ public class GameScreen extends ScreenAdapter {
blurlvl = 4; blurlvl = 4;
if (gaussianBlurShader != null) { if (gaussianBlurShader != null) {
//Begin drawing a normal version of screen //Begin drawing a normal version of screen
gameArea.getViewport().apply();
normalBuffer.begin(); normalBuffer.begin();
Gdx.gl.glClearColor(0f, 0f, 0f, 0f); Gdx.gl.glClearColor(0.22f, 0f, 0f, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
gameArea.draw(); gameArea.draw();
gameArea.getCollisionDetector().renderParticles(gameArea.getBatch(), Gdx.graphics.getDeltaTime(), true); normalBuffer.end();
normalBuffer.end( //END STAGE BATCH
gameArea.getViewport().getScreenX(),
gameArea.getViewport().getScreenY(),
gameArea.getViewport().getScreenWidth(),
gameArea.getViewport().getScreenHeight());
//END
//BEGINNING NORMAL SCREEN RENDER
screenViewport.apply();
//Begin light filtering //Begin light filtering
lightFilterBuffer.begin(); lightFilterBuffer.begin();
Gdx.gl.glClearColor(0f, 0f, 0f, 0f); Gdx.gl.glClearColor(0f, 0f, 0f, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
gameArea.getBatch().setShader(brightFilterShader); fboRegion.setTexture(normalBuffer.getColorBufferTexture());
gameArea.getBatch().begin(); //BATCH STARTS HERE batch.setShader(brightFilterShader);
gameArea.getRoot().draw(gameArea.getBatch(), 1f); batch.begin(); //BATCH STARTS HERE
gameArea.getBatch().flush(); batch.draw(fboRegion, 0, 0, gameArea.getWidth(), gameArea.getHeight());
lightFilterBuffer.end( batch.flush();
gameArea.getViewport().getScreenX(), lightFilterBuffer.end();
gameArea.getViewport().getScreenY(),
gameArea.getViewport().getScreenWidth(),
gameArea.getViewport().getScreenHeight());
//Horizontal gaussian blur //Horizontal gaussian blur
hBlur.begin(); hBlur.begin();
fboRegion.setRegion(lightFilterBuffer.getColorBufferTexture()); Gdx.gl.glClearColor(0f, 0f, 0f, 1f);
gameArea.getBatch().setShader(gaussianBlurShader); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
fboRegion.setTexture(lightFilterBuffer.getColorBufferTexture());
batch.setShader(gaussianBlurShader);
gaussianBlurShader.setUniformi("horizontal", 1); gaussianBlurShader.setUniformi("horizontal", 1);
gameArea.getBatch().draw(fboRegion, 0f, 0f, RhythmBullet.GAME_AREA_WIDTH, RhythmBullet.GAME_AREA_HEIGHT); batch.draw(fboRegion, 0f, 0f, gameArea.getWidth(), gameArea.getHeight());
gameArea.getBatch().flush(); batch.flush();
hBlur.end( hBlur.end();
gameArea.getViewport().getScreenX(),
gameArea.getViewport().getScreenY(),
gameArea.getViewport().getScreenWidth(),
gameArea.getViewport().getScreenHeight());
//Vertical gaussian blur //Vertical gaussian blur
vBlur.begin(); vBlur.begin();
fboRegion.setRegion(hBlur.getColorBufferTexture()); Gdx.gl.glClearColor(0f, 0f, 0f, 1f);
gameArea.getBatch().setShader(gaussianBlurShader); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
fboRegion.setTexture(hBlur.getColorBufferTexture());
batch.setShader(gaussianBlurShader);
gaussianBlurShader.setUniformi("horizontal", 0); gaussianBlurShader.setUniformi("horizontal", 0);
gameArea.getBatch().draw(fboRegion, 0f, 0f, RhythmBullet.GAME_AREA_WIDTH, RhythmBullet.GAME_AREA_HEIGHT); batch.draw(fboRegion, 0f, 0f, gameArea.getWidth(), gameArea.getHeight());
gameArea.getBatch().flush(); batch.flush();
vBlur.end( vBlur.end();
gameArea.getViewport().getScreenX(),
gameArea.getViewport().getScreenY(),
gameArea.getViewport().getScreenWidth(),
gameArea.getViewport().getScreenHeight());
for (int i = 0; i < blurlvl; i++) { for (int i = 0; i < blurlvl; i++) {
//Horizontal gaussian blur //Horizontal gaussian blur
hBlur.begin(); hBlur.begin();
fboRegion.setRegion(vBlur.getColorBufferTexture()); fboRegion.setTexture(vBlur.getColorBufferTexture());
gameArea.getBatch().setShader(gaussianBlurShader); batch.setShader(gaussianBlurShader);
gaussianBlurShader.setUniformi("horizontal", 1); gaussianBlurShader.setUniformi("horizontal", 1);
gameArea.getBatch().draw(fboRegion, 0f, 0f, RhythmBullet.GAME_AREA_WIDTH, RhythmBullet.GAME_AREA_HEIGHT); batch.draw(fboRegion, 0f, 0f, gameArea.getWidth(), gameArea.getHeight());
gameArea.getBatch().flush(); batch.flush();
hBlur.end( hBlur.end();
gameArea.getViewport().getScreenX(),
gameArea.getViewport().getScreenY(),
gameArea.getViewport().getScreenWidth(),
gameArea.getViewport().getScreenHeight());
//Vertical gaussian blur //Vertical gaussian blur
vBlur.begin(); vBlur.begin();
fboRegion.setRegion(hBlur.getColorBufferTexture()); fboRegion.setTexture(hBlur.getColorBufferTexture());
gameArea.getBatch().setShader(gaussianBlurShader); batch.setShader(gaussianBlurShader);
gaussianBlurShader.setUniformi("horizontal", 0); gaussianBlurShader.setUniformi("horizontal", 0);
gameArea.getBatch().draw(fboRegion, 0f, 0f, RhythmBullet.GAME_AREA_WIDTH, RhythmBullet.GAME_AREA_HEIGHT); batch.draw(fboRegion, 0f, 0f, gameArea.getWidth(), gameArea.getHeight());
gameArea.getBatch().flush(); batch.flush();
vBlur.end( vBlur.end();
gameArea.getViewport().getScreenX(),
gameArea.getViewport().getScreenY(),
gameArea.getViewport().getScreenWidth(),
gameArea.getViewport().getScreenHeight());
} }
//Draw everything to screen //draw a final copy to a fbo
gameArea.getBatch().setShader(combineShader); Gdx.gl.glClearColor(0f, 0f, 0f, 0f);
fboRegion.setRegion(normalBuffer.getColorBufferTexture()); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
fboRegion.flip(false, true); batch.setShader(combineShader);
gameArea.getBatch().draw(fboRegion, 0f, 0f, RhythmBullet.GAME_AREA_WIDTH, RhythmBullet.GAME_AREA_HEIGHT); fboRegion.setTexture(normalBuffer.getColorBufferTexture());
gameArea.getBatch().setShader(null); batch.draw(fboRegion, 0f, 0f, gameArea.getWidth(), gameArea.getHeight());
gameArea.getBatch().end(); //BATCH ENDS HERE batch.setShader(null);
batch.end(); //STAGE BATCH ENDS HERE
} else { } else {
gameArea.draw(); gameArea.draw();
} }

View File

@ -4,8 +4,9 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys; import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.ScreenAdapter; 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.Pixmap.Format; import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.glutils.FrameBuffer; import com.badlogic.gdx.graphics.glutils.FrameBuffer;
import com.badlogic.gdx.graphics.glutils.ShaderProgram; import com.badlogic.gdx.graphics.glutils.ShaderProgram;
@ -17,12 +18,12 @@ import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.viewport.ScreenViewport; import com.badlogic.gdx.utils.viewport.ScreenViewport;
import zero1hd.rhythmbullet.RhythmBullet; import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.audio.SongList;
import zero1hd.rhythmbullet.audio.SongListController; import zero1hd.rhythmbullet.audio.SongListController;
import zero1hd.rhythmbullet.graphics.ui.pages.CreditsPage; import zero1hd.rhythmbullet.graphics.ui.pages.CreditsPage;
import zero1hd.rhythmbullet.graphics.ui.pages.MainPage; import zero1hd.rhythmbullet.graphics.ui.pages.MainPage;
import zero1hd.rhythmbullet.graphics.ui.pages.MoreOptionsPage; import zero1hd.rhythmbullet.graphics.ui.pages.MoreOptionsPage;
import zero1hd.rhythmbullet.graphics.ui.pages.OptionsPage; import zero1hd.rhythmbullet.graphics.ui.pages.OptionsPage;
import zero1hd.rhythmbullet.audio.SongList;
import zero1hd.rhythmbullet.util.TransitionAdapter; import zero1hd.rhythmbullet.util.TransitionAdapter;
public class MainMenu extends ScreenAdapter implements TransitionAdapter { public class MainMenu extends ScreenAdapter implements TransitionAdapter {
@ -47,8 +48,9 @@ public class MainMenu extends ScreenAdapter implements TransitionAdapter {
private FrameBuffer hBlur, vBlur; private FrameBuffer hBlur, vBlur;
private TextureRegion fboRegion; private TextureRegion fboRegion;
private int fboSize; private int fboSize;
private int blurlvl = 2; private int blurlvl = 2;
private Batch batch;
private ScreenViewport screenViewport;
public MainMenu(final RhythmBullet core) { public MainMenu(final RhythmBullet core) {
this.core = core; this.core = core;
@ -118,6 +120,9 @@ public class MainMenu extends ScreenAdapter implements TransitionAdapter {
} }
public void loadShaders() { public void loadShaders() {
if (core.getPrefs().getBoolean("glow shader")) { if (core.getPrefs().getBoolean("glow shader")) {
batch = new SpriteBatch();
screenViewport = new ScreenViewport();
Gdx.app.debug("Shader", "using glow shader"); Gdx.app.debug("Shader", "using glow shader");
brightFilterShader = new ShaderProgram(Gdx.files.internal("shaders/basic.vsh"), Gdx.files.internal("shaders/bright_filter.fsh")); brightFilterShader = new ShaderProgram(Gdx.files.internal("shaders/basic.vsh"), Gdx.files.internal("shaders/bright_filter.fsh"));
if (!brightFilterShader.isCompiled()) { if (!brightFilterShader.isCompiled()) {
@ -160,7 +165,8 @@ public class MainMenu extends ScreenAdapter implements TransitionAdapter {
hBlur = new FrameBuffer(Format.RGBA8888, fboSize/2, fboSize/2, false); hBlur = new FrameBuffer(Format.RGBA8888, fboSize/2, fboSize/2, false);
vBlur = new FrameBuffer(Format.RGBA8888, fboSize/2, fboSize/2, false); vBlur = new FrameBuffer(Format.RGBA8888, fboSize/2, fboSize/2, false);
fboRegion = new TextureRegion(); fboRegion = new TextureRegion(normalBuffer.getColorBufferTexture());
fboRegion.flip(false, true);
combineShader.begin(); combineShader.begin();
combineShader.setUniformi("u_texture1", 1); combineShader.setUniformi("u_texture1", 1);
@ -176,87 +182,95 @@ public class MainMenu extends ScreenAdapter implements TransitionAdapter {
@Override @Override
public void render(float delta) { public void render(float delta) {
Gdx.gl.glClearColor(0f, 0f, 0f, 1f); Gdx.gl.glClearColor(0.22f, 0f, 0f, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act(delta); stage.act(delta);
blurlvl = 5; blurlvl = 5;
if (gaussianBlurShader != null) { if (gaussianBlurShader != null) {
//Begin drawing a normal version of screen //Begin drawing a normal version of screen
stage.getViewport().apply();
normalBuffer.begin(); normalBuffer.begin();
Gdx.gl.glClearColor(0.22f, 0f, 0f, 1f); Gdx.gl.glClearColor(0.22f, 0f, 0f, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.draw(); stage.draw();
normalBuffer.end(); normalBuffer.end();
//END //END STAGE BATCH
//BEGINNING NORMAL SCREEN RENDER
screenViewport.apply();
//Begin light filtering //Begin light filtering
lightFilterBuffer.begin(); lightFilterBuffer.begin();
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.getBatch().setShader(brightFilterShader); fboRegion.setTexture(normalBuffer.getColorBufferTexture());
stage.getBatch().begin(); //BATCH STARTS HERE batch.setShader(brightFilterShader);
stage.getRoot().draw(stage.getBatch(), 1f); batch.begin(); //BATCH STARTS HERE
stage.getBatch().flush(); batch.draw(fboRegion, 0, 0, stage.getWidth(), stage.getHeight());
batch.flush();
lightFilterBuffer.end(); lightFilterBuffer.end();
//Horizontal gaussian blur //Horizontal gaussian blur
hBlur.begin(); hBlur.begin();
fboRegion.setRegion(lightFilterBuffer.getColorBufferTexture()); Gdx.gl.glClearColor(0f, 0f, 0f, 1f);
stage.getBatch().setShader(gaussianBlurShader); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
fboRegion.setTexture(lightFilterBuffer.getColorBufferTexture());
batch.setShader(gaussianBlurShader);
gaussianBlurShader.setUniformi("horizontal", 1); gaussianBlurShader.setUniformi("horizontal", 1);
stage.getBatch().draw(fboRegion, 0f, 0f, stage.getWidth(), stage.getHeight()); batch.draw(fboRegion, 0f, 0f, stage.getWidth(), stage.getHeight());
stage.getBatch().flush(); batch.flush();
hBlur.end(); hBlur.end();
//Vertical gaussian blur //Vertical gaussian blur
vBlur.begin(); vBlur.begin();
fboRegion.setRegion(hBlur.getColorBufferTexture()); Gdx.gl.glClearColor(0f, 0f, 0f, 1f);
stage.getBatch().setShader(gaussianBlurShader); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
fboRegion.setTexture(hBlur.getColorBufferTexture());
batch.setShader(gaussianBlurShader);
gaussianBlurShader.setUniformi("horizontal", 0); gaussianBlurShader.setUniformi("horizontal", 0);
stage.getBatch().draw(fboRegion, 0f, 0f, stage.getWidth(), stage.getHeight()); batch.draw(fboRegion, 0f, 0f, stage.getWidth(), stage.getHeight());
stage.getBatch().flush(); batch.flush();
vBlur.end(); vBlur.end();
for (int i = 0; i < blurlvl; i++) { for (int i = 0; i < blurlvl; i++) {
//Horizontal gaussian blur //Horizontal gaussian blur
hBlur.begin(); hBlur.begin();
fboRegion.setRegion(vBlur.getColorBufferTexture()); fboRegion.setTexture(vBlur.getColorBufferTexture());
stage.getBatch().setShader(gaussianBlurShader); batch.setShader(gaussianBlurShader);
gaussianBlurShader.setUniformi("horizontal", 1); gaussianBlurShader.setUniformi("horizontal", 1);
stage.getBatch().draw(fboRegion, 0f, 0f, stage.getWidth(), stage.getHeight()); batch.draw(fboRegion, 0f, 0f, stage.getWidth(), stage.getHeight());
stage.getBatch().flush(); batch.flush();
hBlur.end(); hBlur.end();
//Vertical gaussian blur //Vertical gaussian blur
vBlur.begin(); vBlur.begin();
fboRegion.setRegion(hBlur.getColorBufferTexture()); fboRegion.setTexture(hBlur.getColorBufferTexture());
stage.getBatch().setShader(gaussianBlurShader); batch.setShader(gaussianBlurShader);
gaussianBlurShader.setUniformi("horizontal", 0); gaussianBlurShader.setUniformi("horizontal", 0);
stage.getBatch().draw(fboRegion, 0f, 0f, stage.getWidth(), stage.getHeight()); batch.draw(fboRegion, 0f, 0f, stage.getWidth(), stage.getHeight());
stage.getBatch().flush(); batch.flush();
vBlur.end(); vBlur.end();
} }
//Draw everything to screen //draw a final copy to a fbo
stage.getBatch().setShader(combineShader); Gdx.gl.glClearColor(0f, 0f, 0f, 0f);
fboRegion.setRegion(normalBuffer.getColorBufferTexture()); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
fboRegion.flip(false, true); batch.setShader(combineShader);
stage.getBatch().draw(fboRegion, 0f, 0f, stage.getWidth(), stage.getHeight()); fboRegion.setTexture(normalBuffer.getColorBufferTexture());
stage.getBatch().setShader(null); batch.draw(fboRegion, 0f, 0f, stage.getWidth(), stage.getHeight());
stage.getBatch().end(); //BATCH ENDS HERE batch.setShader(null);
batch.end(); //STAGE BATCH ENDS HERE
} else { } else {
stage.draw(); stage.draw();
} }
if (stage.getCamera().position.x != targetPosition.x || stage.getCamera().position.y != targetPosition.y) { if (stage.getCamera().position.x != targetPosition.x || stage.getCamera().position.y != targetPosition.y) {
stage.getCamera().position.lerp(targetPosition, lerpAlpha); stage.getCamera().position.lerp(targetPosition, lerpAlpha);
stage.getViewport().apply();
} }
super.render(delta); super.render(delta);
} }
@Override @Override
public void preTransition() { public void preTransition() {
stage.clear(); stage.clear();