font.vert 954 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 ivec2 cursor;
  11. layout(location = 0) in ivec2 tile;
  12. layout(location = 1) in int c;
  13. layout(location = 2) in vec4 color;
  14. out vec2 uv;
  15. flat out int glyph_c;
  16. out vec4 glyph_fg_color;
  17. out vec4 glyph_bg_color;
  18. vec2 project_point(vec2 point)
  19. {
  20. return (2.0 * point) / resolution;
  21. }
  22. void main()
  23. {
  24. uv = vec2(float(gl_VertexID & 1),
  25. float((gl_VertexID >> 1) & 1));
  26. vec2 char_size = vec2(float(FONT_CH_W), float(FONT_CH_H));
  27. vec2 pos = tile * char_size * scale;
  28. gl_Position = vec4(project_point(uv * char_size * scale + pos), 0.0, 1.0);
  29. glyph_c = c;
  30. glyph_fg_color = color;
  31. glyph_bg_color = vec4(0);
  32. if ( tile == cursor ) {
  33. glyph_fg_color = vec4(0);
  34. glyph_bg_color = vec4(1);
  35. }
  36. }