4 changed files with 98 additions and 2 deletions
@ -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; |
|||
|
|||
|
|||
} |
@ -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; |
|||
} |
@ -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…
Reference in new issue