added new mesh to render

This commit is contained in:
Harrison Deng 2017-09-19 00:58:28 -05:00
parent bf2e68e0f7
commit a45662238f
2 changed files with 18 additions and 21 deletions

View File

@ -8,8 +8,9 @@ import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.VertexAttribute; import com.badlogic.gdx.graphics.VertexAttribute;
import com.badlogic.gdx.graphics.VertexAttributes.Usage; 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;
public class Parallelogram { public class Parallelogram implements Disposable {
private Mesh mesh; private Mesh mesh;
private OrthographicCamera cam; private OrthographicCamera cam;
private ShaderProgram shader; private ShaderProgram shader;
@ -25,7 +26,7 @@ public class Parallelogram {
public Parallelogram(OrthographicCamera camera) { public Parallelogram(OrthographicCamera camera) {
this.cam = camera; this.cam = camera;
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"));
@ -81,4 +82,9 @@ public class Parallelogram {
idx = 0; idx = 0;
} }
} }
@Override
public void dispose() {
mesh.dispose();
}
} }

View File

@ -2,18 +2,17 @@ package zero1hd.rhythmbullet.graphics.ui.components;
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.Pixmap;
import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite; 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;
public class TitleBarVisualizer extends Group implements Disposable { public class TitleBarVisualizer extends Group implements Disposable {
private Visualizer hvisual; private Visualizer hvisual;
private Sprite backgroundBar; private Parallelogram parall;
private Texture backgroundTexture;
private Image titleImage; private Image titleImage;
public TitleBarVisualizer(AssetManager assets) { public TitleBarVisualizer(AssetManager assets) {
@ -22,19 +21,9 @@ public class TitleBarVisualizer extends Group implements Disposable {
hvisual = new Visualizer(); hvisual = new Visualizer();
addActor(hvisual); addActor(hvisual);
Pixmap pixmap = new Pixmap(2, 2, Format.RGBA8888);
pixmap.setColor(Color.WHITE);
pixmap.fill();
backgroundTexture = new Texture(pixmap);
pixmap.dispose();
backgroundBar = new Sprite(backgroundTexture);
titleImage = new Image(assets.get("title.png", Texture.class)); titleImage = new Image(assets.get("title.png", Texture.class));
addActor(titleImage); addActor(titleImage);
backgroundBar.setPosition(getX(), getY());
backgroundBar.setRotation(getRotation());
backgroundBar.setSize(getWidth(), getHeight());
hvisual.setY(getHeight()); hvisual.setY(getHeight());
} }
@ -43,25 +32,27 @@ public class TitleBarVisualizer extends Group implements Disposable {
super.act(delta); super.act(delta);
} }
@Override
public void draw(Batch batch, float parentAlpha) {
parall.drawParallelogram(getX(), getY(), getWidth(), getHeight(), 30, getColor());
super.draw(batch, parentAlpha);
}
public Visualizer getHvisual() { public Visualizer getHvisual() {
return hvisual; return hvisual;
} }
@Override @Override
public void dispose() { public void dispose() {
backgroundTexture.dispose();
backgroundTexture = null;
} }
@Override @Override
public void setColor(Color color) { public void setColor(Color color) {
backgroundBar.setColor(color);
super.setColor(color); super.setColor(color);
} }
@Override @Override
public void setColor(float r, float g, float b, float a) { public void setColor(float r, float g, float b, float a) {
backgroundBar.setColor(r, g, b, a);
super.setColor(r, g, b, a); super.setColor(r, g, b, a);
} }
} }