Browse Source

began gui bars

master
Mathieu Sérandour 2 years ago
parent
commit
f538269114
  1. 5
      res/list.json
  2. 31
      shaders/bar_f.glsl
  3. 15
      shaders/bar_v.glsl
  4. 49
      src/client/graphics/hud/gui/primitives/StaticBar.java

5
res/list.json

@ -2,9 +2,10 @@
"shaders":[
["texture2d", "basic/texture2d_v.glsl", "basic/texture2d_f.glsl"],
"map",
"sprite2d",
["sprite2d", "sprite_v.glsl", "sprite_f.glsl"],
"button",
"text"
"text",
"bar"
],
"textures":[
["orc", "sprites/enemies/orc.png"],

31
shaders/bar_f.glsl

@ -0,0 +1,31 @@
#version 420 core
in vec2 coords;
out vec4 outColor;
uniform sampler2D mask;
uniform vec4 backColor;
uniform vec4 frontColor;
uniform float maskXOffset;
uniform float value;
void main() {
vec4 masked = texture(mask, coords);
if(masked.a == 0)
discard;
if(masked == vec4(0,1,0,1)) {
float x = (coords.x - maskXOffset) / (1 - 2 * maskXOffset);
if(x <= value)
outColor = frontColor;
else
outColor = backColor;
}
else
outColor = masked;
}

15
shaders/bar_v.glsl

@ -0,0 +1,15 @@
#version 420 core
layout(location=0) in vec2 vertex;
layout(location=1) in vec2 incoords;
out vec2 coords;
uniform mat4 projection;
uniform mat4 transform;
void main() {
gl_Position = projection * transform * vec4(vertex, 0, 1);
coords = incoords;
}

49
src/client/graphics/hud/gui/primitives/StaticBar.java

@ -0,0 +1,49 @@
package client.graphics.hud.gui.primitives;
import java.awt.Color;
import client.graphics.engine.Texture;
import client.graphics.engine.draw.Model;
import client.graphics.engine.shader.Shader;
import client.graphics.exceptions.ShaderException;
import client.graphics.hud.HUDMain;
import math.vec.Vec2;
/**
*
* @author Mathieu
*
* bar with what the user cannot interact
*/
public class StaticBar extends Container {
private int value;
private int maxValue;
private final Shader shader;
public StaticBar(Vec2 pos, Vec2 size, boolean dynamicSize, Texture barTexture) {
super(pos, size, dynamicSize);
shader = Shader.get("bar");
add(new TexturedObject(new Vec2(), size, new Model(Model.getSquareModel(), barTexture, shader), false));
add(new Label(" ", HUDMain.HUD_FONT, Color.black, 1, new Vec2()));
}
public final void setValue(int value) {
this.value = value;
}
public final void setMaxValue(int maxValue) {
this.maxValue = maxValue;
}
@Override
public void draw() throws ShaderException {
shader.bind();
shader.setUniform1f("value", value);
shader.setUniform1f("maxValue", maxValue);
super.draw();
}
}
Loading…
Cancel
Save