Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Glyph atlas preparations #18

Merged
merged 20 commits into from
Feb 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So nice to be able to use esy x for this too, nice!


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