basic game logic with simple translation animation

This commit is contained in:
2023-12-13 06:58:08 +02:00
parent 7360359a48
commit 9620e12681
44 changed files with 33798 additions and 6 deletions
+21
View File
@@ -0,0 +1,21 @@
#version 330 core
in vec2 v_TexCoords;
in vec4 textColor;
out vec4 FragColor;
uniform sampler2D text;
const float smoothness = 0.05;
const float outlineDistance = 0.50;
const vec4 outlineColor = vec4(0.0, 0.0, 0.0, 1.0);
void main() {
//float distance = texture(text, v_TexCoords).r;
//float outlineFactor = smoothstep(0.5 - smoothness, 0.5 + smoothness, distance);
//vec4 color = mix(outlineColor, textColor, outlineFactor);
//float alpha = smoothstep(outlineDistance - smoothness, outlineDistance + smoothness, distance);
vec4 sampled = vec4(1.0, 1.0, 1.0, texture(text, v_TexCoords).r);
FragColor = textColor * sampled;
//FragColor = vec4(color.rgb, textColor.a * alpha);
}
+21
View File
@@ -0,0 +1,21 @@
#version 330 core
layout (location = 0) in vec2 vertex;
// per instance
layout (location = 1) in vec4 offset;
layout (location = 2) in int tex_index;
layout (location = 3) in vec4 color;
layout (location = 4) in mat4 model; // this takes locations 4,5,6,7
out vec2 v_TexCoords;
out vec4 textColor;
uniform mat4 projection;
// buffer for all the 96 ascii characters' texcoords
uniform vec2 texcoords[96 * 4];
void main() {
vec2 pos = vec2((vertex.x) * offset.z, (vertex.y) * offset.w);
gl_Position = projection * model * vec4(pos + offset.xy, 0.0, 1.0);
v_TexCoords = texcoords[tex_index * 4 + gl_VertexID];
textColor = color;
}
+33
View File
@@ -0,0 +1,33 @@
#version 330 core
in vec2 v_TexCoords;
out vec4 FragColor;
uniform vec4 aColor;
uniform float borderRadius;
uniform float uiWidth;
uniform float uiHeight;
const float smoothness = 1.0;
void main() {
float alpha = aColor.a;
if (borderRadius > 0.0) {
vec2 dimensions = v_TexCoords * vec2(uiWidth, uiHeight);
float xMax = uiWidth - borderRadius;
float yMax = uiHeight - borderRadius;
if (dimensions.x < borderRadius && dimensions.y < borderRadius) {
alpha *= 1.0 - smoothstep(borderRadius - smoothness, borderRadius + smoothness, length(dimensions - vec2(borderRadius)));
} else if (dimensions.x < borderRadius && dimensions.y > yMax) {
alpha *= 1.0 - smoothstep(borderRadius - smoothness, borderRadius + smoothness, length(dimensions - vec2(borderRadius, yMax)));
} else if (dimensions.x > xMax && dimensions.y < borderRadius) {
alpha *= 1.0 - smoothstep(borderRadius - smoothness, borderRadius + smoothness, length(dimensions - vec2(xMax, borderRadius)));
} else if (dimensions.x > xMax && dimensions.y > yMax) {
alpha *= 1.0 - smoothstep(borderRadius - smoothness, borderRadius + smoothness, length(dimensions - vec2(xMax, yMax)));
}
}
FragColor = vec4(aColor.rgb, alpha);
}
+11
View File
@@ -0,0 +1,11 @@
#version 330 core
layout (location = 0) in vec4 vertex;
out vec2 v_TexCoords;
uniform mat4 projection;
uniform mat4 model;
void main() {
gl_Position = projection * model * vec4(vertex.xy, 0.0, 1.0);
v_TexCoords = vertex.zw;
}