Skip to content

Commit 4e64680

Browse files
committed
updated text to only load visible chars
1 parent 8d9d6a4 commit 4e64680

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

src/ngl/text.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ def __init__(self, font_name: str, size: int):
3939
face.set_pixel_sizes(0, size)
4040
# disable byte-alignment restriction
4141
gl.glPixelStorei(gl.GL_UNPACK_ALIGNMENT, 1)
42-
for i in range(0, 128):
43-
face.load_char(chr(i), freetype.FT_LOAD_RENDER)
42+
start_char = " "
43+
end_char = "~"
44+
45+
for code in range(ord(start_char), ord(end_char) + 1):
46+
c = chr(code)
47+
face.load_char(c, freetype.FT_LOAD_RENDER)
4448
# # now we create the OpenGL texture ID and bind to make it active
4549
# texture_id = gl.glGenTextures(1)
4650
# gl.glActiveTexture(gl.GL_TEXTURE0)
@@ -60,6 +64,7 @@ def __init__(self, font_name: str, size: int):
6064
# fmt: on
6165
# generate and bind texture
6266
texture_id = gl.glGenTextures(1)
67+
gl.glActiveTexture(gl.GL_TEXTURE0)
6368
gl.glBindTexture(gl.GL_TEXTURE_2D, texture_id)
6469

6570
# upload glyph bitmap as single channel texture
@@ -76,12 +81,8 @@ def __init__(self, font_name: str, size: int):
7681
)
7782

7883
# set texture options
79-
gl.glTexParameteri(
80-
gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_EDGE
81-
)
82-
gl.glTexParameteri(
83-
gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP_TO_EDGE
84-
)
84+
gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_EDGE)
85+
gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP_TO_EDGE)
8586
gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR)
8687
gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR)
8788
char = Character(
@@ -92,7 +93,7 @@ def __init__(self, font_name: str, size: int):
9293
face.glyph.bitmap_top,
9394
face.glyph.advance.x,
9495
)
95-
self.characters[chr(i)] = char
96+
self.characters[c] = char
9697

9798
gl.glPixelStorei(gl.GL_UNPACK_ALIGNMENT, 4)
9899
self.set_colour(0.0, 0.0, 0.0)

0 commit comments

Comments
 (0)