Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial text rendering
- Loading branch information
Showing
16 changed files
with
322 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
|
||
open Reglfw.Glfw; | ||
open Fontkit; | ||
|
||
let getGlyph = (font: Fontkit.fk_face, codepoint: int) => { | ||
/* TODO: Cache */ | ||
Fontkit.renderGlyph(font, codepoint); | ||
}; | ||
|
||
let getTexture = (font: Fontkit.fk_face, codepoint: int) => { | ||
let glyph = getGlyph(font, codepoint); | ||
|
||
let {image, _ } = glyph; | ||
|
||
/* TODO: */ | ||
/* - Cache textures */ | ||
/* - Create texture atlas */ | ||
glPixelStorei(GL_PACK_ALIGNMENT, 1); | ||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); | ||
|
||
let texture = glCreateTexture(); | ||
glBindTexture(GL_TEXTURE_2D, texture); | ||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); | ||
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, GL_UNSIGNED_BYTE, image); | ||
texture | ||
}; | ||
|
||
type dimensions = { | ||
width: int, | ||
height: int, | ||
} | ||
|
||
let measure = (font: Fontkit.fk_face, text: string) => { | ||
let shapedText = Fontkit.fk_shape(font, text); | ||
let minY = ref(1000); | ||
let maxY = ref(-1000); | ||
let x = ref(0); | ||
|
||
Array.iter(shape => { | ||
let {height, bearingY, advance, _} = getGlyph(font, shape.codepoint); | ||
let top = height + bearingY; | ||
let bottom = top + height; | ||
|
||
if (height > 0) { | ||
minY := minY^ < top ? minY^ : top; | ||
maxY := maxY^ > bottom ? maxY^ : bottom; | ||
} | ||
|
||
x := x^ + advance; | ||
}, shapedText); | ||
|
||
let d: dimensions = { | ||
height: maxY^ - minY^, | ||
width: int_of_float(float_of_int(x^) /. 64.0), | ||
}; | ||
d; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module Shaders = Revery_Shaders; | ||
module Geometry = Revery_Geometry; | ||
module Layout = Layout; | ||
module LayoutTypes = Layout.LayoutTypes; | ||
|
||
class node (_name: string) = { | ||
as _this; | ||
|
||
val _children: ref(list(node)) = ref([]); | ||
val _style = ref(Layout.defaultStyle); | ||
val _layoutNode = ref(Layout.createNode([||], Layout.defaultStyle)); | ||
|
||
pub draw = (layer: int) => { | ||
List.iter((c) => c#draw(layer + 1), _children^) | ||
}; | ||
|
||
pub measurements = () => { | ||
(_layoutNode^).layout; | ||
}; | ||
|
||
pub setStyle = (style) => { | ||
_style := style; | ||
}; | ||
|
||
pub addChild = (n: node) => { | ||
_children := List.append(_children^, [n]); | ||
}; | ||
|
||
pub getMeasureFunction = () => { | ||
None; | ||
}; | ||
|
||
pub toLayoutNode = () => { | ||
let childNodes = List.map((c) => c#toLayoutNode(), _children^); | ||
let node = switch (_this#getMeasureFunction()) { | ||
| None => Layout.createNode(Array.of_list(childNodes), _style^); | ||
| Some(m) => Layout.createNodeWithMeasure(Array.of_list(childNodes), _style^, m); | ||
}; | ||
|
||
_layoutNode := node; | ||
node; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.