changed to completely dedicated mesh instead of generic

This commit is contained in:
Harrison Deng 2017-09-20 11:58:25 -05:00
parent a45662238f
commit 3c6616a242
4 changed files with 53 additions and 21 deletions

View File

@ -10,50 +10,74 @@ import com.badlogic.gdx.graphics.VertexAttributes.Usage;
import com.badlogic.gdx.graphics.glutils.ShaderProgram; import com.badlogic.gdx.graphics.glutils.ShaderProgram;
import com.badlogic.gdx.utils.Disposable; import com.badlogic.gdx.utils.Disposable;
public class Parallelogram implements Disposable { public class TitleBarMesh implements Disposable {
private Mesh mesh; private Mesh mesh;
private OrthographicCamera cam; private OrthographicCamera cam;
private ShaderProgram shader; private ShaderProgram shader;
private Color color;
private int height;
public final int POSITION_VARS = 2; public final int POSITION_VARS = 2;
public final int COLOR_VARS = 1; //Packed color data public final int COLOR_VARS = 1; //Packed color data
public final int TOTAL_VARS = POSITION_VARS + COLOR_VARS; public final int TOTAL_VARS = POSITION_VARS + COLOR_VARS;
public final int MAX_QUADS = 1; public final int MAX_POLY = 1;
public final int MAX_VERTS = 4 * MAX_QUADS; public final int MAX_VERTS = 4 * MAX_POLY;
private float[] verts = new float[MAX_VERTS * TOTAL_VARS]; private float[] verts = new float[MAX_VERTS * TOTAL_VARS];
public Parallelogram(OrthographicCamera camera) { public TitleBarMesh() {
this.cam = camera;
shader = new ShaderProgram(Gdx.files.internal("shaders/mesh.vsh"), Gdx.files.internal("shaders/mesh.vsh")); shader = new ShaderProgram(Gdx.files.internal("shaders/mesh.vsh"), Gdx.files.internal("shaders/mesh.vsh"));
mesh = new Mesh(true, MAX_VERTS, 0, new VertexAttribute(Usage.Position, POSITION_VARS, "a_position"), mesh = new Mesh(true, MAX_VERTS, 0, new VertexAttribute(Usage.Position, POSITION_VARS, "a_position"),
//still expects 4 color components //still expects 4 color components
new VertexAttribute(Usage.ColorPacked, 4, "a_color")); new VertexAttribute(Usage.ColorPacked, 4, "a_color"));
color = new Color(Color.WHITE);
} }
public void setCam(OrthographicCamera cam) {
this.cam = cam;
}
public void setColor(Color color) {
this.color = color;
}
public void setHeight(int height) {
this.height = height;
}
public int getHeight() {
return height;
}
public Color getColor() {
return color;
}
private int idx = 0; private int idx = 0;
public void drawParallelogram(float x, float y, float width, float height, float topOffset, Color color) { public void draw() {
if (idx >= verts.length) { if (idx >= verts.length) {
flush(); flush();
} }
float c = color.toFloatBits(); float c = color.toFloatBits();
verts[idx++] = x; verts[idx++] = 0;
verts[idx++] = y; verts[idx++] = Gdx.graphics.getHeight()/2;
verts[idx++] = c; verts[idx++] = c;
verts[idx++] = x + width; verts[idx++] = Gdx.graphics.getWidth();
verts[idx++] = y; verts[idx++] = Gdx.graphics.getHeight()-height;
verts[idx++] = c; verts[idx++] = c;
verts[idx++] = x + width + topOffset; verts[idx++] = Gdx.graphics.getWidth();
verts[idx++] = y + height; verts[idx++] = Gdx.graphics.getHeight();
verts[idx++] = c; verts[idx++] = c;
verts[idx++] = x + topOffset; verts[idx++] = 0;
verts[idx++] = y + height; verts[idx++] = Gdx.graphics.getHeight()/2 + height;
verts[idx++] = c; verts[idx++] = c;
} }

View File

@ -1,21 +1,23 @@
package zero1hd.rhythmbullet.graphics.ui.components; package zero1hd.rhythmbullet.graphics.ui.components;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.assets.AssetManager; import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.scenes.scene2d.Group; import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.ui.Image; import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.utils.Disposable; import com.badlogic.gdx.utils.Disposable;
import zero1hd.rhythmbullet.graphics.meshes.Parallelogram; import zero1hd.rhythmbullet.graphics.meshes.TitleBarMesh;
public class TitleBarVisualizer extends Group implements Disposable { public class TitleBarVisualizer extends Group implements Disposable {
private Visualizer hvisual; private Visualizer hvisual;
private Parallelogram parall; private TitleBarMesh background;
private Image titleImage; private Image titleImage;
public TitleBarVisualizer(AssetManager assets) { public TitleBarVisualizer(AssetManager assets, OrthographicCamera camera) {
if (assets == null) throw new NullPointerException("TitleBarVisualizer requires assets manager... ITS NULL YOU FOOL"); if (assets == null) throw new NullPointerException("TitleBarVisualizer requires assets manager... ITS NULL YOU FOOL");
hvisual = new Visualizer(); hvisual = new Visualizer();
@ -24,6 +26,10 @@ public class TitleBarVisualizer extends Group implements Disposable {
titleImage = new Image(assets.get("title.png", Texture.class)); titleImage = new Image(assets.get("title.png", Texture.class));
addActor(titleImage); addActor(titleImage);
background = new TitleBarMesh();
background.setHeight((int) (Gdx.graphics.getHeight()*0.2));
background.setCam(camera);
hvisual.setY(getHeight()); hvisual.setY(getHeight());
} }
@ -34,7 +40,7 @@ public class TitleBarVisualizer extends Group implements Disposable {
@Override @Override
public void draw(Batch batch, float parentAlpha) { public void draw(Batch batch, float parentAlpha) {
parall.drawParallelogram(getX(), getY(), getWidth(), getHeight(), 30, getColor()); background.draw();
super.draw(batch, parentAlpha); super.draw(batch, parentAlpha);
} }

View File

@ -1,5 +1,6 @@
package zero1hd.rhythmbullet.graphics.ui.pages; package zero1hd.rhythmbullet.graphics.ui.pages;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.scenes.scene2d.ui.Label; import com.badlogic.gdx.scenes.scene2d.ui.Label;
@ -15,10 +16,10 @@ public class MainPage extends Page implements OnDifferentSongListener {
private SongListController sc; private SongListController sc;
private TitleBarVisualizer titleBar; private TitleBarVisualizer titleBar;
public MainPage(RhythmBullet core, Vector3 targetPosition, SongListController sc) { public MainPage(RhythmBullet core, Vector3 targetPosition, SongListController sc, OrthographicCamera camera) {
this.sc = sc; this.sc = sc;
titleBar = new TitleBarVisualizer(core.getAssetManager()); titleBar = new TitleBarVisualizer(core.getAssetManager(), camera);
addActor(titleBar); addActor(titleBar);
sc.addOnDifferentSongListener(this); sc.addOnDifferentSongListener(this);

View File

@ -4,6 +4,7 @@ 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.math.Vector3; import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener; import com.badlogic.gdx.scenes.scene2d.InputListener;
@ -59,7 +60,7 @@ public class MainMenu extends ScreenAdapter implements TransitionAdapter {
@Override @Override
public void postTransition() { public void postTransition() {
mainPage = new MainPage(core, targetPosition, sc); mainPage = new MainPage(core, targetPosition, sc, (OrthographicCamera) stage.getCamera());
mainPage.setPosition(0, 0); mainPage.setPosition(0, 0);
stage.addActor(mainPage); stage.addActor(mainPage);