102 printf(
"TGLSdfFontMaker::MakeFont entering.\n");
104 const std::string base =
"31:126";
105 const std::string accented =
",0x00e0:0x00fc,0x010c:0x010d,0x0160:0x0161,0x017d:0x017e";
106 const std::string greek =
",0x0391:0x03a9,0x03b1:0x03c9";
107 const std::string range_end =
",0xffff";
109 root_sdf_fonts::SdfCreator sc;
112 std::unique_ptr<TGLWidget> glw(
116 glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, &sc.max_tex_size);
119 std::string res_filename = output_prefix;
122 std::cerr <<
"Input file not specified" << std::endl;
126 if (res_filename.empty()) {
127 size_t ext_dot =
filename.find_last_of(
".");
128 if (ext_dot == std::string::npos) {
131 res_filename =
filename.substr(0, ext_dot);
135 if (!sc.font.load_ttf_file(
filename.c_str())) {
136 std::cerr <<
"Error reading TTF file '" <<
filename <<
"' " << std::endl;
142 sc.sdf_atlas.init(&sc.font, sc.width, sc.row_height, sc.border_size);
144 sc.parse_unicode_ranges(base + accented + greek + range_end);
145 sc.apply_unicode_ranges();
147 sc.sdf_atlas.draw_glyphs(sc.gp);
150 std::cout <<
"Allocated " << sc.sdf_atlas.glyph_count <<
" glyphs\n";
151 std::cout <<
"Atlas maximum height is " << sc.sdf_atlas.max_height <<
"\n";
154 if (sc.height == 0) {
155 sc.height = sc.sdf_atlas.max_height;
163 glGenRenderbuffers(1, &rbcolor);
164 glBindRenderbuffer(GL_RENDERBUFFER, rbcolor);
165 glRenderbufferStorage(GL_RENDERBUFFER, GL_RED, sc.width, sc.height);
166 glBindRenderbuffer(GL_RENDERBUFFER, 0);
169 glGenRenderbuffers(1, &rbds);
170 glBindRenderbuffer(GL_RENDERBUFFER, rbds);
171 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_STENCIL, sc.width, sc.height);
172 glBindRenderbuffer(GL_RENDERBUFFER, 0);
175 glGenFramebuffers(1, &fbo);
176 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
177 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbcolor);
178 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rbds);
180 if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
181 std::cerr <<
"Error creating framebuffer!" << std::endl;
187 uint8_t *picbuf = (uint8_t *)malloc(sc.width * sc.height);
189 glViewport(0, 0, sc.width, sc.height);
190 glClearColor(0.0, 0.0, 0.0, 0.0);
191 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
193 sc.sdf_gl.render_sdf({float(sc.width), float(sc.height)}, sc.gp.fp.vertices, sc.gp.lp.vertices);
195 glReadPixels(0, 0, sc.width, sc.height, GL_RED, GL_UNSIGNED_BYTE, picbuf);
197 glBindFramebuffer(GL_FRAMEBUFFER, 0);
201 printf(
"Resulting GL buffer: w=%d, h=%d\n", sc.width, sc.height);
205 for (
int iy = 0; iy < sc.height; ++iy) {
215 std::string
json = sc.sdf_atlas.json(sc.height);
216 std::vector<char> json_gz;
217 gzip_compress_buffer(
json.data(),
json.size(), json_gz);
219 std::string json_filename = res_filename +
".js.gz";
220 FILE *json_file = fopen(json_filename.c_str(),
"wb");
222 perror(
"Error writing json file.");
225 fwrite(json_gz.data(), json_gz.size(), 1, json_file);