105 lines
1.7 KiB
GLSL
105 lines
1.7 KiB
GLSL
#include inc_cp437.glsl
|
|
|
|
#ifndef INC_WRITE
|
|
#define INC_WRITE
|
|
|
|
const int hex_chars[] = int[16](
|
|
0x30,
|
|
0x31,
|
|
0x32,
|
|
0x33,
|
|
0x34,
|
|
0x35,
|
|
0x36,
|
|
0x37,
|
|
0x38,
|
|
0x39,
|
|
0x41,
|
|
0x42,
|
|
0x43,
|
|
0x44,
|
|
0x45,
|
|
0x46
|
|
);
|
|
|
|
float write_5(vec2 uv, vec2 pos, int str[5])
|
|
{
|
|
float d = 0.;
|
|
int i;
|
|
|
|
for (i = 0; i < 5; i++) {
|
|
if (str[i] == 0) {
|
|
return d;
|
|
}
|
|
|
|
d += cp437_at(uv, pos + vec2(i, 0.), str[i]);
|
|
}
|
|
|
|
return d;
|
|
}
|
|
|
|
float write_10(vec2 uv, vec2 pos, int str[10])
|
|
{
|
|
float d = 0.;
|
|
int i;
|
|
|
|
for (i = 0; i < 10; i++) {
|
|
if (str[i] == 0) {
|
|
return d;
|
|
}
|
|
|
|
d += cp437_at(uv, pos + vec2(i, 0.), str[i]);
|
|
}
|
|
|
|
return d;
|
|
}
|
|
|
|
float write_20(vec2 uv, vec2 pos, int str[20])
|
|
{
|
|
float d = 0.;
|
|
int i;
|
|
|
|
for (i = 0; i < 20; i++) {
|
|
if (str[i] == 0) {
|
|
return d;
|
|
}
|
|
|
|
d += cp437_at(uv, pos + vec2(i, 0.), str[i]);
|
|
}
|
|
|
|
return d;
|
|
}
|
|
|
|
float write_int(vec2 uv, vec2 pos, int value, int magnitude)
|
|
{
|
|
value = max(0, value);
|
|
int i;
|
|
int m = 1;
|
|
float d = 0.;
|
|
for (i = 0; i < magnitude; i++) {
|
|
if (i == 0 || value >= m) {
|
|
d += cp437_at(uv, pos + vec2(magnitude - i - 1, 0.), int(0x30 + (value % (m * 10)) / m));
|
|
m *= 10;
|
|
}
|
|
}
|
|
return d;
|
|
}
|
|
|
|
float write_int_left(vec2 uv, vec2 pos, int value, int magnitude)
|
|
{
|
|
value = max(0, value);
|
|
int i;
|
|
int m = 1;
|
|
float d = 0.;
|
|
pos.x -= magnitude;
|
|
for (i = 0; i < magnitude; i++) {
|
|
if (i == 0 || value >= m) {
|
|
pos.x += 1.;
|
|
m *= 10;
|
|
}
|
|
}
|
|
return write_int(uv, pos, value, magnitude);
|
|
}
|
|
|
|
#endif
|