Skip to content

Commit

Permalink
Glyph atlas preparations (#18)
Browse files Browse the repository at this point in the history
* WIP segfault debugging

* Revert changes to glVertexAttribPointer

* Remove reason-glfw dependency and example

* Revert "Remove reason-glfw dependency and example"

This reverts commit b81b946.

* Remove rejection files

* Add code for determining execution directory

* Fix array dimension order

* Add debugging logic and memoization for repro of a bug

* Fix memory management in caml_fk_load_glyph

* Remove debuging aids

* Remove esy link

* Resolve reason-glfw with unreleased version for now

* Fixes to JS bindings, part 1

* Merge master -> glyph-atlas-preparations (#23)

* API: Add 'fk_get_metrics' API (#20)

Add 'fk_get_metrics' API

* 2.1.0

* Upgrade reason-glfw -> 3.2.1015 (#21)

* Use hb_blob_create_from_file for mmap file reading (#19)

Not tested locally however.

* 2.2.0

* Add /opt/local/lib to link path (#22)

* 2.2.1

* Update fontkit.cpp

* Bring back iSize

* Debugging

* Get working on Windows

* Add bitmap back

* Pick up published reason-glfw dependency

* Update lockfile

* Fix missed merge conflict
  • Loading branch information
Manuel Hornung authored and bryphe committed Feb 27, 2019
1 parent 8aad87a commit 736964a
Show file tree
Hide file tree
Showing 58 changed files with 3,544 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .ci/esy-build-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ steps:
- task: NodeTool@0
inputs:
versionSpec: '8.9'
- script: npm install -g esy@0.4.9
- script: npm install -g esy@0.5.6
- script: esy install
- script: esy build
# Might want to add running tests here - that step will be dependent on your project!
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,3 @@ typings/
.merlin
esy.lock.json
_esy/
_build/
36 changes: 32 additions & 4 deletions bin_native/test_fontkit.re
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ open Reglfw.Glfw;
open Reglm;
open Fontkit;

let isNative =
switch (Sys.backend_type) {
| Native => true
| Bytecode => true
| _ => false
};

Printexc.record_backtrace(true);

let getExecutingDirectory = () =>
isNative ? Filename.dirname(Sys.argv[0]) ++ Filename.dir_sep : "";

print_endline("Hello, world!");

let loadShader = (shaderType, source) => {
Expand Down Expand Up @@ -37,7 +49,16 @@ let run = () => {
glfwMakeContextCurrent(w);
glViewport(0, 0, 800, 600);

let%lwt font = Fontkit.load("Roboto-Regular.ttf", 24);
let%lwt font =
Fontkit.load(getExecutingDirectory() ++ "Roboto-Regular.ttf", 24);

let metrics = Fontkit.fk_get_metrics(font);
print_endline ("-- height: " ++ string_of_int(metrics.height));
print_endline ("-- ascent: " ++ string_of_int(metrics.ascent));
print_endline ("-- descent: " ++ string_of_int(metrics.descent));
print_endline ("-- underlinePosition: " ++ string_of_int(metrics.underlinePosition));
print_endline ("-- underlineThickness: " ++ string_of_int(metrics.underlineThickness));
print_endline ("-- unitsPerEm: " ++ string_of_int(metrics.unitsPerEm));

let metrics = Fontkit.fk_get_metrics(font);
print_endline ("-- height: " ++ string_of_int(metrics.height));
Expand Down Expand Up @@ -112,7 +133,7 @@ let run = () => {
let render = (s: Fontkit.fk_shape, x: float, y: float) => {
let glyph = Fontkit.renderGlyph(font, s.glyphId);

let {image, width, height, bearingX, bearingY, advance, _} = glyph;
let {bitmap, width, height, bearingX, bearingY, advance, _} = glyph;

glUniformMatrix4fv(projectionUniform, projection);
glUniform4f(
Expand All @@ -132,7 +153,14 @@ let run = () => {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, image);
glTexImage2D(
GL_TEXTURE_2D,
0,
GL_ALPHA,
GL_ALPHA,
GL_UNSIGNED_BYTE,
bitmap,
);

glBindBuffer(GL_ARRAY_BUFFER, tb);
glVertexAttribPointer(texAttribute, 2, GL_FLOAT, false);
Expand Down Expand Up @@ -177,4 +205,4 @@ let run = () => {
Lwt.return();
};

Lwt_main.run(run());
Lwt_main.run(run());
3 changes: 3 additions & 0 deletions esy.lock/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

# Set eol to LF so files aren't converted to CRLF-eol on Windows.
* text eol=lf
3 changes: 3 additions & 0 deletions esy.lock/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

# Reset any possible .gitignore, we want all esy.lock to be un-ignored.
!*
Loading

0 comments on commit 736964a

Please sign in to comment.