summaryrefslogtreecommitdiff
path: root/txtgameengine
diff options
context:
space:
mode:
Diffstat (limited to 'txtgameengine')
-rw-r--r--txtgameengine/__main__.py2
-rw-r--r--txtgameengine/app.py2
-rw-r--r--txtgameengine/builtin_res/fonts/fira_code/regular.pngbin0 -> 27940 bytes
-rw-r--r--txtgameengine/builtin_res/fonts/fira_code/regular.xml98
-rw-r--r--txtgameengine/builtin_res/shaders/basic/fragment.glsl (renamed from txtgameengine/builtin_shaders/basic/fragment.glsl)0
-rw-r--r--txtgameengine/builtin_res/shaders/basic/vertex.glsl (renamed from txtgameengine/builtin_shaders/basic/vertex.glsl)0
-rw-r--r--txtgameengine/builtin_res/shaders/texture/fragment.glsl (renamed from txtgameengine/builtin_shaders/texture/fragment.glsl)0
-rw-r--r--txtgameengine/builtin_res/shaders/texture/vertex.glsl (renamed from txtgameengine/builtin_shaders/texture/vertex.glsl)0
-rw-r--r--txtgameengine/fonts.py51
-rw-r--r--txtgameengine/shaders/integrated.py4
10 files changed, 143 insertions, 14 deletions
diff --git a/txtgameengine/__main__.py b/txtgameengine/__main__.py
index b66d9fe..edfbd29 100644
--- a/txtgameengine/__main__.py
+++ b/txtgameengine/__main__.py
@@ -5,7 +5,7 @@ from pathlib import Path
from .shaders import TextureShader
from .twod.textures import Texture
-shader_path = Path(__file__).parent / 'builtin_shaders'
+shader_path = Path(__file__).parent / 'shaders'
class TriangleScene(Scene):
diff --git a/txtgameengine/app.py b/txtgameengine/app.py
index e7121da..58b239f 100644
--- a/txtgameengine/app.py
+++ b/txtgameengine/app.py
@@ -4,7 +4,7 @@ from pathlib import Path
from .platform import PlatformComponent, RenderComponent, ShaderComponent
EPSILON = 1.e-10
-base_path = Path(__file__).parent
+builtin_resource_path = Path(__file__).parent / 'builtin_res'
class TxtGameApp:
diff --git a/txtgameengine/builtin_res/fonts/fira_code/regular.png b/txtgameengine/builtin_res/fonts/fira_code/regular.png
new file mode 100644
index 0000000..8fa2358
--- /dev/null
+++ b/txtgameengine/builtin_res/fonts/fira_code/regular.png
Binary files differ
diff --git a/txtgameengine/builtin_res/fonts/fira_code/regular.xml b/txtgameengine/builtin_res/fonts/fira_code/regular.xml
new file mode 100644
index 0000000..880f7d3
--- /dev/null
+++ b/txtgameengine/builtin_res/fonts/fira_code/regular.xml
@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Font size="65" family="Fira Code" height="142" style="Regular">
+ <Char width="142" offset="0 107" rect="1 108 0 0" code=" "/>
+ <Char width="142" offset="28 25" rect="2 26 16 83" code="!"/>
+ <Char width="142" offset="20 19" rect="19 20 31 31" code="&quot;"/>
+ <Char width="142" offset="6 25" rect="51 26 58 82" code="#"/>
+ <Char width="142" offset="7 6" rect="110 7 57 119" code="$"/>
+ <Char width="142" offset="2 23" rect="168 24 67 87" code="%"/>
+ <Char width="142" offset="6 23" rect="236 24 62 85" code="&amp;"/>
+ <Char width="142" offset="30 19" rect="299 20 11 31" code="'"/>
+ <Char width="142" offset="15 6" rect="311 7 37 118" code="("/>
+ <Char width="142" offset="20 6" rect="349 7 37 118" code=")"/>
+ <Char width="142" offset="5 38" rect="387 39 61 58" code="*"/>
+ <Char width="142" offset="8 43" rect="449 44 56 55" code="+"/>
+ <Char width="142" offset="24 87" rect="506 88 21 41" code=","/>
+ <Char width="142" offset="12 66" rect="528 67 48 8" code="-"/>
+ <Char width="142" offset="25 87" rect="577 88 21 21" code="."/>
+ <Char width="142" offset="6 10" rect="599 11 59 110" code="/"/>
+ <Char width="142" offset="9 23" rect="659 24 54 85" code="0"/>
+ <Char width="142" offset="11 25" rect="714 26 50 82" code="1"/>
+ <Char width="142" offset="6 24" rect="765 25 53 83" code="2"/>
+ <Char width="142" offset="6 23" rect="819 24 54 85" code="3"/>
+ <Char width="142" offset="9 23" rect="874 24 54 84" code="4"/>
+ <Char width="142" offset="9 25" rect="929 26 52 83" code="5"/>
+ <Char width="142" offset="9 23" rect="982 24 53 85" code="6"/>
+ <Char width="142" offset="12 25" rect="1036 26 48 83" code="7"/>
+ <Char width="142" offset="8 23" rect="1085 24 56 85" code="8"/>
+ <Char width="142" offset="8 24" rect="1142 25 53 86" code="9"/>
+ <Char width="142" offset="26 46" rect="1196 47 19 62" code=":"/>
+ <Char width="142" offset="24 46" rect="1216 47 21 82" code=";"/>
+ <Char width="142" offset="10 36" rect="1238 37 51 68" code="&lt;"/>
+ <Char width="142" offset="12 55" rect="1290 56 46 31" code="="/>
+ <Char width="142" offset="10 36" rect="1337 37 51 68" code=">"/>
+ <Char width="142" offset="10 23" rect="1389 24 49 85" code="?"/>
+ <Char width="142" offset="0 24" rect="1439 25 69 94" code="@"/>
+ <Char width="142" offset="2 25" rect="1509 26 67 82" code="A"/>
+ <Char width="142" offset="11 25" rect="1577 26 53 82" code="B"/>
+ <Char width="142" offset="8 24" rect="1631 25 61 84" code="C"/>
+ <Char width="142" offset="10 25" rect="1693 26 56 82" code="D"/>
+ <Char width="142" offset="15 25" rect="1750 26 48 82" code="E"/>
+ <Char width="142" offset="16 25" rect="1799 26 48 82" code="F"/>
+ <Char width="142" offset="5 24" rect="1848 25 58 84" code="G"/>
+ <Char width="142" offset="10 25" rect="1907 26 51 82" code="H"/>
+ <Char width="142" offset="12 25" rect="1959 26 47 82" code="I"/>
+ <Char width="142" offset="8 25" rect="2007 26 50 83" code="J"/>
+ <Char width="142" offset="12 25" rect="2058 26 58 82" code="K"/>
+ <Char width="142" offset="16 25" rect="2117 26 49 82" code="L"/>
+ <Char width="142" offset="6 25" rect="2167 26 59 82" code="M"/>
+ <Char width="142" offset="10 25" rect="2227 26 52 82" code="N"/>
+ <Char width="142" offset="6 24" rect="2280 25 60 84" code="O"/>
+ <Char width="142" offset="14 26" rect="2341 27 52 82" code="P"/>
+ <Char width="142" offset="5 24" rect="2394 25 65 104" code="Q"/>
+ <Char width="142" offset="12 25" rect="2460 26 57 82" code="R"/>
+ <Char width="142" offset="5 24" rect="2518 25 59 84" code="S"/>
+ <Char width="142" offset="4 25" rect="2578 26 62 82" code="T"/>
+ <Char width="142" offset="9 24" rect="2641 25 54 84" code="U"/>
+ <Char width="142" offset="2 25" rect="2696 26 67 82" code="V"/>
+ <Char width="142" offset="0 25" rect="2764 26 71 82" code="W"/>
+ <Char width="142" offset="3 25" rect="2836 26 65 82" code="X"/>
+ <Char width="142" offset="2 25" rect="2902 26 67 82" code="Y"/>
+ <Char width="142" offset="8 25" rect="2970 26 55 82" code="Z"/>
+ <Char width="142" offset="22 10" rect="3026 11 30 111" code="["/>
+ <Char width="142" offset="6 10" rect="3057 11 59 110" code="\"/>
+ <Char width="142" offset="19 10" rect="3117 11 30 111" code="]"/>
+ <Char width="142" offset="8 7" rect="3148 8 55 37" code="^"/>
+ <Char width="142" offset="6 120" rect="3204 121 59 9" code="_"/>
+ <Char width="142" offset="21 13" rect="3264 14 29 20" code="`"/>
+ <Char width="142" offset="8 43" rect="3294 44 54 65" code="a"/>
+ <Char width="142" offset="12 17" rect="3349 18 51 91" code="b"/>
+ <Char width="142" offset="11 43" rect="3401 44 51 65" code="c"/>
+ <Char width="142" offset="8 17" rect="3453 18 51 91" code="d"/>
+ <Char width="142" offset="9 43" rect="3505 44 53 65" code="e"/>
+ <Char width="142" offset="11 18" rect="3559 19 55 89" code="f"/>
+ <Char width="142" offset="8 36" rect="3615 37 58 96" code="g"/>
+ <Char width="142" offset="12 18" rect="3674 19 47 89" code="h"/>
+ <Char width="142" offset="14 15" rect="3722 16 47 92" code="i"/>
+ <Char width="142" offset="10 15" rect="3770 16 42 118" code="j"/>
+ <Char width="142" offset="13 18" rect="3813 19 55 89" code="k"/>
+ <Char width="142" offset="7 19" rect="3869 20 53 89" code="l"/>
+ <Char width="142" offset="6 43" rect="3923 44 59 64" code="m"/>
+ <Char width="142" offset="12 43" rect="3983 44 47 64" code="n"/>
+ <Char width="142" offset="9 43" rect="4031 44 54 65" code="o"/>
+ <Char width="142" offset="12 43" rect="4086 44 51 89" code="p"/>
+ <Char width="142" offset="9 43" rect="4138 44 50 89" code="q"/>
+ <Char width="142" offset="12 43" rect="4189 44 50 64" code="r"/>
+ <Char width="142" offset="8 43" rect="4240 44 51 65" code="s"/>
+ <Char width="142" offset="9 28" rect="4292 29 53 80" code="t"/>
+ <Char width="142" offset="12 44" rect="4346 45 47 64" code="u"/>
+ <Char width="142" offset="7 44" rect="4394 45 57 63" code="v"/>
+ <Char width="142" offset="2 44" rect="4452 45 68 63" code="w"/>
+ <Char width="142" offset="6 45" rect="4521 46 59 62" code="x"/>
+ <Char width="142" offset="7 44" rect="4581 45 57 89" code="y"/>
+ <Char width="142" offset="12 45" rect="4639 46 48 62" code="z"/>
+ <Char width="142" offset="13 7" rect="4688 8 40 116" code="{"/>
+ <Char width="142" offset="31 0" rect="4729 1 9 143" code="|"/>
+ <Char width="142" offset="18 7" rect="4739 8 40 116" code="}"/>
+ <Char width="142" offset="5 60" rect="4780 61 61 20" code="~"/>
+</Font>
diff --git a/txtgameengine/builtin_shaders/basic/fragment.glsl b/txtgameengine/builtin_res/shaders/basic/fragment.glsl
index a9dfa6f..a9dfa6f 100644
--- a/txtgameengine/builtin_shaders/basic/fragment.glsl
+++ b/txtgameengine/builtin_res/shaders/basic/fragment.glsl
diff --git a/txtgameengine/builtin_shaders/basic/vertex.glsl b/txtgameengine/builtin_res/shaders/basic/vertex.glsl
index 92f7c97..92f7c97 100644
--- a/txtgameengine/builtin_shaders/basic/vertex.glsl
+++ b/txtgameengine/builtin_res/shaders/basic/vertex.glsl
diff --git a/txtgameengine/builtin_shaders/texture/fragment.glsl b/txtgameengine/builtin_res/shaders/texture/fragment.glsl
index d9d36fd..d9d36fd 100644
--- a/txtgameengine/builtin_shaders/texture/fragment.glsl
+++ b/txtgameengine/builtin_res/shaders/texture/fragment.glsl
diff --git a/txtgameengine/builtin_shaders/texture/vertex.glsl b/txtgameengine/builtin_res/shaders/texture/vertex.glsl
index dd93afb..dd93afb 100644
--- a/txtgameengine/builtin_shaders/texture/vertex.glsl
+++ b/txtgameengine/builtin_res/shaders/texture/vertex.glsl
diff --git a/txtgameengine/fonts.py b/txtgameengine/fonts.py
index 60660d6..fcbf8b5 100644
--- a/txtgameengine/fonts.py
+++ b/txtgameengine/fonts.py
@@ -1,15 +1,21 @@
+import os
from abc import ABC
from dataclasses import dataclass
from typing import Optional
+import typing
+import xml.dom.minidom as minidom
+
+if typing.TYPE_CHECKING:
+ from .twod import Texture
+ from .app import TxtGameApp
class Font(ABC):
- def get_glyph(self, char: str) -> Optional['Glyph']:
- raise NotImplementedError()
+ def __init__(self):
+ self.glyphs = dict()
- @property
- def font(self):
- raise NotImplementedError()
+ def get_glyph(self, char: str) -> Optional['Glyph']:
+ return self.glyphs.get(char)
@dataclass
@@ -17,10 +23,35 @@ class Glyph:
font: 'Font'
x_texture_offset: int
y_texture_offset: int
- x_width: int
- y_width: int
+ x_texture_width: int
+ y_texture_width: int
+ x_render_offset: int
+ y_render_offset: int
+ x_advance: int
+
+
+class BitmapFont(Font):
+ def __init__(self, texture: Texture, xml_path: str):
+ self.texture = texture
+ dom = minidom.parse(xml_path)
+ for char in dom.getElementsByTagName('Char'):
+ code = char.attributes['code'].value
+ width = char.attributes['width'].value
+ x_render_offset, y_render_offset = char.attributes['offset'].value.split(' ')
+ x_texture_offset, y_texture_offset, x_texture_width, y_texture_width = char.attributes['rect'].split(' ')
+ self.glyphs[code] = \
+ Glyph(self, int(x_texture_offset), int(y_texture_offset), int(x_texture_width), int(y_texture_width),
+ int(x_render_offset), int(y_render_offset), int(width))
+
+ @classmethod
+ def load(cls, app: 'TxtGameApp', image_path: os.PathLike, xml_path: os.PathLike):
+ from .twod import Texture
+ return cls(Texture(app, image_path), xml_path)
+
+class TextRenderer:
+ def __init__(self, app: 'TxtGameApp'):
+ self.app = app
-class MonospacedFont(Font):
- def get_glyph(self, char: str):
- pass
+ def use_font(self, font: Font):
+ self.font = font
diff --git a/txtgameengine/shaders/integrated.py b/txtgameengine/shaders/integrated.py
index dfa1033..d9e5ae5 100644
--- a/txtgameengine/shaders/integrated.py
+++ b/txtgameengine/shaders/integrated.py
@@ -1,7 +1,7 @@
from .shader import Shader
-from ..app import base_path
+from ..app import builtin_resource_path
-shader_base_path = base_path / 'builtin_shaders'
+shader_base_path = builtin_resource_path / 'shaders'
class BasicShader(Shader):