src/config.onyx
*.wasm
run_tree/lib/
+lib/
+++ /dev/null
-precision mediump float;
-
-COMM vec2 v_texture;
-
-#ifdef VERTEX_SHADER
-
-layout(location = 0) in vec2 a_interp;
-layout(location = 1) in vec2 a_pos_top_left;
-layout(location = 2) in vec2 a_pos_bottom_right;
-layout(location = 3) in vec2 a_tex_top_left;
-layout(location = 4) in vec2 a_tex_bottom_right;
-
-layout(std140) uniform u_window_matrix_block {
- mat4 u_window;
-};
-
-layout(std140) uniform u_world_matrix_block {
- mat4 u_world;
- mat4 u_model;
-};
-
-void main() {
- gl_Position = u_window * u_world * u_model * vec4(mix(a_pos_top_left, a_pos_bottom_right, a_interp), 0, 1);
- v_texture = mix(a_tex_top_left, a_tex_bottom_right, a_interp);
-}
-
-#endif
-
-#ifdef FRAGMENT_SHADER
-
-uniform sampler2D u_texture;
-uniform vec4 u_color;
-
-out vec4 fragColor;
-
-void main() {
- fragColor = vec4(u_color.rgb, u_color.a * texture(u_texture, v_texture).a);
-}
-
-#endif
+++ /dev/null
-precision mediump float;
-
-COMM vec4 v_col;
-COMM vec2 v_tex;
-
-#ifdef VERTEX_SHADER
-
-layout(location = 0) in vec2 a_pos;
-layout(location = 1) in vec2 a_tex;
-layout(location = 2) in vec4 a_col;
-
-layout(std140) uniform u_window_matrix_block {
- mat4 u_window;
-};
-
-layout(std140) uniform u_world_matrix_block {
- mat4 u_world;
- mat4 u_model;
-};
-
-void main() {
- gl_Position = u_window * u_world * u_model * vec4(a_pos, 0, 1);
- v_tex = a_tex;
- v_col = a_col;
-}
-
-#endif
-
-#ifdef FRAGMENT_SHADER
-
-uniform sampler2D u_texture;
-uniform float u_texture_enabled;
-
-out vec4 fragColor;
-
-void main() {
- fragColor = v_col * mix(vec4(1), texture(u_texture, v_tex), vec4(u_texture_enabled));
-}
-
-#endif
use core
-use glfw3
use ogre
@Entity_Schematic.{ "Wall" }
Audio_Manager.set_volume(0.1);
distortion_shader = shader_make("./assets/shaders/crt.glsl");
- shader_link_window_matrix_block(distortion_shader);
- shader_link_world_matrix_block(distortion_shader);
-
- scene_canvas = canvas_make(800, 608);
+ scene_canvas = canvas_make(800, 608);
// This process of queueing the asset bucket should
// be made automatic somehow...
#if DEBUG { debug_font: Font; }
init :: () {
+ if !ogre_init() {
+ debug_log(.Critical, "Failed to initialize OGRE!");
+ os.exit(1);
+ }
+
window = window_create(1200, 900, #cstr "Bar Simulator");
window_use(^window);
- ogre_init();
+ ogre_setup();
editor_init();
game_init();
input_update();
if is_key_just_up(GLFW_KEY_ESCAPE) {
- glfwSetWindowShouldClose(window.glfw_window, true);
+ window->set_should_close(true);
return;
}
font_print(debug_font, ~~window.width - font_get_width(debug_font, version_str), 16, version_str);
}
- glfwSwapBuffers(window.glfw_window);
+ window->swap_buffers();
}
game_draw();
seconds := 0.0;
frame_count := 0;
- while !glfwWindowShouldClose(window.glfw_window) {
- glfwPollEvents();
+ while !(window->should_close()) {
+ window->poll_events();
now = glfwGetTime();
dt := now - last;
random.set_seed(os.time());
debug_set_level(.Info);
- if !glfwInit() {
- debug_log(.Critical, "Failed to initialize GLFW!");
- os.exit(1);
- }
-
init();
run();
deinit();
fonts_init :: () {
map.init(^font_registry);
- font_shader = shader_make("./assets/shaders/font.glsl");
+ font_shader = shader_make_from_source(#file_contents "./shaders/font.glsl");
shader_use(font_shader);
- shader_link_window_matrix_block(font_shader);
- shader_link_world_matrix_block(font_shader);
glGenVertexArrays(1, ^font_vao);
glBindVertexArray(font_vao);
memory.alloc_slice(^vertex_data, Maximum_Vertex_Count);
vertex_count = 0;
- imgui_shader = shader_make(Shader_Path);
- shader_use(imgui_shader);
- shader_link_window_matrix_block(imgui_shader);
- shader_link_world_matrix_block(imgui_shader);
+ imgui_shader = shader_make_from_source(#file_contents "./shaders/imgui.glsl");
shader_set_uniform(imgui_shader, #cstr "u_texture_enabled", 0.0f);
shader_set_uniform(imgui_shader, #cstr "u_texture", 0);
}
#local {
- Shader_Path :: "./assets/shaders/imgui.glsl"
imgui_shader: Shader;
Maximum_Vertex_Count :: 1023;
package ogre
-ogre_init :: () {
+use glfw3 {glfwInit}
+
+ogre_init :: () -> bool {
+ if !glfwInit() {
+ return false;
+ }
+
+ return true;
+}
+
+ogre_setup :: () {
shaders_init();
fonts_init();
immediate_init();
prog := link_program(vs, fs);
- return Shader.{vs, fs, prog};
+ s := Shader.{vs, fs, prog};
+ shader_link_window_matrix_block(s);
+ shader_link_world_matrix_block(s);
+
+ return s;
}
shader_use :: (shader: Shader) {
shader_link_window_matrix_block :: (use shader: Shader) {
matrix_block_index := glGetUniformBlockIndex(prog, #cstr "u_window_matrix_block");
+ if matrix_block_index == GL_INVALID_INDEX do return;
+
glUniformBlockBinding(prog, matrix_block_index, WINDOW_MATRIX_BLOCK);
}
shader_link_world_matrix_block :: (use shader: Shader) {
matrix_block_index := glGetUniformBlockIndex(prog, #cstr "u_world_matrix_block");
+ if matrix_block_index == GL_INVALID_INDEX do return;
+
glUniformBlockBinding(prog, matrix_block_index, WORLD_MATRIX_BLOCK);
}
--- /dev/null
+precision mediump float;
+
+COMM vec2 v_texture;
+
+#ifdef VERTEX_SHADER
+
+layout(location = 0) in vec2 a_interp;
+layout(location = 1) in vec2 a_pos_top_left;
+layout(location = 2) in vec2 a_pos_bottom_right;
+layout(location = 3) in vec2 a_tex_top_left;
+layout(location = 4) in vec2 a_tex_bottom_right;
+
+layout(std140) uniform u_window_matrix_block {
+ mat4 u_window;
+};
+
+layout(std140) uniform u_world_matrix_block {
+ mat4 u_world;
+ mat4 u_model;
+};
+
+void main() {
+ gl_Position = u_window * u_world * u_model * vec4(mix(a_pos_top_left, a_pos_bottom_right, a_interp), 0, 1);
+ v_texture = mix(a_tex_top_left, a_tex_bottom_right, a_interp);
+}
+
+#endif
+
+#ifdef FRAGMENT_SHADER
+
+uniform sampler2D u_texture;
+uniform vec4 u_color;
+
+out vec4 fragColor;
+
+void main() {
+ fragColor = vec4(u_color.rgb, u_color.a * texture(u_texture, v_texture).a);
+}
+
+#endif
--- /dev/null
+precision mediump float;
+
+COMM vec4 v_col;
+COMM vec2 v_tex;
+
+#ifdef VERTEX_SHADER
+
+layout(location = 0) in vec2 a_pos;
+layout(location = 1) in vec2 a_tex;
+layout(location = 2) in vec4 a_col;
+
+layout(std140) uniform u_window_matrix_block {
+ mat4 u_window;
+};
+
+layout(std140) uniform u_world_matrix_block {
+ mat4 u_world;
+ mat4 u_model;
+};
+
+void main() {
+ gl_Position = u_window * u_world * u_model * vec4(a_pos, 0, 1);
+ v_tex = a_tex;
+ v_col = a_col;
+}
+
+#endif
+
+#ifdef FRAGMENT_SHADER
+
+uniform sampler2D u_texture;
+uniform float u_texture_enabled;
+
+out vec4 fragColor;
+
+void main() {
+ fragColor = v_col * mix(vec4(1), texture(u_texture, v_tex), vec4(u_texture_enabled));
+}
+
+#endif
filename: str;
}
-texture_lookup :: #match {}
-#match texture_lookup (filename: str) -> (Texture, bool) {
+texture_lookup :: #match #local {}
+
+#overload
+texture_lookup :: (filename: str) -> (Texture, bool) {
if texture_cache->has(filename) {
return texture_cache[filename], true;
}
return texture_lookup(cast(cstr) buffer);
}
-#match texture_lookup (path: cstr) -> (Texture, bool) {
+#overload
+texture_lookup :: (path: cstr) -> (Texture, bool) {
filename := string.from_cstr(path);
if texture_cache->has(filename) {
return texture_cache[filename], true;
global_window = w;
}
+window_should_close :: (w: ^Window) -> bool {
+ return glfwWindowShouldClose(w.glfw_window);
+}
+
+window_set_should_close :: (w: ^Window, b: bool) {
+ return glfwSetWindowShouldClose(w.glfw_window, b);
+}
+
+window_swap_buffers :: (w: ^Window) {
+ glfwSwapBuffers(w.glfw_window);
+}
+
+window_poll_events :: (_: ^Window) {
+ glfwPollEvents();
+}
+
+#inject Window {
+ should_close :: window_should_close;
+ set_should_close :: window_set_should_close;
+ swap_buffers :: window_swap_buffers;
+ poll_events :: window_poll_events;
+}
+
//
// These have to be macros because '#export_name' is used on the argument,
// which requires that they are compile time known functions.