Skip to content

Commit

Permalink
cleanup and minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Leterax committed Mar 2, 2021
1 parent 6af642f commit 1977a6c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
8 changes: 4 additions & 4 deletions config.ini
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[WORLD]
chunk_size = 32
chunk_size = 16
render_distance = 33
seed = 1

[PLAYER]
x = 0
y = 0
z = 0
x = 305
y = 171
z = -100

2 changes: 1 addition & 1 deletion rendering/resources/programs/test.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ out vec3 normal;
out vec4 color;

void main() {
mat4 m_view = m_camera * m_model;
mat4 m_view = m_camera * m_model;
vec4 p = m_view * vec4(in_position, 1.0);
gl_Position = m_proj * p;
mat3 m_normal = inverse(transpose(mat3(m_view)));
Expand Down
24 changes: 12 additions & 12 deletions rendering/terrain_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import configparser
from base import CameraWindow

np.set_printoptions(linewidth=100)

config_file = "config.ini"
config = configparser.ConfigParser()
config.read(config_file)
Expand Down Expand Up @@ -86,7 +84,7 @@ class TerrainTest(CameraWindow):
aspect_ratio = None
window_size = 1280, 720
resizable = True
samples = 4
samples = 0
clear_color = 51 / 255, 51 / 255, 51 / 255

def __init__(self, **kwargs) -> None:
Expand Down Expand Up @@ -164,7 +162,8 @@ def __init__(self, **kwargs) -> None:
]
# number of vertices for each vao/buffer
self.num_vertices = [0] * self.render_distance ** 2

# position of chunks, used for placing the frustrum culling primitive
self.chunk_positions = [(0, 0, 0)] * self.render_distance ** 2
# Texture
self.world_texture = self.ctx.texture(
(self.N, self.render_distance ** 2), alignment=4, dtype="i4", components=1
Expand Down Expand Up @@ -295,10 +294,10 @@ def generate_chunk(self, out_buffer, world_pos):
self.geometry_vao.transform(out_buffer, mode=moderngl.POINTS)

self.num_vertices[chunk_id] = self.q.primitives * 3
# print(f"{chunk_id}: {self.rendering_vaos[chunk_id]}, \
# {out_buffer} @ {self.q.primitives * 3}")
self.chunk_positions[chunk_id] = world_pos

def render(self, time: float, frame_time: float) -> None:
# print("rendering")
self.ctx.enable_only(moderngl.DEPTH_TEST)

self.player.position = self.camera.position
Expand All @@ -316,7 +315,10 @@ def render(self, time: float, frame_time: float) -> None:
self.test_render_program["m_proj"].write(self.camera.projection.matrix)

self.test_render_program["id"] = -1
for vao, num_vertices in zip(self.rendering_vaos, self.num_vertices):

grouped_vaos = zip(self.rendering_vaos, self.num_vertices)

for vao, num_vertices in grouped_vaos:
if self.show_id:
self.test_render_program["id"] = vao.glo
vao.render(mode=moderngl.TRIANGLES, vertices=num_vertices)
Expand All @@ -334,17 +336,15 @@ def key_event(self, key, action, modifiers):
super().key_event(key, action, modifiers)
keys = self.wnd.keys

if key == keys.G:
if key == keys.G and action == keys.ACTION_PRESS:
self.ctx.wireframe = not self.ctx.wireframe
if self.ctx.wireframe:
self.ctx.enable_only(moderngl.DEPTH_TEST)
else:
self.ctx.enable_only(moderngl.DEPTH_TEST | moderngl.CULL_FACE)

if key == keys.F:
self.show_id = True
else:
self.show_id = False
if key == keys.F and action == keys.ACTION_PRESS:
self.show_id = not self.show_id


if __name__ == "__main__":
Expand Down

0 comments on commit 1977a6c

Please sign in to comment.