Print text in OpenGl Context first implementation

This commit is contained in:
Antoine
2021-06-03 16:55:54 +02:00
parent f55bc8b2c1
commit 6a93931f68
6 changed files with 77 additions and 9 deletions

View File

@ -0,0 +1,48 @@
package engine.object;
import engine.Engine;
import engine.math.Vector3f;
import java.util.ArrayList;
import java.util.List;
public class Text {
private final List<ObjectGl> charList;
private float size;
private Engine engine;
private float zPos;
public Text(String text, float z, float size, Engine engine){
this.charList = new ArrayList<>();
this.zPos = z;
this.size = size;
this.engine = engine;
this.textToArrayObjectGl(text);
}
private void textToArrayObjectGl(String s){
for (int i = 0; i < s.length(); i++){
this.charList.add(this.charToObjectGl(s.charAt(i)));
}
int i = 0;
for (ObjectGl c : this.charList){
c.translate(new Vector3f(i * 10.0f * this.size, 0.0f, 0.0f));
this.engine.add_objectGl(c);
i++;
}
}
private ObjectGl charToObjectGl(char a){
ObjectGl objectGl = new ObjectGl(this.zPos, 1.0f, 1.0f, this.size, "textures/dejavu10x10_gs_tc.png", null);
objectGl.setShader("shaders/StylishShaders/BasicVert.glsl","shaders/StylishShaders/TextFrag.glsl");
switch (a){
case ('a'): {
objectGl.setTextureWrap(0.0f,40.0f,10.0f,10.0f, ObjectGl.DEFAULT);
break;
}
}
return objectGl;
}
}