WavyTextVert.glsl + support des shaders dans UIElementText.java

This commit is contained in:
Antoine 2021-06-14 17:03:10 +02:00
parent acf62519f4
commit 95d2d7e21c
5 changed files with 50 additions and 12 deletions

View File

@ -7,7 +7,6 @@ in vec2 fragCoord;
in vec2 texCoord; in vec2 texCoord;
uniform sampler2D texture1; uniform sampler2D texture1;
uniform int index;
void main(){ void main(){
vec3 black = vec3(0.0f, 0.0f , 0.0f); vec3 black = vec3(0.0f, 0.0f , 0.0f);

View File

@ -0,0 +1,27 @@
#version 410 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aColor;
layout (location = 2) in vec2 aTexCoord;
out vec2 fragCoord;
out vec2 texCoord;
out vec4 color;
uniform mat4 projection;
uniform mat4 view;
uniform mat4 transform;
uniform int index;
uniform float time;
void main()
{
float speed = 10f;
float amplitude = 4f;
vec3 newPos = aPos;
newPos.y = newPos.y + (sin((time + index * 10f + newPos.x) * speed) * amplitude);
gl_Position = projection * view * transform * vec4(newPos, 1.0);
color = vec4(aColor, 1.0f);
texCoord = aTexCoord;
fragCoord = aPos.xy;
}

View File

@ -77,6 +77,7 @@ public class TestEngine {
UIElementText fpsTracker = new UIElementText("Boulevard Combattant", 5.0f, 0.0f,0.5f, 25.0f, engine); UIElementText fpsTracker = new UIElementText("Boulevard Combattant", 5.0f, 0.0f,0.5f, 25.0f, engine);
engine.add_uiElement(fpsTracker); engine.add_uiElement(fpsTracker);
fpsTracker.setShader("shaders/StylishShaders/WavyTextVert.glsl", "shaders/StylishShaders/TextFrag.glsl", true, true);
UIElementText uiTextCoordP1 = new UIElementText("Boulevard Combattant", 7.0f, 0.0f,0.05f, 25.0f, engine); UIElementText uiTextCoordP1 = new UIElementText("Boulevard Combattant", 7.0f, 0.0f,0.05f, 25.0f, engine);
engine.add_uiElement(uiTextCoordP1); engine.add_uiElement(uiTextCoordP1);

View File

@ -2,6 +2,7 @@ package engine.gui;
import engine.Engine; import engine.Engine;
import engine.math.Vector3f; import engine.math.Vector3f;
import engine.object.Letter;
import engine.object.ObjectGl; import engine.object.ObjectGl;
import engine.object.Text; import engine.object.Text;
@ -12,7 +13,7 @@ import java.util.List;
*/ */
public class UIElementText extends UIDummy{ public class UIElementText extends UIDummy{
private final List<ObjectGl> objs; private final List<Letter> objs;
private final Text txt; private final Text txt;
/** /**
@ -38,7 +39,9 @@ public class UIElementText extends UIDummy{
* Ajouter l'element à la liste de rendu du moteur dont il est lié. * Ajouter l'element à la liste de rendu du moteur dont il est lié.
*/ */
public void init(){ public void init(){
this.engine.add_objectsGl(objs); for (ObjectGl obj : this.txt.getCharList()){
this.engine.add_objectGl(obj);
}
} }
/** /**
@ -49,6 +52,14 @@ public class UIElementText extends UIDummy{
this.txt.setNewText(txt); this.txt.setNewText(txt);
} }
public void setShader(String vert, String frag, boolean indexBasedShader, boolean useTime){
for (Letter l : this.txt.getCharList()){
l.setShader(vert, frag);
l.setIndexBasedShader(indexBasedShader);
l.useTime = useTime;
}
}
protected void getObjInPosition(){ protected void getObjInPosition(){
int i = 0; int i = 0;
for (ObjectGl obj : this.txt.getCharList()){ for (ObjectGl obj : this.txt.getCharList()){

View File

@ -12,7 +12,7 @@ import java.util.List;
*/ */
public class Text { public class Text {
private List<ObjectGl> charList; private List<Letter> charList;
private final float size; private final float size;
private final Engine engine; private final Engine engine;
private final float zPos; private final float zPos;
@ -40,13 +40,13 @@ public class Text {
private void addCharListInEngine(){ private void addCharListInEngine(){
int i = 0; int i = 0;
for (ObjectGl obj : this.charList){ for (Letter obj : this.charList){
addCharInEngine(i, obj); addCharInEngine(i, obj);
i++; i++;
} }
} }
private void addCharInEngine(int i, ObjectGl obj){ private void addCharInEngine(int i, Letter obj){
obj.translate(new Vector3f(i * 10.0f * this.size, 0.0f, 0.0f)); obj.translate(new Vector3f(i * 10.0f * this.size, 0.0f, 0.0f));
obj.translate(transformation); obj.translate(transformation);
this.engine.add_objectGl(obj); this.engine.add_objectGl(obj);
@ -57,13 +57,13 @@ public class Text {
public void setNewText(String text){ public void setNewText(String text){
int i = 0; int i = 0;
for (ObjectGl obj : this.charList) { for (Letter obj : this.charList) {
ObjectGlSetCharWrap(text.charAt(i), obj); ObjectGlSetCharWrap(text.charAt(i), obj);
i++; i++;
if (i >= text.length()) break; if (i >= text.length()) break;
} }
while (i < text.length()){ while (i < text.length()){
ObjectGl obj = this.charToObjectGl(text.charAt(i), i); Letter obj = this.charToObjectGl(text.charAt(i), i);
this.charList.add(obj); this.charList.add(obj);
addCharInEngine(i, obj); addCharInEngine(i, obj);
i++; i++;
@ -91,7 +91,7 @@ public class Text {
private void removeFromIndexToEnd(int i){ private void removeFromIndexToEnd(int i){
int j = 0; int j = 0;
for (ObjectGl objectGl : this.charList){ for (Letter objectGl : this.charList){
if (j >= i) { if (j >= i) {
this.engine.remove_objectGl(objectGl); this.engine.remove_objectGl(objectGl);
} }
@ -100,8 +100,8 @@ public class Text {
this.charList = this.charList.subList(0, i); this.charList = this.charList.subList(0, i);
} }
private ObjectGl charToObjectGl(char a, int index){ private Letter charToObjectGl(char a, int index){
ObjectGl objectGl = new Letter(this.zPos, 1.0f, 1.0f, this.size, "textures/dejavu10x10_gs_tc.png", null, index); Letter 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"); objectGl.setShader("shaders/StylishShaders/BasicVert.glsl","shaders/StylishShaders/TextFrag.glsl");
ObjectGlSetCharWrap(a, objectGl); ObjectGlSetCharWrap(a, objectGl);
return objectGl; return objectGl;
@ -119,7 +119,7 @@ public class Text {
} }
} }
public List<ObjectGl> getCharList(){ public List<Letter> getCharList(){
return this.charList; return this.charList;
} }