Print text in OpenGl Context first implementation
This commit is contained in:
parent
f55bc8b2c1
commit
6a93931f68
@ -1,4 +1,4 @@
|
||||
#version 410
|
||||
#version 410 core
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
@ -20,7 +20,7 @@ void main(){
|
||||
if (tex.a == 0.0){
|
||||
FragColor = tex;
|
||||
} else{
|
||||
FragColor = mix(tex, flash, 0.5f);
|
||||
FragColor = mix(tex, flash, 0.3f);
|
||||
FragColor.a = 1.0f;
|
||||
}
|
||||
}
|
||||
|
18
shaders/StylishShaders/TextFrag.glsl
Normal file
18
shaders/StylishShaders/TextFrag.glsl
Normal file
@ -0,0 +1,18 @@
|
||||
#version 410 core
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
in vec4 color;
|
||||
in vec2 fragCoord;
|
||||
in vec2 texCoord;
|
||||
|
||||
uniform sampler2D texture1;
|
||||
|
||||
void main(){
|
||||
vec3 black = vec3(0.0f, 0.0f , 0.0f);
|
||||
vec4 tex = texture(texture1, texCoord);
|
||||
if (tex.xyz == black){
|
||||
tex.a = 0.0f;
|
||||
}
|
||||
FragColor = tex;
|
||||
}
|
@ -201,7 +201,7 @@ public class Engine {
|
||||
soundSource.setBuffer(jumpSoundBuffer.getBufferId());
|
||||
|
||||
soundManager.addSoundSource("jump", soundSource);
|
||||
soundManager.playSoundSource("jump");
|
||||
// soundManager.playSoundSource("jump");q
|
||||
|
||||
/*
|
||||
Engine Init
|
||||
@ -214,15 +214,15 @@ public class Engine {
|
||||
String path = "textures/zangief_sprite.png";
|
||||
String path2 = "textures/awesomeface.png";
|
||||
String pathToBG = "textures/background_beach.png";
|
||||
String pathToText = "textures/dejavu10x10_gs_tc.png";
|
||||
|
||||
ObjectGl zangief = new ObjectGl(10.0f, 1f, 1f, 10f, path, null);
|
||||
zangief.setTextureWrap(58, 0, 62, 84, ObjectGl.DEFAULT);
|
||||
engine.add_objectGl(zangief);
|
||||
zangief.translate(new Vector3f(-1000.0f, 200.0f, 0.0f));
|
||||
|
||||
ObjectGl smiley2 = new ObjectGl(0.0f, 500.0f, 500.0f, 1f, path2, null);
|
||||
engine.add_objectGl(smiley2);
|
||||
smiley2.translate(new Vector3f(0.0f, 0.0f, 15.0f));
|
||||
zangief.setColor(new Vector3f(1.0f, 1.0f, 1.0f));
|
||||
zangief.setShader("shaders/StylishShaders/BasicVert.glsl", "shaders/StylishShaders/FlashFrag.glsl");
|
||||
zangief.useTime = true;
|
||||
|
||||
//Create background
|
||||
ObjectGl background = new ObjectGl(0f,1f,1f,10f, pathToBG, null);
|
||||
@ -230,6 +230,8 @@ public class Engine {
|
||||
background.translate(new Vector3f(-3011.0f, 1400.0f, 1.0f));
|
||||
engine.add_objectGl(background);
|
||||
|
||||
Text TexTest = new Text("aaaaa",20.0f, 10, engine);
|
||||
|
||||
long timer = System.currentTimeMillis();
|
||||
long lastFrame;
|
||||
int frame = 0;
|
||||
|
@ -94,7 +94,7 @@ public class KeyboardInput extends GLFWKeyCallback {
|
||||
keyPressed = true;
|
||||
} else if (KeyboardInput.isKeyDown(GLFW.GLFW_KEY_W)) {
|
||||
keyPressed = true;
|
||||
token.scale(new Vector3f(1.001f,1.001f,1.0f));
|
||||
// token.scale(new Vector3f(1.001f,1.001f,1.0f));
|
||||
}
|
||||
if (KeyboardInput.isKeyDown(GLFW.GLFW_KEY_A)) {
|
||||
token.translate(new Vector3f (speed * -1.0f, 0.0f, 0.0f));
|
||||
@ -108,6 +108,6 @@ public class KeyboardInput extends GLFWKeyCallback {
|
||||
}
|
||||
if (!keyPressed) token.setTextureWrap(58,0,62,82, ObjectGl.STICK_TOP);
|
||||
|
||||
token.flipTextureWrapH();
|
||||
// token.flipTextureWrapH();
|
||||
}
|
||||
}
|
||||
|
48
src/engine/object/Text.java
Normal file
48
src/engine/object/Text.java
Normal 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;
|
||||
}
|
||||
|
||||
}
|
BIN
textures/dejavu10x10_gs_tc.png
Normal file
BIN
textures/dejavu10x10_gs_tc.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.2 KiB |
Loading…
x
Reference in New Issue
Block a user