diff options
author | rom <romangraef@gmail.com> | 2021-04-24 03:19:22 +0200 |
---|---|---|
committer | rom <romangraef@gmail.com> | 2021-04-24 11:08:22 +0200 |
commit | ec934bf2f0f3536c1b4d31b4ca002f6f38ada9fe (patch) | |
tree | 21e44e889c91eeecc1537e69eae7d0b50d25804a /txtgameengine/platform.py | |
parent | a0a40e9259b9e8be4e677c8c29dfdfb89eb81ce8 (diff) | |
download | txtgameengine-ec934bf2f0f3536c1b4d31b4ca002f6f38ada9fe.tar.gz txtgameengine-ec934bf2f0f3536c1b4d31b4ca002f6f38ada9fe.tar.bz2 txtgameengine-ec934bf2f0f3536c1b4d31b4ca002f6f38ada9fe.zip |
font rendering
Diffstat (limited to 'txtgameengine/platform.py')
-rw-r--r-- | txtgameengine/platform.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/txtgameengine/platform.py b/txtgameengine/platform.py index 8258d33..bcf3d10 100644 --- a/txtgameengine/platform.py +++ b/txtgameengine/platform.py @@ -149,6 +149,8 @@ class RenderComponent: @staticmethod def setup_buffer(arr, mode=GL_STATIC_DRAW): + if not hasattr(arr, 'itemsize'): + arr = np.array(arr, np.float32) buf = glGenBuffers(1) glBindBuffer(GL_ARRAY_BUFFER, buf) glBufferData(GL_ARRAY_BUFFER, arr.itemsize * @@ -156,21 +158,24 @@ class RenderComponent: return buf @staticmethod - def triangle(buf): + def triangle(buf, count=3): glEnableVertexAttribArray(0) glBindBuffer(GL_ARRAY_BUFFER, buf) glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, None) - glDrawArrays(GL_TRIANGLES, 0, 3) + glDrawArrays(GL_TRIANGLE_STRIP, 0, count) glDisableVertexAttribArray(0) - def textured_triangle(self, shader_location, texture, triangle, uvs): + @staticmethod + def bind_texture(shader_location, texture): glActiveTexture(GL_TEXTURE0) glBindTexture(GL_TEXTURE_2D, texture.gl_texid) glUniform1i(shader_location, 0) + + def textured_triangle(self, triangle, uvs, count=3): glEnableVertexAttribArray(1) glBindBuffer(GL_ARRAY_BUFFER, uvs) glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, None) - self.triangle(triangle) + self.triangle(triangle, count) glDisableVertexAttribArray(1) def setup_texture(self, width: int, height: int, data: np.ndarray): |