Bump engine submodule and move shader loading code to game.
This commit is contained in:
parent
8a33228dff
commit
a145a4bea3
2
engine
2
engine
@ -1 +1 @@
|
||||
Subproject commit 1e56cc1c28d4f9977b55f47566c3c8050f25670c
|
||||
Subproject commit af25548752d7ae7004a937307e06bd4810e46cc7
|
@ -18,7 +18,8 @@ from math import pi, tau, dist
|
||||
|
||||
from engine import *
|
||||
|
||||
from game import math, resources, camera, batch, triangles, generator, environment, sea
|
||||
from game import (
|
||||
math, resources, shader, camera, batch, triangles, generator, environment, sea)
|
||||
|
||||
def main():
|
||||
print("Generating terrain...")
|
||||
@ -29,8 +30,8 @@ def main():
|
||||
|
||||
print("Initializing...")
|
||||
window = initialize(b'RK Island', 1600, 900)
|
||||
terrain_shader = load_shader(b'game/shaders/terrain')
|
||||
sky_shader = load_shader(b'game/shaders/sky')
|
||||
terrain_shader = shader.load('terrain')
|
||||
sky_shader = shader.load('sky')
|
||||
|
||||
print("Loading resources...")
|
||||
select_shader(terrain_shader)
|
||||
|
44
game/shader.py
Normal file
44
game/shader.py
Normal file
@ -0,0 +1,44 @@
|
||||
# Copyright (C) 2022 RozK
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from engine import load_shader
|
||||
|
||||
#TODO: preprocessing (at least includes)
|
||||
|
||||
def load(name):
|
||||
def _cleanup(_line):
|
||||
return _line.partition('//')[0].strip()
|
||||
def _filter(_line):
|
||||
return _line
|
||||
def _convert(_line):
|
||||
return bytes(_line, 'utf-8') + b'\n'
|
||||
def load_source(_path):
|
||||
if not _path.exists():
|
||||
print("Cannot find", _path)
|
||||
return None
|
||||
return list(map(_convert, filter(_filter, map(_cleanup, open(_path, 'rt')))))
|
||||
print("Loading shader", name)
|
||||
path = Path('.') / 'game' / 'shaders'
|
||||
vert_lines = load_source(path / (name + '_opengles.vert'))
|
||||
if not vert_lines:
|
||||
print("Error: Vertex shader is empty.")
|
||||
return None
|
||||
frag_lines = load_source(path / (name + '_opengles.frag'))
|
||||
if not frag_lines:
|
||||
print("Error: Fragment shader is empty.")
|
||||
return None
|
||||
return load_shader(vert_lines, frag_lines)
|
Loading…
Reference in New Issue
Block a user