Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
te
ded
SDL2
*.exe
*.obj
Expand Down
23 changes: 19 additions & 4 deletions shaders/font.frag
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,25 @@

uniform sampler2D font;
uniform float time;
uniform vec2 resolution;

in vec2 uv;
in float glyph_ch;
in vec4 glyph_color;
flat in int glyph_ch;
in vec4 glyph_fg_color;
in vec4 glyph_bg_color;

float map01(float x)
{
return (x + 1) / 2.0;
}

vec3 hsl2rgb(vec3 c) {
vec3 rgb = clamp(abs(mod(c.x*6.0+vec3(0.0,4.0,2.0),6.0)-3.0)-1.0, 0.0, 1.0);
return c.z + c.y * (rgb-0.5)*(1.0-abs(2.0*c.z-1.0));
}

void main() {
int ch = int(glyph_ch);
int ch = glyph_ch;
if (!(ASCII_DISPLAY_LOW <= ch && ch <= ASCII_DISPLAY_HIGH)) {
ch = 63;
}
Expand All @@ -32,5 +44,8 @@ void main() {
vec2 size = vec2(FONT_CHAR_WIDTH_UV, -FONT_CHAR_HEIGHT_UV);
vec2 t = pos + size * uv;

gl_FragColor = texture(font, t)* glyph_color;
vec4 tc = texture(font, t);
vec2 frag_uv = gl_FragCoord.xy / resolution;
vec4 rainbow = vec4(hsl2rgb(vec3((time + frag_uv.x + frag_uv.y), 0.5, 0.5)), 1.0);
gl_FragColor = glyph_bg_color * (1.0 - tc.x) + tc.x * glyph_fg_color * rainbow;
}
24 changes: 16 additions & 8 deletions shaders/font.vert
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,33 @@
#define FONT_CHAR_HEIGHT (FONT_HEIGHT / FONT_ROWS)

uniform vec2 resolution;
uniform vec2 scale;
uniform float time;
uniform vec2 camera;

layout(location = 0) in vec2 pos;
layout(location = 1) in float scale;
layout(location = 2) in float ch;
layout(location = 3) in vec4 color;
layout(location = 0) in ivec2 tile;
layout(location = 1) in int ch;
layout(location = 2) in vec4 fg_color;
layout(location = 3) in vec4 bg_color;

out vec2 uv;
out float glyph_ch;
out vec4 glyph_color;
flat out int glyph_ch;
out vec4 glyph_fg_color;
out vec4 glyph_bg_color;

vec2 project_point(vec2 point)
{
return 2.0 * point / resolution;
return 2.0 * (point - camera) / resolution;
}

void main() {
uv = vec2(float(gl_VertexID & 1), float((gl_VertexID >> 1) & 1));
vec2 char_size = vec2(float(FONT_CHAR_WIDTH), float(FONT_CHAR_HEIGHT));
vec2 pos = tile * char_size * scale;

gl_Position = vec4(project_point(uv * char_size * scale + pos), 0.0, 1.0);
glyph_ch = ch;
glyph_color = color;

glyph_fg_color = fg_color;
glyph_bg_color = bg_color;
}
42 changes: 42 additions & 0 deletions src/la.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,48 @@ Vec2f vec2f_div(Vec2f a, Vec2f b)
return vec2f(a.x / b.x, a.y / b.y);
}

//////////////////////////////

Vec2i vec2i(int x, int y)
{
return (Vec2i) {
.x = x,
.y = y,
};
}

Vec2i vec2is(int x)
{
return vec2i(x, x);
}

Vec2i vec2i_add(Vec2i a, Vec2i b)
{
return vec2i(a.x + b.x, a.y + b.y);
}

Vec2i vec2i_sub(Vec2i a, Vec2i b)
{
return vec2i(a.x - b.x, a.y - b.y);
}

Vec2i vec2i_mul(Vec2i a, Vec2i b)
{
return vec2i(a.x * b.x, a.y * b.y);
}

Vec2i vec2i_mul3(Vec2i a, Vec2i b, Vec2i c)
{
return vec2i_mul(vec2i_mul(a, b), c);
}

Vec2i vec2i_div(Vec2i a, Vec2i b)
{
return vec2i(a.x / b.x, a.y / b.y);
}

//////////////////////////////

Vec4f vec4f(float x, float y, float z, float w)
{
return (Vec4f) {
Expand Down
12 changes: 12 additions & 0 deletions src/la.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ Vec2f vec2f_mul(Vec2f a, Vec2f b);
Vec2f vec2f_mul3(Vec2f a, Vec2f b, Vec2f c);
Vec2f vec2f_div(Vec2f a, Vec2f b);

typedef struct {
int x, y;
} Vec2i;

Vec2i vec2i(int x, int y);
Vec2i vec2is(int x);
Vec2i vec2i_add(Vec2i a, Vec2i b);
Vec2i vec2i_sub(Vec2i a, Vec2i b);
Vec2i vec2i_mul(Vec2i a, Vec2i b);
Vec2i vec2i_mul3(Vec2i a, Vec2i b, Vec2i c);
Vec2i vec2i_div(Vec2i a, Vec2i b);

typedef struct {
float x, y, z, w;
} Vec4f;
Expand Down
Loading