basilisk-engine 0.1.35__py3-none-any.whl → 0.1.36__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of basilisk-engine might be problematic. Click here for more details.
- basilisk/__init__.py +26 -26
- basilisk/audio/sound.py +27 -27
- basilisk/bsk_assets/cube.obj +48 -48
- basilisk/collisions/broad/broad_aabb.py +102 -102
- basilisk/collisions/broad/broad_bvh.py +137 -137
- basilisk/collisions/collider.py +95 -95
- basilisk/collisions/collider_handler.py +225 -225
- basilisk/collisions/narrow/contact_manifold.py +95 -95
- basilisk/collisions/narrow/dataclasses.py +34 -34
- basilisk/collisions/narrow/deprecated.py +46 -46
- basilisk/collisions/narrow/epa.py +91 -91
- basilisk/collisions/narrow/gjk.py +66 -66
- basilisk/collisions/narrow/graham_scan.py +24 -24
- basilisk/collisions/narrow/helper.py +29 -29
- basilisk/collisions/narrow/line_intersections.py +106 -106
- basilisk/collisions/narrow/sutherland_hodgman.py +75 -75
- basilisk/config.py +54 -4
- basilisk/draw/draw.py +100 -100
- basilisk/draw/draw_handler.py +175 -175
- basilisk/draw/font_renderer.py +28 -28
- basilisk/engine.py +165 -165
- basilisk/generic/abstract_bvh.py +15 -15
- basilisk/generic/abstract_custom.py +133 -133
- basilisk/generic/collisions.py +70 -70
- basilisk/generic/input_validation.py +82 -74
- basilisk/generic/math.py +6 -6
- basilisk/generic/matrices.py +35 -35
- basilisk/generic/meshes.py +72 -72
- basilisk/generic/quat.py +142 -142
- basilisk/generic/quat_methods.py +7 -7
- basilisk/generic/raycast_result.py +26 -26
- basilisk/generic/vec3.py +143 -143
- basilisk/input_output/IO_handler.py +91 -91
- basilisk/input_output/clock.py +49 -49
- basilisk/input_output/keys.py +43 -43
- basilisk/input_output/mouse.py +90 -89
- basilisk/input_output/path.py +14 -14
- basilisk/mesh/cube.py +33 -33
- basilisk/mesh/mesh.py +233 -233
- basilisk/mesh/mesh_from_data.py +150 -150
- basilisk/mesh/model.py +271 -271
- basilisk/mesh/narrow_aabb.py +89 -89
- basilisk/mesh/narrow_bvh.py +91 -91
- basilisk/mesh/narrow_primative.py +23 -23
- basilisk/nodes/helper.py +28 -28
- basilisk/nodes/node.py +704 -695
- basilisk/nodes/node_handler.py +97 -97
- basilisk/particles/particle_handler.py +64 -64
- basilisk/particles/particle_renderer.py +92 -92
- basilisk/physics/impulse.py +112 -112
- basilisk/physics/physics_body.py +43 -43
- basilisk/physics/physics_engine.py +35 -35
- basilisk/render/batch.py +103 -103
- basilisk/render/bloom.py +108 -0
- basilisk/render/camera.py +260 -260
- basilisk/render/chunk.py +108 -106
- basilisk/render/chunk_handler.py +167 -165
- basilisk/render/frame.py +107 -95
- basilisk/render/framebuffer.py +203 -192
- basilisk/render/image.py +120 -120
- basilisk/render/image_handler.py +120 -120
- basilisk/render/light.py +96 -96
- basilisk/render/light_handler.py +58 -58
- basilisk/render/material.py +232 -221
- basilisk/render/material_handler.py +133 -133
- basilisk/render/post_process.py +139 -139
- basilisk/render/shader.py +134 -134
- basilisk/render/shader_handler.py +85 -83
- basilisk/render/sky.py +120 -120
- basilisk/scene.py +289 -289
- basilisk/shaders/batch.frag +289 -276
- basilisk/shaders/batch.vert +117 -115
- basilisk/shaders/bloom_downsample.frag +43 -0
- basilisk/shaders/bloom_frame.frag +25 -0
- basilisk/shaders/bloom_upsample.frag +34 -0
- basilisk/shaders/crt.frag +31 -31
- basilisk/shaders/draw.frag +25 -22
- basilisk/shaders/draw.vert +25 -25
- basilisk/shaders/filter.frag +22 -22
- basilisk/shaders/frame.frag +12 -12
- basilisk/shaders/frame.vert +13 -13
- basilisk/shaders/geometry.frag +8 -8
- basilisk/shaders/geometry.vert +41 -41
- basilisk/shaders/normal.frag +59 -59
- basilisk/shaders/normal.vert +96 -96
- basilisk/shaders/particle.frag +71 -71
- basilisk/shaders/particle.vert +84 -84
- basilisk/shaders/sky.frag +23 -9
- basilisk/shaders/sky.vert +13 -13
- basilisk_engine-0.1.36.dist-info/METADATA +89 -0
- basilisk_engine-0.1.36.dist-info/RECORD +110 -0
- {basilisk_engine-0.1.35.dist-info → basilisk_engine-0.1.36.dist-info}/WHEEL +1 -1
- basilisk/input/__init__.py +0 -0
- basilisk/input/mouse.py +0 -62
- basilisk/input/path.py +0 -14
- basilisk_engine-0.1.35.dist-info/METADATA +0 -45
- basilisk_engine-0.1.35.dist-info/RECORD +0 -109
- {basilisk_engine-0.1.35.dist-info → basilisk_engine-0.1.36.dist-info}/top_level.txt +0 -0
basilisk/draw/draw_handler.py
CHANGED
|
@@ -1,176 +1,176 @@
|
|
|
1
|
-
import moderngl as mgl
|
|
2
|
-
import numpy as np
|
|
3
|
-
import glm
|
|
4
|
-
from math import cos, sin, atan2
|
|
5
|
-
from ..render.image import Image
|
|
6
|
-
from .font_renderer import FontRenderer
|
|
7
|
-
from ..render.shader import Shader
|
|
8
|
-
from ..generic.input_validation import validate_color, validate_rect, validate_point
|
|
9
|
-
|
|
10
|
-
class DrawHandler():
|
|
11
|
-
engine: ...
|
|
12
|
-
ctx: mgl.Context
|
|
13
|
-
"""Back reference to the parent context"""
|
|
14
|
-
program: mgl.Program
|
|
15
|
-
"""2D draw program"""
|
|
16
|
-
draw_data: list[float]
|
|
17
|
-
"""Temporary buffer for user draw calls"""
|
|
18
|
-
vbo: mgl.Buffer=None
|
|
19
|
-
"""Buffer for all 2D draws"""
|
|
20
|
-
vao: mgl.VertexArray=None
|
|
21
|
-
"""VAO for rendering all 2D draw calls"""
|
|
22
|
-
|
|
23
|
-
def __init__(self, engine) -> None:
|
|
24
|
-
# Back references
|
|
25
|
-
self.engine = engine
|
|
26
|
-
self.ctx = engine.ctx
|
|
27
|
-
|
|
28
|
-
# Get the shader
|
|
29
|
-
root = self.engine.root
|
|
30
|
-
self.shader = self.engine.shader_handler.add(Shader(self.engine, root + '/shaders/draw.vert', root + '/shaders/draw.frag'))
|
|
31
|
-
|
|
32
|
-
# Initialize draw data as blank
|
|
33
|
-
self.draw_data = []
|
|
34
|
-
self.vbo = None
|
|
35
|
-
self.vao = None
|
|
36
|
-
|
|
37
|
-
self.font_renderer = FontRenderer(self.engine.root)
|
|
38
|
-
|
|
39
|
-
def render(self) -> None:
|
|
40
|
-
"""
|
|
41
|
-
Renders all draw calls from the user since the last frame
|
|
42
|
-
"""
|
|
43
|
-
|
|
44
|
-
if not self.draw_data: return
|
|
45
|
-
|
|
46
|
-
# Reverse the draw order, and convert to C-like array
|
|
47
|
-
self.draw_data.reverse()
|
|
48
|
-
data = np.array(self.draw_data, dtype='f4')
|
|
49
|
-
ratio = np.array([2 / self.engine.win_size[0], 2 / self.engine.win_size[1]])
|
|
50
|
-
data[:,:2] = data[:,:2] * ratio - 1
|
|
51
|
-
|
|
52
|
-
# Create buffer and VAO
|
|
53
|
-
self.vbo = self.ctx.buffer(data)
|
|
54
|
-
self.vao = self.ctx.vertex_array(self.shader.program, [(self.vbo, '2f 4f 1i 1f', *['in_position', 'in_color', 'in_uses_image', 'in_alpha'])], skip_errors=True)
|
|
55
|
-
|
|
56
|
-
# Render the VAO
|
|
57
|
-
self.ctx.enable(mgl.BLEND)
|
|
58
|
-
self.ctx.blend_equation = mgl.ADDITIVE_BLENDING
|
|
59
|
-
self.vao.render()
|
|
60
|
-
|
|
61
|
-
# Clera the draw data
|
|
62
|
-
self.vbo.release()
|
|
63
|
-
self.vao.release()
|
|
64
|
-
self.vbo = None
|
|
65
|
-
self.vao = None
|
|
66
|
-
self.draw_data.clear()
|
|
67
|
-
|
|
68
|
-
def draw_rect(self, color: tuple, rect: tuple) -> None:
|
|
69
|
-
"""
|
|
70
|
-
Draws a rect to the screen
|
|
71
|
-
"""
|
|
72
|
-
|
|
73
|
-
color = validate_color('draw', 'color', color)
|
|
74
|
-
rect = validate_rect(rect)
|
|
75
|
-
|
|
76
|
-
p1 = (rect[0] , rect[1] )
|
|
77
|
-
p2 = (rect[0] , rect[1] + rect[3])
|
|
78
|
-
p3 = (rect[0] + rect[2], rect[1] )
|
|
79
|
-
p4 = (rect[0] + rect[2], rect[1] + rect[3])
|
|
80
|
-
|
|
81
|
-
v1 = (*p1, *color, 0, 0.0)
|
|
82
|
-
v2 = (*p2, *color, 0, 0.0)
|
|
83
|
-
v3 = (*p3, *color, 0, 0.0)
|
|
84
|
-
v4 = (*p4, *color, 0, 0.0)
|
|
85
|
-
|
|
86
|
-
self.draw_data.extend([
|
|
87
|
-
v1, v3, v2,
|
|
88
|
-
v2, v3, v4
|
|
89
|
-
])
|
|
90
|
-
|
|
91
|
-
def draw_circle(self, color: tuple, center: tuple, radius: int, resolution: int=20, outer_color: tuple=None) -> None:
|
|
92
|
-
"""
|
|
93
|
-
Draws a rect between centered on x, y with width and height
|
|
94
|
-
Args:
|
|
95
|
-
color: tuple(r, g, b) | tuple(r, g, b, a)
|
|
96
|
-
The color value of the circle, with int components in range [0, 255]
|
|
97
|
-
center: tuple (x: float, y: float)
|
|
98
|
-
Center of the circle, given in pixels
|
|
99
|
-
radius: float
|
|
100
|
-
Radius of the circle, given in pixels
|
|
101
|
-
resolution: float
|
|
102
|
-
The number of triangles used to approximate the circle
|
|
103
|
-
"""
|
|
104
|
-
|
|
105
|
-
if not outer_color: outer_color = color
|
|
106
|
-
color = validate_color('draw', 'color', color)
|
|
107
|
-
outer_color = validate_color('draw', 'color', outer_color)
|
|
108
|
-
p1 = validate_point(center)
|
|
109
|
-
|
|
110
|
-
v1 = (*p1, *color, 0, 0.0)
|
|
111
|
-
theta = 0
|
|
112
|
-
delta_theta = (2 * 3.1415) / resolution
|
|
113
|
-
|
|
114
|
-
for triangle in range(resolution):
|
|
115
|
-
v2 = (center[0] + radius * cos(theta), center[1] + radius * sin(theta), *outer_color, 0, 0.0)
|
|
116
|
-
theta += delta_theta
|
|
117
|
-
v3 = (center[0] + radius * cos(theta), center[1] + radius * sin(theta), *outer_color, 0, 0.0)
|
|
118
|
-
self.draw_data.extend([v1, v2, v3])
|
|
119
|
-
|
|
120
|
-
def draw_line(self, color: tuple, p1: tuple, p2: tuple, thickness: int=1):
|
|
121
|
-
"""
|
|
122
|
-
Draws a line between two points
|
|
123
|
-
Args:
|
|
124
|
-
color: tuple=(r, g, b) | tuple=(r, g, b, a)
|
|
125
|
-
Color of the line
|
|
126
|
-
p1: tuple=((x1, y1), (x2, y2))
|
|
127
|
-
Starting point of the line. Given in pixels
|
|
128
|
-
p1: tuple=((x1, y1), (x2, y2))
|
|
129
|
-
Starting point of the line. Given in pixels
|
|
130
|
-
thickness: int
|
|
131
|
-
Size of the line on either side. pixels
|
|
132
|
-
"""
|
|
133
|
-
|
|
134
|
-
color = validate_color('draw', 'color', color)
|
|
135
|
-
|
|
136
|
-
p1 = glm.vec2(validate_point(p1))
|
|
137
|
-
p2 = glm.vec2(validate_point(p2))
|
|
138
|
-
|
|
139
|
-
thickness /= 2
|
|
140
|
-
|
|
141
|
-
unit = glm.normalize(p1 - p2) * thickness
|
|
142
|
-
theta = atan2(*unit)
|
|
143
|
-
perp_vector = glm.vec2(cos(-theta), sin(-theta)) * thickness
|
|
144
|
-
|
|
145
|
-
v1 = (*(p1 - perp_vector), *color, 0, 0.0)
|
|
146
|
-
v2 = (*(p1 + perp_vector), *color, 0, 0.0)
|
|
147
|
-
v3 = (*(p2 - perp_vector), *color, 0, 0.0)
|
|
148
|
-
v4 = (*(p2 + perp_vector), *color, 0, 0.0)
|
|
149
|
-
|
|
150
|
-
self.draw_data.extend([v1, v3, v4, v2, v1, v4])
|
|
151
|
-
|
|
152
|
-
def blit(self, image: Image, rect: tuple, alpha: float=1.0):
|
|
153
|
-
rect = validate_rect(rect)
|
|
154
|
-
|
|
155
|
-
p1 = (rect[0] , rect[1] )
|
|
156
|
-
p2 = (rect[0] , rect[1] + rect[3])
|
|
157
|
-
p3 = (rect[0] + rect[2], rect[1] )
|
|
158
|
-
p4 = (rect[0] + rect[2], rect[1] + rect[3])
|
|
159
|
-
|
|
160
|
-
v1 = (*p1, *image.index, 0, 0, 1, alpha)
|
|
161
|
-
v2 = (*p2, *image.index, 0, 1, 1, alpha)
|
|
162
|
-
v3 = (*p3, *image.index, 1, 0, 1, alpha)
|
|
163
|
-
v4 = (*p4, *image.index, 1, 1, 1, alpha)
|
|
164
|
-
|
|
165
|
-
self.draw_data.extend([
|
|
166
|
-
v1, v3, v2,
|
|
167
|
-
v2, v3, v4
|
|
168
|
-
])
|
|
169
|
-
|
|
170
|
-
def __del__(self) -> None:
|
|
171
|
-
"""
|
|
172
|
-
Releases any allocated data
|
|
173
|
-
"""
|
|
174
|
-
|
|
175
|
-
if self.vbo: self.vbo.release()
|
|
1
|
+
import moderngl as mgl
|
|
2
|
+
import numpy as np
|
|
3
|
+
import glm
|
|
4
|
+
from math import cos, sin, atan2
|
|
5
|
+
from ..render.image import Image
|
|
6
|
+
from .font_renderer import FontRenderer
|
|
7
|
+
from ..render.shader import Shader
|
|
8
|
+
from ..generic.input_validation import validate_color, validate_rect, validate_point
|
|
9
|
+
|
|
10
|
+
class DrawHandler():
|
|
11
|
+
engine: ...
|
|
12
|
+
ctx: mgl.Context
|
|
13
|
+
"""Back reference to the parent context"""
|
|
14
|
+
program: mgl.Program
|
|
15
|
+
"""2D draw program"""
|
|
16
|
+
draw_data: list[float]
|
|
17
|
+
"""Temporary buffer for user draw calls"""
|
|
18
|
+
vbo: mgl.Buffer=None
|
|
19
|
+
"""Buffer for all 2D draws"""
|
|
20
|
+
vao: mgl.VertexArray=None
|
|
21
|
+
"""VAO for rendering all 2D draw calls"""
|
|
22
|
+
|
|
23
|
+
def __init__(self, engine) -> None:
|
|
24
|
+
# Back references
|
|
25
|
+
self.engine = engine
|
|
26
|
+
self.ctx = engine.ctx
|
|
27
|
+
|
|
28
|
+
# Get the shader
|
|
29
|
+
root = self.engine.root
|
|
30
|
+
self.shader = self.engine.shader_handler.add(Shader(self.engine, root + '/shaders/draw.vert', root + '/shaders/draw.frag'))
|
|
31
|
+
|
|
32
|
+
# Initialize draw data as blank
|
|
33
|
+
self.draw_data = []
|
|
34
|
+
self.vbo = None
|
|
35
|
+
self.vao = None
|
|
36
|
+
|
|
37
|
+
self.font_renderer = FontRenderer(self.engine.root)
|
|
38
|
+
|
|
39
|
+
def render(self) -> None:
|
|
40
|
+
"""
|
|
41
|
+
Renders all draw calls from the user since the last frame
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
if not self.draw_data: return
|
|
45
|
+
|
|
46
|
+
# Reverse the draw order, and convert to C-like array
|
|
47
|
+
self.draw_data.reverse()
|
|
48
|
+
data = np.array(self.draw_data, dtype='f4')
|
|
49
|
+
ratio = np.array([2 / self.engine.win_size[0], 2 / self.engine.win_size[1]])
|
|
50
|
+
data[:,:2] = data[:,:2] * ratio - 1
|
|
51
|
+
|
|
52
|
+
# Create buffer and VAO
|
|
53
|
+
self.vbo = self.ctx.buffer(data)
|
|
54
|
+
self.vao = self.ctx.vertex_array(self.shader.program, [(self.vbo, '2f 4f 1i 1f', *['in_position', 'in_color', 'in_uses_image', 'in_alpha'])], skip_errors=True)
|
|
55
|
+
|
|
56
|
+
# Render the VAO
|
|
57
|
+
self.ctx.enable(mgl.BLEND)
|
|
58
|
+
self.ctx.blend_equation = mgl.ADDITIVE_BLENDING
|
|
59
|
+
self.vao.render()
|
|
60
|
+
|
|
61
|
+
# Clera the draw data
|
|
62
|
+
self.vbo.release()
|
|
63
|
+
self.vao.release()
|
|
64
|
+
self.vbo = None
|
|
65
|
+
self.vao = None
|
|
66
|
+
self.draw_data.clear()
|
|
67
|
+
|
|
68
|
+
def draw_rect(self, color: tuple, rect: tuple) -> None:
|
|
69
|
+
"""
|
|
70
|
+
Draws a rect to the screen
|
|
71
|
+
"""
|
|
72
|
+
|
|
73
|
+
color = validate_color('draw', 'color', color)
|
|
74
|
+
rect = validate_rect(rect)
|
|
75
|
+
|
|
76
|
+
p1 = (rect[0] , rect[1] )
|
|
77
|
+
p2 = (rect[0] , rect[1] + rect[3])
|
|
78
|
+
p3 = (rect[0] + rect[2], rect[1] )
|
|
79
|
+
p4 = (rect[0] + rect[2], rect[1] + rect[3])
|
|
80
|
+
|
|
81
|
+
v1 = (*p1, *color, 0, 0.0)
|
|
82
|
+
v2 = (*p2, *color, 0, 0.0)
|
|
83
|
+
v3 = (*p3, *color, 0, 0.0)
|
|
84
|
+
v4 = (*p4, *color, 0, 0.0)
|
|
85
|
+
|
|
86
|
+
self.draw_data.extend([
|
|
87
|
+
v1, v3, v2,
|
|
88
|
+
v2, v3, v4
|
|
89
|
+
])
|
|
90
|
+
|
|
91
|
+
def draw_circle(self, color: tuple, center: tuple, radius: int, resolution: int=20, outer_color: tuple=None) -> None:
|
|
92
|
+
"""
|
|
93
|
+
Draws a rect between centered on x, y with width and height
|
|
94
|
+
Args:
|
|
95
|
+
color: tuple(r, g, b) | tuple(r, g, b, a)
|
|
96
|
+
The color value of the circle, with int components in range [0, 255]
|
|
97
|
+
center: tuple (x: float, y: float)
|
|
98
|
+
Center of the circle, given in pixels
|
|
99
|
+
radius: float
|
|
100
|
+
Radius of the circle, given in pixels
|
|
101
|
+
resolution: float
|
|
102
|
+
The number of triangles used to approximate the circle
|
|
103
|
+
"""
|
|
104
|
+
|
|
105
|
+
if not outer_color: outer_color = color
|
|
106
|
+
color = validate_color('draw', 'color', color)
|
|
107
|
+
outer_color = validate_color('draw', 'color', outer_color)
|
|
108
|
+
p1 = validate_point(center)
|
|
109
|
+
|
|
110
|
+
v1 = (*p1, *color, 0, 0.0)
|
|
111
|
+
theta = 0
|
|
112
|
+
delta_theta = (2 * 3.1415) / resolution
|
|
113
|
+
|
|
114
|
+
for triangle in range(resolution):
|
|
115
|
+
v2 = (center[0] + radius * cos(theta), center[1] + radius * sin(theta), *outer_color, 0, 0.0)
|
|
116
|
+
theta += delta_theta
|
|
117
|
+
v3 = (center[0] + radius * cos(theta), center[1] + radius * sin(theta), *outer_color, 0, 0.0)
|
|
118
|
+
self.draw_data.extend([v1, v2, v3])
|
|
119
|
+
|
|
120
|
+
def draw_line(self, color: tuple, p1: tuple, p2: tuple, thickness: int=1):
|
|
121
|
+
"""
|
|
122
|
+
Draws a line between two points
|
|
123
|
+
Args:
|
|
124
|
+
color: tuple=(r, g, b) | tuple=(r, g, b, a)
|
|
125
|
+
Color of the line
|
|
126
|
+
p1: tuple=((x1, y1), (x2, y2))
|
|
127
|
+
Starting point of the line. Given in pixels
|
|
128
|
+
p1: tuple=((x1, y1), (x2, y2))
|
|
129
|
+
Starting point of the line. Given in pixels
|
|
130
|
+
thickness: int
|
|
131
|
+
Size of the line on either side. pixels
|
|
132
|
+
"""
|
|
133
|
+
|
|
134
|
+
color = validate_color('draw', 'color', color)
|
|
135
|
+
|
|
136
|
+
p1 = glm.vec2(validate_point(p1))
|
|
137
|
+
p2 = glm.vec2(validate_point(p2))
|
|
138
|
+
|
|
139
|
+
thickness /= 2
|
|
140
|
+
|
|
141
|
+
unit = glm.normalize(p1 - p2) * thickness
|
|
142
|
+
theta = atan2(*unit)
|
|
143
|
+
perp_vector = glm.vec2(cos(-theta), sin(-theta)) * thickness
|
|
144
|
+
|
|
145
|
+
v1 = (*(p1 - perp_vector), *color, 0, 0.0)
|
|
146
|
+
v2 = (*(p1 + perp_vector), *color, 0, 0.0)
|
|
147
|
+
v3 = (*(p2 - perp_vector), *color, 0, 0.0)
|
|
148
|
+
v4 = (*(p2 + perp_vector), *color, 0, 0.0)
|
|
149
|
+
|
|
150
|
+
self.draw_data.extend([v1, v3, v4, v2, v1, v4])
|
|
151
|
+
|
|
152
|
+
def blit(self, image: Image, rect: tuple, alpha: float=1.0):
|
|
153
|
+
rect = validate_rect(rect)
|
|
154
|
+
|
|
155
|
+
p1 = (rect[0] , rect[1] )
|
|
156
|
+
p2 = (rect[0] , rect[1] + rect[3])
|
|
157
|
+
p3 = (rect[0] + rect[2], rect[1] )
|
|
158
|
+
p4 = (rect[0] + rect[2], rect[1] + rect[3])
|
|
159
|
+
|
|
160
|
+
v1 = (*p1, *image.index, 0, 0, 1, alpha)
|
|
161
|
+
v2 = (*p2, *image.index, 0, 1, 1, alpha)
|
|
162
|
+
v3 = (*p3, *image.index, 1, 0, 1, alpha)
|
|
163
|
+
v4 = (*p4, *image.index, 1, 1, 1, alpha)
|
|
164
|
+
|
|
165
|
+
self.draw_data.extend([
|
|
166
|
+
v1, v3, v2,
|
|
167
|
+
v2, v3, v4
|
|
168
|
+
])
|
|
169
|
+
|
|
170
|
+
def __del__(self) -> None:
|
|
171
|
+
"""
|
|
172
|
+
Releases any allocated data
|
|
173
|
+
"""
|
|
174
|
+
|
|
175
|
+
if self.vbo: self.vbo.release()
|
|
176
176
|
if self.vao: self.vao.release()
|
basilisk/draw/font_renderer.py
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import pygame as pg
|
|
2
|
-
|
|
3
|
-
class FontRenderer():
|
|
4
|
-
def __init__(self, root):
|
|
5
|
-
pg.font.init()
|
|
6
|
-
self.font = pg.font.Font(root + '/bsk_assets/Roboto-Regular.ttf', 48)
|
|
7
|
-
self.text_renders = {}
|
|
8
|
-
|
|
9
|
-
def render(self, text, color=(255, 255, 255), bold=False, underline=False, italic=False):
|
|
10
|
-
'''
|
|
11
|
-
Renders any font which has been loaded to the class instance.
|
|
12
|
-
Args:
|
|
13
|
-
text::str
|
|
14
|
-
Text to be rendered
|
|
15
|
-
color::(int, int, int) =(255, 255, 255)
|
|
16
|
-
The RGB value of the text
|
|
17
|
-
bold::bool (=False)
|
|
18
|
-
Specifies if the text should be rendered in bolded font
|
|
19
|
-
underline::bool (=False)
|
|
20
|
-
Specifies if the text should be underlined in bolded font
|
|
21
|
-
italic::bool (=False)
|
|
22
|
-
Specifies if the text should be rendered in italicized font
|
|
23
|
-
'''
|
|
24
|
-
self.font.set_bold(bold)
|
|
25
|
-
self.font.set_underline(underline)
|
|
26
|
-
self.font.set_italic(italic)
|
|
27
|
-
|
|
28
|
-
return self.font.render(text, True, color, (0, 0, 0, 0))
|
|
1
|
+
import pygame as pg
|
|
2
|
+
|
|
3
|
+
class FontRenderer():
|
|
4
|
+
def __init__(self, root):
|
|
5
|
+
pg.font.init()
|
|
6
|
+
self.font = pg.font.Font(root + '/bsk_assets/Roboto-Regular.ttf', 48)
|
|
7
|
+
self.text_renders = {}
|
|
8
|
+
|
|
9
|
+
def render(self, text, color=(255, 255, 255), bold=False, underline=False, italic=False):
|
|
10
|
+
'''
|
|
11
|
+
Renders any font which has been loaded to the class instance.
|
|
12
|
+
Args:
|
|
13
|
+
text::str
|
|
14
|
+
Text to be rendered
|
|
15
|
+
color::(int, int, int) =(255, 255, 255)
|
|
16
|
+
The RGB value of the text
|
|
17
|
+
bold::bool (=False)
|
|
18
|
+
Specifies if the text should be rendered in bolded font
|
|
19
|
+
underline::bool (=False)
|
|
20
|
+
Specifies if the text should be underlined in bolded font
|
|
21
|
+
italic::bool (=False)
|
|
22
|
+
Specifies if the text should be rendered in italicized font
|
|
23
|
+
'''
|
|
24
|
+
self.font.set_bold(bold)
|
|
25
|
+
self.font.set_underline(underline)
|
|
26
|
+
self.font.set_italic(italic)
|
|
27
|
+
|
|
28
|
+
return self.font.render(text, True, color, (0, 0, 0, 0))
|