Framework pour utliser les shaders sur du texte
This commit is contained in:
parent
f93f801e0b
commit
ae4a332eaf
@ -7,6 +7,7 @@ in vec2 fragCoord;
|
||||
in vec2 texCoord;
|
||||
|
||||
uniform sampler2D texture1;
|
||||
uniform int index;
|
||||
|
||||
void main(){
|
||||
vec3 black = vec3(0.0f, 0.0f , 0.0f);
|
||||
|
@ -164,8 +164,11 @@ public class TestEngine {
|
||||
// nextFrame = System.currentTimeMillis() - lastFrame >= 16.66f;
|
||||
// }
|
||||
|
||||
hpCurrent -= 0.01;
|
||||
hpCurrent -= 0.1;
|
||||
healthP1.setCurrent(hpCurrent);
|
||||
if (hpCurrent < 0){
|
||||
hpCurrent = 100f;
|
||||
}
|
||||
|
||||
nextFrame = false;
|
||||
if (engine.shouldClose()) engine.setRunning(false);
|
||||
|
39
src/engine/object/Letter.java
Normal file
39
src/engine/object/Letter.java
Normal file
@ -0,0 +1,39 @@
|
||||
package engine.object;
|
||||
|
||||
import engine.math.Vector3f;
|
||||
|
||||
import static org.lwjgl.glfw.GLFW.glfwGetTime;
|
||||
|
||||
public class Letter extends ObjectGl {
|
||||
|
||||
private int index;
|
||||
private boolean indexBasedShader;
|
||||
|
||||
public Letter(float z, float w, float h, float size, String tex, Vector3f color, int index) {
|
||||
super(z, w, h, size, tex, color);
|
||||
this.index = index;
|
||||
this.indexBasedShader = false;
|
||||
}
|
||||
|
||||
public void setIndexBasedShader(boolean b){
|
||||
this.indexBasedShader = b;
|
||||
}
|
||||
|
||||
public void render(){
|
||||
|
||||
this.shader.enable();
|
||||
if (this.texture != null) this.texture.bind();
|
||||
|
||||
if (this.useTime) this.shader.setUniform1f("time", (float) glfwGetTime());
|
||||
if (this.indexBasedShader) this.shader.setUniform1i("index",this.index);
|
||||
|
||||
this.shader.setUniformMat4f("projection", projection);
|
||||
this.shader.setUniformMat4f("view", view);
|
||||
this.shader.setUniformMat4f("transform", this.transform);
|
||||
|
||||
this.vertexArray.render();
|
||||
|
||||
if (this.texture != null) this.texture.unbind();
|
||||
this.shader.disable();
|
||||
}
|
||||
}
|
@ -42,7 +42,7 @@ public class ObjectGl {
|
||||
|
||||
public boolean useTime;
|
||||
|
||||
private Texture texture;
|
||||
protected Texture texture;
|
||||
private float[] textureWrap;
|
||||
|
||||
/**
|
||||
|
@ -34,7 +34,7 @@ public class Text {
|
||||
|
||||
private void textToArrayObjectGl(String s){
|
||||
for (int i = 0; i < s.length(); i++){
|
||||
this.charList.add(this.charToObjectGl(s.charAt(i)));
|
||||
this.charList.add(this.charToObjectGl(s.charAt(i), i));
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,7 +63,7 @@ public class Text {
|
||||
if (i >= text.length()) break;
|
||||
}
|
||||
while (i < text.length()){
|
||||
ObjectGl obj = this.charToObjectGl(text.charAt(i));
|
||||
ObjectGl obj = this.charToObjectGl(text.charAt(i), i);
|
||||
this.charList.add(obj);
|
||||
addCharInEngine(i, obj);
|
||||
i++;
|
||||
@ -100,8 +100,8 @@ public class Text {
|
||||
this.charList = this.charList.subList(0, i);
|
||||
}
|
||||
|
||||
private ObjectGl charToObjectGl(char a){
|
||||
ObjectGl objectGl = new ObjectGl(this.zPos, 1.0f, 1.0f, this.size, "textures/dejavu10x10_gs_tc.png", null);
|
||||
private ObjectGl charToObjectGl(char a, int index){
|
||||
ObjectGl objectGl = new Letter(this.zPos, 1.0f, 1.0f, this.size, "textures/dejavu10x10_gs_tc.png", null, index);
|
||||
objectGl.setShader("shaders/StylishShaders/BasicVert.glsl","shaders/StylishShaders/TextFrag.glsl");
|
||||
ObjectGlSetCharWrap(a, objectGl);
|
||||
return objectGl;
|
||||
|
Loading…
x
Reference in New Issue
Block a user