font.vert 939 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #version 330 core
  2. #define FONT_WIDTH 128
  3. #define FONT_HEIGHT 64
  4. #define FONT_COLS 18
  5. #define FONT_ROWS 7
  6. #define FONT_CH_W (FONT_WIDTH / FONT_COLS)
  7. #define FONT_CH_H (FONT_HEIGHT / FONT_ROWS)
  8. uniform float scale;
  9. uniform vec2 resolution;
  10. uniform float time;
  11. uniform vec2 camera;
  12. layout(location = 0) in ivec2 tile;
  13. layout(location = 1) in int c;
  14. layout(location = 2) in vec4 fg_color;
  15. layout(location = 3) in vec4 bg_color;
  16. out vec2 uv;
  17. flat out int glyph_c;
  18. out vec4 glyph_fg_color;
  19. out vec4 glyph_bg_color;
  20. vec2 project_point(vec2 point)
  21. {
  22. return (2.0 * (point - camera)) / resolution;
  23. }
  24. void main()
  25. {
  26. uv = vec2(float(gl_VertexID & 1),
  27. float((gl_VertexID >> 1) & 1));
  28. vec2 char_size = vec2(float(FONT_CH_W), float(FONT_CH_H));
  29. vec2 pos = tile * char_size * scale;
  30. gl_Position = vec4(project_point(uv * char_size * scale + pos), 0.0, 1.0);
  31. glyph_c = c;
  32. glyph_fg_color = fg_color;
  33. glyph_bg_color = bg_color;
  34. }