-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtxtref.c
139 lines (93 loc) · 2.74 KB
/
txtref.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <libgen.h>
#include <GL/GLee.h>
#include <GLFW/glfw3.h>
#include "gl/init.h"
#include "gl/should_close.h"
#include "gl/wnd.h"
#include "gl/swap.h"
#include "gl/u8_rgb.h"
#include "err/assert_gl_ok.h"
#include "err/assert_int.h"
#include "color_quad/prepare.h"
#include "color_quad/set.h"
#include "color_quad/draw.h"
#include "geom/full_screen_quad.h"
#include "glsl/load_program.h"
#include "fnt/load.h"
#include "txt/init.h"
#include "txt/bind.h"
#include "txt/upload.h"
#include "txt/draw.h"
#include "anim/txt_alpha_init.h"
#include "anim/txt_alpha_update.h"
#include "time/fsleep.h"
int main(int argc, char **argv) {
int w = 800, h = 600;
s3d_gl_init(w, h, basename(__FILE__));
assert_int(argc, val <= 4);
{
s3d_color_quad_prepare();
static s3d_vec4 bg_gradient[4] = {
s3d_gl_u8_rgb(0x0f, 0x38, 0x7f), 1,
s3d_gl_u8_rgb(0x0f, 0x30, 0x70), 1,
s3d_gl_u8_rgb(0x40, 0xc0, 0xdf), 1,
s3d_gl_u8_rgb(0x40, 0xc0, 0xdf), 1
};
s3d_color_quad_set(s3d_geom_full_screen_quad, bg_gradient);
}
s3d_txt txt;
{
s3d_fnt fnt;
s3d_fnt_load(&fnt, (argc >= 2)? argv[1] : "data/fnt/jp");
s3d_vec3 color = { 0.8, 1, 0.8 };
s3d_txt_init(
&txt, &fnt, color, 0, (argc >= 3)? argv[2] : "京都は綺麗"
);
}
s3d_anim_txt_alpha_state anim_st;
{
anim_st.txt = &txt;
anim_st.speed = 10;
s3d_anim_txt_alpha_init(&anim_st);
}
unsigned p_id = s3d_glsl_load_program(
"glsl/fnt.xyz.glsl", "glsl/fnt.frag.glsl"
);
unsigned vw_uni_id = glGetUniformLocation(p_id, "vw");
unsigned xy_uni_id = glGetUniformLocation(p_id, "xy");
while(!s3d_gl_should_close()) {
assert_gl_ok();
int w, h;
glfwGetWindowSize(s3d_gl_wnd, &w, &h);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
{
s3d_color_quad_prepare();
s3d_color_quad_draw();
}
{
glUseProgram(p_id);
{
s3d_vec2 vw = { w, h };
glUniform2fv(vw_uni_id, 1, vw);
}
{
s3d_vec2 xy = { 0.008, 0.009 };
glUniform2fv(xy_uni_id, 1, xy);
}
{
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
s3d_txt_bind(&txt);
if(!anim_st.done) {
s3d_anim_txt_alpha_update(&anim_st);
s3d_txt_upload(&txt, GL_STREAM_DRAW);
}
s3d_txt_draw(&txt);
}
}
s3d_gl_swap();
glfwPollEvents();
s3d_fsleep(0.001);
}
return 0;
}