├── .gitignore ├── LICENSE ├── README.md ├── assets ├── arial.ttf ├── embed │ ├── texture.frag │ └── texture.vert ├── icon.png └── test.png ├── build.zig ├── examples ├── basic_setup.zig ├── camera2d.zig ├── camera2d_advanced.zig ├── custombatch.zig ├── customshaders.zig ├── ecs.zig ├── ecs_benchmark.zig ├── example_shooter_game │ ├── .gitignore │ ├── assets │ │ ├── VCR_OSD_MONO.ttf │ │ ├── kenney_simplespace │ │ │ ├── effect_purple.png │ │ │ ├── effect_yellow.png │ │ │ ├── enemy_A.png │ │ │ ├── enemy_B.png │ │ │ ├── enemy_C.png │ │ │ ├── enemy_D.png │ │ │ ├── enemy_E.png │ │ │ ├── icon_crossLarge.png │ │ │ ├── icon_crossSmall.png │ │ │ ├── icon_exclamationLarge.png │ │ │ ├── icon_exclamationSmall.png │ │ │ ├── icon_plusLarge.png │ │ │ ├── icon_plusSmall.png │ │ │ ├── meteor_detailedLarge.png │ │ │ ├── meteor_detailedSmall.png │ │ │ ├── meteor_large.png │ │ │ ├── meteor_small.png │ │ │ ├── meteor_squareDetailedLarge.png │ │ │ ├── meteor_squareDetailedSmall.png │ │ │ ├── meteor_squareLarge.png │ │ │ ├── meteor_squareSmall.png │ │ │ ├── satellite_A.png │ │ │ ├── satellite_B.png │ │ │ ├── satellite_C.png │ │ │ ├── satellite_D.png │ │ │ ├── ship_A.png │ │ │ ├── ship_B.png │ │ │ ├── ship_C.png │ │ │ ├── ship_D.png │ │ │ ├── ship_E.png │ │ │ ├── ship_F.png │ │ │ ├── ship_G.png │ │ │ ├── ship_H.png │ │ │ ├── ship_I.png │ │ │ ├── ship_J.png │ │ │ ├── ship_K.png │ │ │ ├── ship_L.png │ │ │ ├── ship_sidesA.png │ │ │ ├── ship_sidesB.png │ │ │ ├── ship_sidesC.png │ │ │ ├── ship_sidesD.png │ │ │ ├── star_large.png │ │ │ ├── star_medium.png │ │ │ ├── star_small.png │ │ │ ├── star_tiny.png │ │ │ ├── station_A.png │ │ │ ├── station_B.png │ │ │ └── station_C.png │ │ └── station_heart.png │ ├── build.zig │ ├── libbuild.zig │ └── src │ │ ├── ecs.zig │ │ ├── game.zig │ │ ├── gui.zig │ │ ├── main.zig │ │ └── run.sh ├── gui.zig ├── input.zig ├── shape_drawing.zig ├── shooter.zig ├── text_rendering.zig └── texture_drawing.zig ├── get-started.md ├── include ├── glfw-3.3.4 │ ├── include │ │ └── GLFW │ │ │ ├── glfw3.h │ │ │ └── glfw3native.h │ └── src │ │ ├── CMakeLists.txt │ │ ├── cocoa_init.m │ │ ├── cocoa_joystick.h │ │ ├── cocoa_joystick.m │ │ ├── cocoa_monitor.m │ │ ├── cocoa_platform.h │ │ ├── cocoa_time.c │ │ ├── cocoa_window.m │ │ ├── context.c │ │ ├── egl_context.c │ │ ├── egl_context.h │ │ ├── glfw3.pc.in │ │ ├── glfw3Config.cmake.in │ │ ├── glfw_config.h.in │ │ ├── glx_context.c │ │ ├── glx_context.h │ │ ├── init.c │ │ ├── input.c │ │ ├── internal.h │ │ ├── linux_joystick.c │ │ ├── linux_joystick.h │ │ ├── mappings.h │ │ ├── mappings.h.in │ │ ├── monitor.c │ │ ├── nsgl_context.h │ │ ├── nsgl_context.m │ │ ├── null_init.c │ │ ├── null_joystick.c │ │ ├── null_joystick.h │ │ ├── null_monitor.c │ │ ├── null_platform.h │ │ ├── null_window.c │ │ ├── osmesa_context.c │ │ ├── osmesa_context.h │ │ ├── posix_thread.c │ │ ├── posix_thread.h │ │ ├── posix_time.c │ │ ├── posix_time.h │ │ ├── vulkan.c │ │ ├── wgl_context.c │ │ ├── wgl_context.h │ │ ├── win32_init.c │ │ ├── win32_joystick.c │ │ ├── win32_joystick.h │ │ ├── win32_monitor.c │ │ ├── win32_platform.h │ │ ├── win32_thread.c │ │ ├── win32_time.c │ │ ├── win32_window.c │ │ ├── window.c │ │ ├── wl_init.c │ │ ├── wl_monitor.c │ │ ├── wl_platform.h │ │ ├── wl_window.c │ │ ├── x11_init.c │ │ ├── x11_monitor.c │ │ ├── x11_platform.h │ │ ├── x11_window.c │ │ ├── xkb_unicode.c │ │ └── xkb_unicode.h └── onefile │ ├── GLAD │ ├── gl.c │ ├── gl.h │ ├── glx.c │ └── glx.h │ └── stb │ ├── image.c │ ├── image.h │ ├── rect_pack.c │ ├── rect_pack.h │ ├── truetype.c │ └── truetype.h ├── libbuild.zig └── src ├── alka.zig ├── assetmanager.zig ├── core ├── audio │ └── audio.zig ├── c.zig ├── core.zig ├── ecs.zig ├── fs.zig ├── gl.zig ├── glfw.zig ├── input.zig ├── log.zig ├── math │ ├── common.zig │ ├── mat4x4.zig │ ├── math.zig │ ├── vec2.zig │ └── vec3.zig ├── private.c ├── renderer.zig ├── utf8.zig ├── utils.zig └── window.zig ├── gui.zig ├── main.zig ├── private.zig └── run.sh /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | zig-cache 3 | zig-out 4 | vscode 5 | build_runner.zig 6 | src/.vscode 7 | .ccls-cache/ 8 | kiragine.log 9 | .vscode/settings.json 10 | actual-testbuf 11 | testbuf 12 | out.png 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | ----------------------------------------- 2 | | Alka 1.0.2 | 3 | ----------------------------------------- 4 | 5 | Copyright © 2020-2021 Mehmet Kaan Uluç 6 | 7 | This software is provided 'as-is', without any express or implied 8 | warranty. In no event will the authors be held liable for any damages 9 | arising from the use of this software. 10 | 11 | Permission is granted to anyone to use this software for any purpose, 12 | including commercial applications, and to alter it and redistribute it 13 | freely, subject to the following restrictions: 14 | 15 | 1. The origin of this software must not be misrepresented; you must not 16 | claim that you wrote the original software. If you use this software 17 | in a product, an acknowledgment in the product documentation would 18 | be appreciated but is not required. 19 | 20 | 2. Altered source versions must be plainly marked as such, and must not 21 | be misrepresented as being the original software. 22 | 23 | 3. This notice may not be removed or altered from any source 24 | distribution. 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Alka 2 | Game engine written in zig, compatible with **zig version 0.8.0**. 3 | 4 | This engine does provide a toolset for you but generally you have to implement how they work and how should be. 5 | 6 | For example if you want to use `GUI`, well you can and engine provides a tool for you but you have to implement how 7 | `elements` behave, draw, etc. There is no `ButtonElement` or `TextBox`, only `Element`. Same goes for the `ECS` too. 8 | 9 | ----- 10 | You may need these packages to compile the engine(tested on ubuntu 21.04) 11 | `libx11-dev libxcursor-dev libxrandr-dev libxinerama-dev libxi-dev libgl-dev` 12 | 13 | Get started [now](https://github.com/Kiakra/Alka/blob/master/get-started.md) 14 | 15 | [Documentation]() 16 | 17 | ----- 18 | ## Project goals 19 | - [x] Single window operations 20 | - [x] Input management 21 | - [x] Asset manager 22 | - [x] Custom batch system 23 | - [x] 2D Camera 24 | - [X] 2D Shape drawing 25 | - [x] 2D Texture drawing 26 | - [x] 2D Text drawing 27 | - [x] Simple ecs 28 | - [ ] Simple 2D lightning 29 | - [ ] Simple 2D physics 30 | - [x] GUI system 31 | - [ ] Audio 32 | - [ ] Optional: Data packer 33 | - [ ] Optional: Scripting language 34 | - [ ] Optional: Vulkan implementation 35 | - [ ] Optional: Android support 36 | 37 | ---- 38 | ## About release cycle 39 | * Versioning: major.minor.patch 40 | * Every x.x.3 creates a new minor, which becomes x.(x + 1).0 41 | * Again every x.3.x creates a new major, which becomes (x + 1).0.x 42 | * When a new version comes, it'll comitted as x.x.x source update 43 | -------------------------------------------------------------------------------- /assets/arial.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/assets/arial.ttf -------------------------------------------------------------------------------- /assets/embed/texture.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | out vec4 final; 4 | in vec2 ourTexCoord; 5 | in vec4 ourColour; 6 | uniform sampler2D uTexture; 7 | 8 | void main() { 9 | vec4 texelColour = texture(uTexture, ourTexCoord); 10 | final = ourColour * texelColour; 11 | } 12 | -------------------------------------------------------------------------------- /assets/embed/texture.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | layout (location = 0) in vec2 aPos; 3 | layout (location = 1) in vec2 aTexCoord; 4 | layout (location = 2) in vec4 aColour; 5 | 6 | out vec2 ourTexCoord; 7 | out vec4 ourColour; 8 | uniform mat4 MVP; 9 | 10 | void main() { 11 | gl_Position = MVP * vec4(aPos.xy, 0.0, 1.0); 12 | ourTexCoord = aTexCoord; 13 | ourColour = aColour; 14 | } 15 | -------------------------------------------------------------------------------- /assets/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/assets/icon.png -------------------------------------------------------------------------------- /assets/test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/assets/test.png -------------------------------------------------------------------------------- /build.zig: -------------------------------------------------------------------------------- 1 | const Builder = @import("std").build.Builder; 2 | const Build = @import("std").build; 3 | 4 | const lib = @import("libbuild.zig"); 5 | 6 | pub fn build(b: *Builder) void { 7 | const target = b.standardTargetOptions(.{}); 8 | const mode = b.standardReleaseOptions(); 9 | 10 | const engine_path = "./"; 11 | 12 | lib.strip = b.option(bool, "strip", "Strip the exe?") orelse false; 13 | 14 | const examples = b.option(bool, "examples", "Compile the examples?") orelse false; 15 | const main = b.option(bool, "main", "Compile the main source?") orelse false; 16 | 17 | if (examples) { 18 | { 19 | const exe = lib.setup(b, target, "basic_setup", "examples/basic_setup.zig", engine_path); 20 | exe.setOutputDir("build"); 21 | exe.setBuildMode(mode); 22 | exe.install(); 23 | } 24 | 25 | { 26 | const exe = lib.setup(b, target, "input", "examples/input.zig", engine_path); 27 | exe.setOutputDir("build"); 28 | exe.setBuildMode(mode); 29 | exe.install(); 30 | } 31 | 32 | { 33 | const exe = lib.setup(b, target, "shape_drawing", "examples/shape_drawing.zig", engine_path); 34 | exe.setOutputDir("build"); 35 | exe.setBuildMode(mode); 36 | exe.install(); 37 | } 38 | 39 | { 40 | const exe = lib.setup(b, target, "texture_drawing", "examples/texture_drawing.zig", engine_path); 41 | exe.setOutputDir("build"); 42 | exe.setBuildMode(mode); 43 | exe.install(); 44 | } 45 | 46 | { 47 | const exe = lib.setup(b, target, "text_rendering", "examples/text_rendering.zig", engine_path); 48 | exe.setOutputDir("build"); 49 | exe.setBuildMode(mode); 50 | exe.install(); 51 | } 52 | 53 | { 54 | const exe = lib.setup(b, target, "ecs", "examples/ecs.zig", engine_path); 55 | exe.setOutputDir("build"); 56 | exe.setBuildMode(mode); 57 | exe.install(); 58 | } 59 | 60 | { 61 | const exe = lib.setup(b, target, "ecs_benchmark", "examples/ecs_benchmark.zig", engine_path); 62 | exe.setOutputDir("build"); 63 | exe.setBuildMode(mode); 64 | exe.install(); 65 | } 66 | 67 | { 68 | const exe = lib.setup(b, target, "camera2d", "examples/camera2d.zig", engine_path); 69 | exe.setOutputDir("build"); 70 | exe.setBuildMode(mode); 71 | exe.install(); 72 | } 73 | 74 | { 75 | const exe = lib.setup(b, target, "camera2d_advanced", "examples/camera2d_advanced.zig", engine_path); 76 | exe.setOutputDir("build"); 77 | exe.setBuildMode(mode); 78 | exe.install(); 79 | } 80 | 81 | { 82 | const exe = lib.setup(b, target, "gui", "examples/gui.zig", engine_path); 83 | exe.setOutputDir("build"); 84 | exe.setBuildMode(mode); 85 | exe.install(); 86 | } 87 | 88 | { 89 | const exe = lib.setup(b, target, "custombatch", "examples/custombatch.zig", engine_path); 90 | exe.setOutputDir("build"); 91 | exe.setBuildMode(mode); 92 | exe.install(); 93 | } 94 | 95 | { 96 | const exe = lib.setup(b, target, "customshaders", "examples/customshaders.zig", engine_path); 97 | exe.setOutputDir("build"); 98 | exe.setBuildMode(mode); 99 | exe.install(); 100 | } 101 | 102 | { 103 | const exe = lib.setup(b, target, "shooter", "examples/shooter.zig", engine_path); 104 | exe.setOutputDir("build"); 105 | exe.setBuildMode(mode); 106 | exe.install(); 107 | } 108 | } 109 | 110 | if (main) { 111 | const exe = b.addExecutable("main", "src/main.zig"); 112 | exe.strip = lib.strip; 113 | exe.linkSystemLibrary("c"); 114 | exe.addIncludeDir(engine_path ++ "include/onefile/"); 115 | 116 | lib.include(exe, engine_path); 117 | lib.compileOneFile(exe, engine_path); 118 | 119 | const target_os = target.getOsTag(); 120 | switch (target_os) { 121 | .windows => { 122 | exe.setTarget(target); 123 | 124 | exe.linkSystemLibrary("gdi32"); 125 | exe.linkSystemLibrary("opengl32"); 126 | 127 | exe.subsystem = .Console; 128 | 129 | lib.compileGLFWWin32(exe, engine_path); 130 | }, 131 | .linux => { 132 | exe.setTarget(target); 133 | exe.linkSystemLibrary("X11"); 134 | 135 | lib.compileGLFWLinux(exe, engine_path); 136 | }, 137 | else => {}, 138 | } 139 | 140 | lib.compileGLFWShared(exe, engine_path); 141 | exe.setOutputDir("build"); 142 | exe.setBuildMode(mode); 143 | exe.install(); 144 | 145 | const run_cmd = exe.run(); 146 | run_cmd.step.dependOn(b.getInstallStep()); 147 | if (b.args) |args| { 148 | run_cmd.addArgs(args); 149 | } 150 | 151 | const run_step = b.step("run", "Run the app"); 152 | run_step.dependOn(&run_cmd.step); 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /examples/basic_setup.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const alka = @import("alka"); 3 | 4 | usingnamespace alka.log; 5 | 6 | pub const mlog = std.log.scoped(.app); 7 | pub const log_level: std.log.Level = .info; 8 | 9 | const virtualwidth: i32 = 1024; 10 | const virtualheight: i32 = 768; 11 | 12 | fn update(dt: f32) !void { 13 | mlog.notice("update", .{}); 14 | } 15 | 16 | fn fupdate(dt: f32) !void { 17 | mlog.notice("fixed update", .{}); 18 | } 19 | 20 | fn draw() !void { 21 | mlog.notice("draw", .{}); 22 | } 23 | 24 | // cannot let out error, it's a C callback 25 | fn resize(w: i32, h: i32) void { 26 | mlog.notice("resize", .{}); 27 | alka.autoResize(virtualwidth, virtualheight, w, h); 28 | } 29 | 30 | // cannot let out error, it's a C callback 31 | fn close() void { 32 | mlog.notice("close", .{}); 33 | } 34 | 35 | pub fn main() !void { 36 | var gpa = std.heap.GeneralPurposeAllocator(.{}){}; 37 | 38 | const callbacks = alka.Callbacks{ 39 | .update = update, 40 | .fixed = fupdate, 41 | .draw = draw, 42 | .resize = resize, 43 | .close = close, 44 | }; 45 | 46 | // .. fpslimit if zero vsync=on, is resizable? 47 | try alka.init(&gpa.allocator, callbacks, 1024, 768, "Basic Setup", 0, true); 48 | alka.autoResize(virtualwidth, virtualheight, 1024, 768); 49 | 50 | // opens the window 51 | try alka.open(); 52 | // runs the loop 53 | try alka.update(); 54 | // closes the window 55 | try alka.close(); 56 | 57 | try alka.deinit(); 58 | 59 | const leaked = gpa.deinit(); 60 | if (leaked) return error.Leak; 61 | } 62 | -------------------------------------------------------------------------------- /examples/camera2d.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const alka = @import("alka"); 3 | 4 | const m = alka.math; 5 | usingnamespace alka.log; 6 | 7 | pub const mlog = std.log.scoped(.app); 8 | pub const log_level: std.log.Level = .info; 9 | 10 | fn fupdate(dt: f32) !void { 11 | alka.getCamera2DPtr().offset.x += 100 * dt; 12 | } 13 | 14 | fn draw() !void { 15 | const r = m.Rectangle{ .position = m.Vec2f{ .x = 100.0, .y = 200.0 }, .size = m.Vec2f{ .x = 50.0, .y = 50.0 } }; 16 | const col = alka.Colour{ .r = 1, .g = 1, .b = 1, .a = 1 }; 17 | try alka.drawRectangleAdv(r, m.Vec2f{ .x = 25, .y = 25 }, m.deg2radf(45), col); 18 | 19 | const r2 = m.Rectangle{ .position = m.Vec2f{ .x = 200.0, .y = 200.0 }, .size = m.Vec2f{ .x = 30.0, .y = 30.0 } }; 20 | const col2 = alka.Colour.rgba(30, 80, 200, 255); 21 | try alka.drawRectangle(r2, col2); 22 | } 23 | 24 | pub fn main() !void { 25 | var gpa = std.heap.GeneralPurposeAllocator(.{}){}; 26 | 27 | const callbacks = alka.Callbacks{ 28 | .update = null, 29 | .fixed = fupdate, 30 | .draw = draw, 31 | .resize = null, 32 | .close = null, 33 | }; 34 | 35 | try alka.init(&gpa.allocator, callbacks, 1024, 768, "Camera 2D", 0, false); 36 | 37 | try alka.open(); 38 | try alka.update(); 39 | try alka.close(); 40 | 41 | try alka.deinit(); 42 | 43 | const leaked = gpa.deinit(); 44 | if (leaked) return error.Leak; 45 | } 46 | -------------------------------------------------------------------------------- /examples/camera2d_advanced.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const alka = @import("alka"); 3 | 4 | const m = alka.math; 5 | usingnamespace alka.log; 6 | 7 | pub const mlog = std.log.scoped(.app); 8 | pub const log_level: std.log.Level = .info; 9 | 10 | var defcam = m.Camera2D{}; 11 | 12 | fn fupdate(dt: f32) !void { 13 | alka.getCamera2DPtr().offset.x += 100 * dt; 14 | } 15 | 16 | fn draw() !void { 17 | // this will use the default camera 18 | const r = m.Rectangle{ .position = m.Vec2f{ .x = 100.0, .y = 200.0 }, .size = m.Vec2f{ .x = 50.0, .y = 50.0 } }; 19 | const col = alka.Colour{ .r = 1, .g = 1, .b = 1, .a = 1 }; 20 | try alka.drawRectangleAdv(r, m.Vec2f{ .x = 25, .y = 25 }, m.deg2radf(45), col); 21 | 22 | // but we need to render it so the batch can change the camera 23 | // well, the engine does not count the camera when drawing to into a batch 24 | // thats why we need to render the batch and clean it after 25 | const rbatch = try alka.getBatch(.triangles, 0, 0); 26 | try alka.renderBatch(rbatch); 27 | alka.cleanBatch(rbatch); 28 | 29 | // push the camera 30 | alka.pushCamera2D(defcam); 31 | defer alka.popCamera2D(); 32 | const r2 = m.Rectangle{ .position = m.Vec2f{ .x = 200.0, .y = 200.0 }, .size = m.Vec2f{ .x = 30.0, .y = 30.0 } }; 33 | const col2 = alka.Colour.rgba(30, 80, 200, 255); 34 | try alka.drawRectangle(r2, col2); 35 | } 36 | 37 | pub fn main() !void { 38 | var gpa = std.heap.GeneralPurposeAllocator(.{}){}; 39 | 40 | const callbacks = alka.Callbacks{ 41 | .update = null, 42 | .fixed = fupdate, 43 | .draw = draw, 44 | .resize = null, 45 | .close = null, 46 | }; 47 | 48 | try alka.init(&gpa.allocator, callbacks, 1024, 768, "Camera 2D Advanced", 0, false); 49 | 50 | defcam = alka.getCamera2D(); 51 | 52 | try alka.open(); 53 | try alka.update(); 54 | try alka.close(); 55 | 56 | try alka.deinit(); 57 | 58 | const leaked = gpa.deinit(); 59 | if (leaked) return error.Leak; 60 | } 61 | -------------------------------------------------------------------------------- /examples/custombatch.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const alka = @import("alka"); 3 | 4 | const m = alka.math; 5 | usingnamespace alka.log; 6 | 7 | pub const mlog = std.log.scoped(.app); 8 | pub const log_level: std.log.Level = .info; 9 | 10 | const vertex_shader = 11 | \\#version 330 core 12 | \\layout (location = 0) in vec2 aPos; 13 | \\layout (location = 1) in vec2 aTexCoord; 14 | \\layout (location = 2) in vec4 aColour; 15 | \\ 16 | \\out vec2 ourTexCoord; 17 | \\out vec4 ourColour; 18 | \\uniform mat4 view; 19 | \\ 20 | \\void main() { 21 | \\ gl_Position = view * vec4(aPos.xy, 0.0, 1.0); 22 | \\ ourTexCoord = aTexCoord; 23 | \\ ourColour = aColour; 24 | \\} 25 | ; 26 | 27 | const fragment_shader = 28 | \\#version 330 core 29 | \\out vec4 final; 30 | \\in vec2 ourTexCoord; 31 | \\in vec4 ourColour; 32 | \\uniform sampler2D uTexture; 33 | \\ 34 | \\void main() { 35 | \\ vec4 texelColour = texture(uTexture, ourTexCoord); 36 | \\ final = vec4(1, 0, 0, 1) * texelColour; // everything is red 37 | \\} 38 | ; 39 | 40 | fn batchDraw(corebatch: alka.Batch2DQuad, mode: alka.gl.DrawMode, shader: *u32, texture: *alka.renderer.Texture, cam2d: *m.Camera2D) alka.Error!void { 41 | cam2d.attach(); 42 | defer cam2d.detach(); 43 | 44 | alka.gl.shaderProgramUse(shader.*); 45 | defer alka.gl.shaderProgramUse(0); 46 | 47 | alka.gl.textureActive(.texture0); 48 | alka.gl.textureBind(.t2D, texture.id); 49 | defer alka.gl.textureBind(.t2D, 0); 50 | 51 | const mvploc = alka.gl.shaderProgramGetUniformLocation(shader.*, "view"); 52 | alka.gl.shaderProgramSetMat4x4f(mvploc, cam2d.view); 53 | 54 | try corebatch.draw(mode); 55 | } 56 | 57 | fn draw() !void { 58 | const asset = alka.getAssetManager(); 59 | 60 | // create the batch 61 | // NOTE: if the batch exists, it won't create one, instead returns the existing batch 62 | // drawmode, shader_id, texture_id 63 | var batch = try alka.createBatch(alka.gl.DrawMode.triangles, 1, 0); 64 | // this way we can change how we draw the batch 65 | // if not used, it'll draw the defaultbatch 66 | // which stored at: `Batch.drawDefault` 67 | batch.drawfun = batchDraw; 68 | alka.setBatchFun(batch); 69 | 70 | // there is also 71 | 72 | // usefull when using non-assetmanager loaded shaders and textures 73 | // createBatchNoID(mode: gl.DrawMode, sh: u32, texture: renderer.Texture) Error!Batch 74 | // 75 | // every draw call will create batches even if you don't create one explicitly 76 | // this is usefull in case you need to explicitly use auto-gen batchs 77 | // getBatch(mode: gl.DrawMode, sh_id: u64, texture_id: u64) Error!Batch 78 | // 79 | // usefull when using non-assetmanager loaded shaders and textures 80 | // getBatchNoID(mode: gl.DrawMode, sh: u32, texture: renderer.Texture) Error!Batch 81 | // 82 | // explicitly renders the batch, does not clean the batch tho 83 | // so you need to use cleanBatch() if you don't want to end up with 84 | // 2x draw call 85 | // renderBatch(batch: Batch) Error!void 86 | // 87 | // explicitly clears the batch 88 | // cleanBatch(batch: Batch) void 89 | 90 | // push the batch 91 | try alka.pushBatch(batch); 92 | { 93 | const r = m.Rectangle{ .position = m.Vec2f{ .x = 100.0, .y = 200.0 }, .size = m.Vec2f{ .x = 50.0, .y = 50.0 } }; 94 | const col = alka.Colour{ .r = 1, .g = 1, .b = 1, .a = 1 }; 95 | try alka.drawRectangleAdv(r, m.Vec2f{ .x = 25, .y = 25 }, m.deg2radf(45), col); 96 | 97 | // custom batch forces to use drawmode: triangles, so it'll be corrupted rectangle 98 | //try alka.drawRectangleLinesAdv(r, m.Vec2f{ .x = 25, .y = 25 }, m.deg2radf(45), col); 99 | 100 | // there is also a 2dcamera in unique to every batch, 101 | // the alka.getCamera2D() is the global camera which every batch defaults for, every frame 102 | batch.cam2d.zoom.x = 0.5; 103 | batch.cam2d.zoom.y = 0.5; 104 | } 105 | // pop the batch 106 | alka.popBatch(); 107 | 108 | const r2 = m.Rectangle{ .position = m.Vec2f{ .x = 200.0, .y = 200.0 }, .size = m.Vec2f{ .x = 30.0, .y = 30.0 } }; 109 | const col2 = alka.Colour.rgba(30, 80, 200, 255); 110 | try alka.drawRectangle(r2, col2); 111 | } 112 | 113 | pub fn main() !void { 114 | var gpa = std.heap.GeneralPurposeAllocator(.{}){}; 115 | 116 | const callbacks = alka.Callbacks{ 117 | .update = null, 118 | .fixed = null, 119 | .draw = draw, 120 | .resize = null, 121 | .close = null, 122 | }; 123 | 124 | try alka.init(&gpa.allocator, callbacks, 1024, 768, "Custom batch", 0, false); 125 | 126 | try alka.getAssetManager().loadShader(1, vertex_shader, fragment_shader); 127 | 128 | try alka.open(); 129 | try alka.update(); 130 | try alka.close(); 131 | 132 | try alka.deinit(); 133 | 134 | const leaked = gpa.deinit(); 135 | if (leaked) return error.Leak; 136 | } 137 | -------------------------------------------------------------------------------- /examples/customshaders.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const alka = @import("alka"); 3 | 4 | const m = alka.math; 5 | usingnamespace alka.log; 6 | 7 | pub const mlog = std.log.scoped(.app); 8 | pub const log_level: std.log.Level = .info; 9 | 10 | const vertex_shader = 11 | \\#version 330 core 12 | \\layout (location = 0) in vec2 aPos; 13 | \\layout (location = 1) in vec2 aTexCoord; 14 | \\layout (location = 2) in vec4 aColour; 15 | \\ 16 | \\out vec2 ourTexCoord; 17 | \\out vec4 ourColour; 18 | \\uniform mat4 view; 19 | \\ 20 | \\void main() { 21 | \\ gl_Position = view * vec4(aPos.xy, 0.0, 1.0); 22 | \\ ourTexCoord = aTexCoord; 23 | \\ ourColour = aColour; 24 | \\} 25 | ; 26 | 27 | const fragment_shader = 28 | \\#version 330 core 29 | \\out vec4 final; 30 | \\in vec2 ourTexCoord; 31 | \\in vec4 ourColour; 32 | \\uniform sampler2D uTexture; 33 | \\ 34 | \\void main() { 35 | \\ vec4 texelColour = texture(uTexture, ourTexCoord); 36 | \\ final = vec4(1, 0, 0, 1) * texelColour; // everything is red 37 | \\} 38 | ; 39 | 40 | fn draw() !void { 41 | // push the shader 42 | // id 43 | try alka.pushShader(1); 44 | 45 | const r = m.Rectangle{ .position = m.Vec2f{ .x = 100.0, .y = 200.0 }, .size = m.Vec2f{ .x = 50.0, .y = 50.0 } }; 46 | const col = alka.Colour{ .r = 1, .g = 1, .b = 1, .a = 1 }; 47 | //try alka.drawRectangleAdv(r, m.Vec2f{ .x = 25, .y = 25 }, m.deg2radf(45), col); 48 | try alka.drawRectangleLinesAdv(r, m.Vec2f{ .x = 25, .y = 25 }, m.deg2radf(125), col); 49 | 50 | const r2 = m.Rectangle{ .position = m.Vec2f{ .x = 200.0, .y = 200.0 }, .size = m.Vec2f{ .x = 30.0, .y = 30.0 } }; 51 | const col2 = alka.Colour.rgba(30, 80, 200, 255); 52 | //try alka.drawRectangle(r2, col2); 53 | try alka.drawRectangleLines(r2, col2); 54 | 55 | // pops the pushed shader 56 | alka.popShader(); 57 | 58 | // position, radius, colour 59 | // segment count is 16 by default 60 | //try alka.drawCircleLines(m.Vec2f{ .x = 350, .y = 260 }, 24, col); 61 | //try alka.drawCircle(m.Vec2f{ .x = 450, .y = 260 }, 24, col); 62 | // position, radius, segment count, startangle, endangle, colour 63 | try alka.drawCircleLinesAdv(m.Vec2f{ .x = 350, .y = 260 }, 24, 8, 0, 360, col); 64 | 65 | try alka.drawCircleLinesAdv(m.Vec2f{ .x = 350, .y = 360 }, 24, 32, 0, 360, col); 66 | 67 | try alka.drawCircleAdv(m.Vec2f{ .x = 450, .y = 260 }, 24, 32, 0, 360, col); 68 | try alka.drawCircleAdv(m.Vec2f{ .x = 450, .y = 360 }, 24, 8, 0, 360, col); 69 | 70 | // start, end, thickness, colour 71 | try alka.drawLine(m.Vec2f{ .x = 300, .y = 300 }, m.Vec2f{ .x = 400, .y = 350 }, 1, col); 72 | 73 | var i: f32 = 0; 74 | while (i < 10) : (i += 2) { 75 | try alka.drawPixel(m.Vec2f{ .x = 300 + i, .y = 400 }, col); 76 | } 77 | } 78 | 79 | pub fn main() !void { 80 | var gpa = std.heap.GeneralPurposeAllocator(.{}){}; 81 | 82 | const callbacks = alka.Callbacks{ 83 | .update = null, 84 | .fixed = null, 85 | .draw = draw, 86 | .resize = null, 87 | .close = null, 88 | }; 89 | 90 | try alka.init(&gpa.allocator, callbacks, 1024, 768, "Custom Shaders", 0, false); 91 | 92 | try alka.getAssetManager().loadShader(1, vertex_shader, fragment_shader); 93 | 94 | try alka.open(); 95 | try alka.update(); 96 | try alka.close(); 97 | 98 | try alka.deinit(); 99 | 100 | const leaked = gpa.deinit(); 101 | if (leaked) return error.Leak; 102 | } 103 | -------------------------------------------------------------------------------- /examples/ecs.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const alka = @import("alka"); 3 | const m = alka.math; 4 | 5 | usingnamespace alka.log; 6 | pub const mlog = std.log.scoped(.app); 7 | pub const log_level: std.log.Level = .debug; 8 | 9 | pub fn main() !void { 10 | var gpa = std.heap.GeneralPurposeAllocator(.{ 11 | .enable_memory_limit = true, 12 | }){}; 13 | gpa.setRequestedMemoryLimit(1048 * 100 * 100 * 2); 14 | 15 | const maxent = 1024; 16 | 17 | const PositionStore = alka.ecs.StoreComponent("Position", m.Vec2f, maxent); 18 | const SizeStore = alka.ecs.StoreComponent("Size", m.Vec3f, maxent); 19 | const TitleStore = alka.ecs.StoreComponent("Title", []const u8, maxent); 20 | const World = alka.ecs.World(struct { p: PositionStore, s: SizeStore, t: TitleStore }); 21 | 22 | { 23 | var world = try World.init(&gpa.allocator); 24 | defer world.deinit(); 25 | 26 | var reg = try world.createRegister(0); 27 | defer world.removeRegister(reg.id) catch unreachable; 28 | 29 | try reg.create(); 30 | defer reg.destroy(); 31 | 32 | try reg.attach("Position", m.Vec2f{ .x = 20 }); 33 | try reg.attach("Size", m.Vec3f{ .x = 20 }); 34 | 35 | var pos = try reg.getPtr("Position", m.Vec2f); 36 | pos.y = 26; 37 | 38 | //try reg.detach("Position"); 39 | //try reg.attach("Position", m.Vec2f{ .x = 20 }); 40 | 41 | mlog.notice("pos: {s}", .{try reg.get("Position", m.Vec2f)}); 42 | 43 | const comps = [_][]const u8{ "Position", "Size" }; 44 | mlog.err("{}", .{reg.hasThese(comps.len, comps)}); 45 | 46 | var it = World.iterator(comps.len, comps){ .world = &world }; 47 | 48 | while (it.next()) |entry| { 49 | if (entry.value) |entity| 50 | mlog.notice("entity: {}", .{entity}); 51 | } 52 | } 53 | 54 | const leaked = gpa.deinit(); 55 | if (leaked) return error.Leak; 56 | } 57 | -------------------------------------------------------------------------------- /examples/ecs_benchmark.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const alka = @import("alka"); 3 | const m = alka.math; 4 | 5 | usingnamespace alka.log; 6 | pub const mlog = std.log.scoped(.app); 7 | pub const log_level: std.log.Level = .debug; 8 | 9 | const RectangleStore = alka.ecs.StoreComponent("Rectangle", m.Rectangle, maxent); 10 | const SpeedStore = alka.ecs.StoreComponent("Speed", f32, maxent); 11 | const VelocityStore = alka.ecs.StoreComponent("Velocity", m.Vec2f, maxent); 12 | const ColourStore = alka.ecs.StoreComponent("Colour", alka.Colour, maxent); 13 | const World = alka.ecs.World(struct { r: RectangleStore, col: ColourStore, sp: SpeedStore, vl: VelocityStore }); 14 | 15 | const maxent: u64 = 1024 * 100; 16 | var random: *std.rand.Random = undefined; 17 | 18 | var world: World = undefined; 19 | 20 | var mouseleftPtr: *const alka.input.State = undefined; 21 | var index: u64 = 0; 22 | 23 | fn createEntity(i: u64) !void { 24 | var reg = try world.createRegister(i); 25 | try reg.create(); 26 | 27 | try reg.attach("Rectangle", m.Rectangle{ 28 | .position = alka.getMousePosition(), 29 | .size = m.Vec2f{ 30 | .x = @intToFloat(f32, random.intRangeAtMost(i32, 10, 50)), 31 | .y = @intToFloat(f32, random.intRangeAtMost(i32, 10, 50)), 32 | }, 33 | }); 34 | 35 | const speed: f32 = 200 * @intToFloat(f32, random.intRangeAtMost(i32, -1, 1)); 36 | try reg.attach("Speed", speed); 37 | 38 | try reg.attach("Velocity", m.Vec2f{}); 39 | 40 | try reg.attach("Colour", alka.Colour.rgba(random.intRangeAtMost(u8, 0, 200), random.intRangeAtMost(u8, 0, 200), random.intRangeAtMost(u8, 0, 200), 255)); 41 | //mlog.info("created {}", .{i}); 42 | } 43 | 44 | fn update(dt: f32) !void { 45 | if (mouseleftPtr.* == alka.input.State.down) { 46 | if (index < maxent) { 47 | var i: u64 = index; 48 | while (i < index + 10) : (i += 1) { 49 | try createEntity(i); 50 | } 51 | index = i; 52 | } 53 | } 54 | 55 | const comps = [_][]const u8{ "Velocity", "Speed", "Rectangle" }; 56 | 57 | var it = World.iterator(comps.len, comps){ .world = &world }; 58 | while (it.next()) |entry| { 59 | if (entry.value) |entity| { 60 | var vel = try entity.getPtr("Velocity", m.Vec2f); 61 | var speed = try entity.getPtr("Speed", f32); 62 | const rect = try entity.get("Rectangle", m.Rectangle); 63 | 64 | if (rect.position.x > 1024 - rect.size.x) { 65 | speed.* = -speed.*; 66 | } else if (rect.position.x < 0) { 67 | speed.* = m.abs(speed.*); 68 | } 69 | 70 | vel.x += speed.* * dt; 71 | } 72 | } 73 | } 74 | 75 | fn fupdate(dt: f32) !void { 76 | const comps = [_][]const u8{ "Velocity", "Rectangle" }; 77 | 78 | var it = World.iterator(comps.len, comps){ .world = &world }; 79 | while (it.next()) |entry| { 80 | if (entry.value) |entity| { 81 | var rect = try entity.getPtr("Rectangle", m.Rectangle); 82 | var vel = try entity.getPtr("Velocity", m.Vec2f); 83 | 84 | rect.position.x += vel.x; 85 | vel.* = m.Vec2f{}; 86 | } 87 | } 88 | } 89 | 90 | fn draw() !void { 91 | const comps = [_][]const u8{ "Rectangle", "Colour" }; 92 | 93 | var it = World.iterator(comps.len, comps){ .world = &world }; 94 | 95 | while (it.next()) |entry| { 96 | if (entry.value) |entity| { 97 | const rect = try entity.get("Rectangle", m.Rectangle); 98 | const colour = try entity.get("Colour", alka.Colour); 99 | 100 | try alka.drawRectangle(rect, colour); 101 | } 102 | } 103 | 104 | const asset = alka.getAssetManager(); 105 | const font = try asset.getFont(0); 106 | 107 | const col = alka.Colour.rgba(200, 30, 70, 255); 108 | 109 | var debug = try alka.getDebug(); 110 | defer alka.getAllocator().free(debug); 111 | 112 | try alka.drawText(0, debug, m.Vec2f{ .x = 20, .y = 20 }, 24, col); 113 | mlog.info("{s}", .{debug}); 114 | 115 | debug = try std.fmt.bufPrint(debug, "total: {}", .{index}); 116 | try alka.drawText(0, debug, m.Vec2f{ .x = 20, .y = 45 }, 24, col); 117 | mlog.info("{s}", .{debug}); 118 | } 119 | 120 | pub fn main() !void { 121 | var gpa = std.heap.GeneralPurposeAllocator(.{ 122 | .enable_memory_limit = false, 123 | }){}; 124 | //gpa.setRequestedMemoryLimit(1048 * 1000 * 5); 125 | 126 | const callbacks = alka.Callbacks{ 127 | .update = update, 128 | .fixed = fupdate, 129 | .draw = draw, 130 | }; 131 | 132 | try alka.init(&gpa.allocator, callbacks, 1024, 768, "ECS Benchmark", 1000, false); 133 | 134 | var prng = std.rand.DefaultPrng.init(blk: { 135 | var seed: u64 = undefined; 136 | try std.os.getrandom(std.mem.asBytes(&seed)); 137 | break :blk seed; 138 | }); 139 | random = &prng.random; 140 | 141 | var input = alka.getInput(); 142 | try input.bindMouse(alka.input.Mouse.ButtonLeft); 143 | mouseleftPtr = try input.mouseStatePtr(alka.input.Mouse.ButtonLeft); 144 | 145 | try alka.getAssetManager().loadFont(0, "assets/arial.ttf", 128); 146 | const font = try alka.getAssetManager().getFont(0); 147 | font.texture.setFilter(alka.gl.TextureParamater.filter_mipmap_nearest, alka.gl.TextureParamater.filter_linear); 148 | 149 | world = try World.init(&gpa.allocator); 150 | 151 | try alka.open(); 152 | try alka.update(); 153 | try alka.close(); 154 | 155 | world.deinit(); 156 | 157 | try alka.deinit(); 158 | 159 | const leaked = gpa.deinit(); 160 | if (leaked) return error.Leak; 161 | } 162 | -------------------------------------------------------------------------------- /examples/example_shooter_game/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | zig-cache 3 | zig-out 4 | vscode 5 | build_runner.zig 6 | src/.vscode 7 | .ccls-cache/ 8 | kiragine.log 9 | .vscode/settings.json 10 | actual-testbuf 11 | testbuf 12 | out.png 13 | -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/VCR_OSD_MONO.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/VCR_OSD_MONO.ttf -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/effect_purple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/effect_purple.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/effect_yellow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/effect_yellow.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/enemy_A.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/enemy_A.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/enemy_B.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/enemy_B.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/enemy_C.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/enemy_C.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/enemy_D.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/enemy_D.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/enemy_E.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/enemy_E.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/icon_crossLarge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/icon_crossLarge.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/icon_crossSmall.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/icon_crossSmall.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/icon_exclamationLarge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/icon_exclamationLarge.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/icon_exclamationSmall.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/icon_exclamationSmall.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/icon_plusLarge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/icon_plusLarge.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/icon_plusSmall.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/icon_plusSmall.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/meteor_detailedLarge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/meteor_detailedLarge.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/meteor_detailedSmall.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/meteor_detailedSmall.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/meteor_large.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/meteor_large.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/meteor_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/meteor_small.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/meteor_squareDetailedLarge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/meteor_squareDetailedLarge.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/meteor_squareDetailedSmall.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/meteor_squareDetailedSmall.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/meteor_squareLarge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/meteor_squareLarge.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/meteor_squareSmall.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/meteor_squareSmall.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/satellite_A.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/satellite_A.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/satellite_B.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/satellite_B.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/satellite_C.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/satellite_C.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/satellite_D.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/satellite_D.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/ship_A.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/ship_A.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/ship_B.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/ship_B.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/ship_C.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/ship_C.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/ship_D.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/ship_D.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/ship_E.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/ship_E.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/ship_F.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/ship_F.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/ship_G.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/ship_G.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/ship_H.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/ship_H.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/ship_I.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/ship_I.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/ship_J.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/ship_J.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/ship_K.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/ship_K.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/ship_L.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/ship_L.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/ship_sidesA.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/ship_sidesA.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/ship_sidesB.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/ship_sidesB.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/ship_sidesC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/ship_sidesC.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/ship_sidesD.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/ship_sidesD.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/star_large.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/star_large.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/star_medium.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/star_medium.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/star_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/star_small.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/star_tiny.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/star_tiny.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/station_A.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/station_A.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/station_B.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/station_B.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/kenney_simplespace/station_C.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/kenney_simplespace/station_C.png -------------------------------------------------------------------------------- /examples/example_shooter_game/assets/station_heart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MeKaLu/Alka/d368c6bf8735392c724565e1dee760e91873ae00/examples/example_shooter_game/assets/station_heart.png -------------------------------------------------------------------------------- /examples/example_shooter_game/build.zig: -------------------------------------------------------------------------------- 1 | const Builder = @import("std").build.Builder; 2 | const lib = @import("libbuild.zig"); 3 | 4 | pub fn build(b: *Builder) void { 5 | const target = b.standardTargetOptions(.{}); 6 | const mode = b.standardReleaseOptions(); 7 | 8 | lib.strip = b.option(bool, "strip", "Strip the exe?") orelse false; 9 | 10 | const exe = lib.setup(b, target, "app", "src/main.zig", "../../"); 11 | exe.setOutputDir("build"); 12 | exe.setBuildMode(mode); 13 | exe.install(); 14 | 15 | const run_cmd = exe.run(); 16 | run_cmd.step.dependOn(b.getInstallStep()); 17 | if (b.args) |args| { 18 | run_cmd.addArgs(args); 19 | } 20 | 21 | const run_step = b.step("run", "Run the app"); 22 | run_step.dependOn(&run_cmd.step); 23 | } 24 | -------------------------------------------------------------------------------- /examples/example_shooter_game/libbuild.zig: -------------------------------------------------------------------------------- 1 | // ----------------------------------------- 2 | // | Alka 1.0.0 | 3 | // ----------------------------------------- 4 | // 5 | //Copyright © 2020-2021 Mehmet Kaan Uluç 6 | // 7 | //This software is provided 'as-is', without any express or implied 8 | //warranty. In no event will the authors be held liable for any damages 9 | //arising from the use of this software. 10 | // 11 | //Permission is granted to anyone to use this software for any purpose, 12 | //including commercial applications, and to alter it and redistribute it 13 | //freely, subject to the following restrictions: 14 | // 15 | //1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | //2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | //3. This notice may not be removed or altered from any source 24 | // distribution. 25 | 26 | const std = @import("std"); 27 | const Builder = @import("std").build.Builder; 28 | const Build = @import("std").build; 29 | const Builtin = @import("std").builtin; 30 | const Zig = @import("std").zig; 31 | 32 | const globalflags = [_][]const u8{"-std=c99"}; 33 | 34 | pub var strip = false; 35 | 36 | pub fn compileGLFWWin32(exe: *Build.LibExeObjStep, comptime engine_path: []const u8) void { 37 | const flags = [_][]const u8{"-O2"} ++ globalflags; 38 | exe.linkSystemLibrary("gdi32"); 39 | exe.linkSystemLibrary("opengl32"); 40 | 41 | exe.defineCMacro("_GLFW_WIN32"); 42 | 43 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/wgl_context.c", &flags); 44 | 45 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/win32_init.c", &flags); 46 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/win32_joystick.c", &flags); 47 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/win32_monitor.c", &flags); 48 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/win32_thread.c", &flags); 49 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/win32_time.c", &flags); 50 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/win32_window.c", &flags); 51 | } 52 | 53 | pub fn compileGLFWLinux(exe: *Build.LibExeObjStep, comptime engine_path: []const u8) void { 54 | const flags = [_][]const u8{"-O2"} ++ globalflags; 55 | exe.linkSystemLibrary("X11"); 56 | 57 | exe.defineCMacro("_GLFW_X11"); 58 | 59 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/glx_context.c", &flags); 60 | 61 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/posix_thread.c", &flags); 62 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/posix_time.c", &flags); 63 | 64 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/x11_init.c", &flags); 65 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/x11_window.c", &flags); 66 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/x11_monitor.c", &flags); 67 | 68 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/xkb_unicode.c", &flags); 69 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/linux_joystick.c", &flags); 70 | } 71 | 72 | pub fn compileGLFWShared(exe: *Build.LibExeObjStep, comptime engine_path: []const u8) void { 73 | const flags = [_][]const u8{"-O2"} ++ globalflags; 74 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/init.c", &flags); 75 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/context.c", &flags); 76 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/input.c", &flags); 77 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/monitor.c", &flags); 78 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/window.c", &flags); 79 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/vulkan.c", &flags); 80 | 81 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/osmesa_context.c", &flags); 82 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/egl_context.c", &flags); 83 | } 84 | 85 | pub fn compileOneFile(exe: *Build.LibExeObjStep, comptime engine_path: []const u8) void { 86 | const flags = [_][]const u8{"-O3"} ++ globalflags; 87 | exe.addCSourceFile(engine_path ++ "include/onefile/GLAD/gl.c", &flags); 88 | exe.addCSourceFile(engine_path ++ "include/onefile/stb/image.c", &flags); 89 | exe.addCSourceFile(engine_path ++ "include/onefile/stb/rect_pack.c", &flags); 90 | exe.addCSourceFile(engine_path ++ "include/onefile/stb/truetype.c", &flags); 91 | exe.addCSourceFile(engine_path ++ "src/core/private.c", &flags); 92 | } 93 | 94 | pub fn include(exe: *Build.LibExeObjStep, comptime engine_path: []const u8) void { 95 | exe.addIncludeDir(engine_path ++ "include/glfw-3.3.4/include/"); 96 | exe.addIncludeDir(engine_path ++ "include/onefile/"); 97 | } 98 | 99 | pub fn setup(b: *Builder, target: Zig.CrossTarget, gamename: []const u8, gamepath: []const u8, comptime engine_path: []const u8) *Build.LibExeObjStep { 100 | const exe = b.addExecutable(gamename, gamepath); 101 | 102 | exe.addPackagePath("alka", engine_path ++ "src/alka.zig"); 103 | 104 | exe.strip = strip; 105 | exe.linkSystemLibrary("c"); 106 | 107 | include(exe, engine_path); 108 | 109 | compileOneFile(exe, engine_path); 110 | 111 | const target_os = target.getOsTag(); 112 | switch (target_os) { 113 | .windows => { 114 | exe.setTarget(target); 115 | 116 | exe.linkSystemLibrary("gdi32"); 117 | exe.linkSystemLibrary("opengl32"); 118 | 119 | exe.subsystem = .Console; 120 | 121 | compileGLFWWin32(exe, engine_path); 122 | }, 123 | .linux => { 124 | exe.setTarget(target); 125 | exe.linkSystemLibrary("X11"); 126 | 127 | compileGLFWLinux(exe, engine_path); 128 | }, 129 | else => {}, 130 | } 131 | 132 | compileGLFWShared(exe, engine_path); 133 | 134 | return exe; 135 | } 136 | -------------------------------------------------------------------------------- /examples/example_shooter_game/src/main.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const alka = @import("alka"); 3 | 4 | const gui = @import("gui.zig"); 5 | const game = @import("game.zig"); 6 | 7 | usingnamespace alka.log; 8 | 9 | pub const mlog = std.log.scoped(.app); 10 | pub const log_level: std.log.Level = .debug; 11 | 12 | pub fn main() !void { 13 | var gpa = std.heap.GeneralPurposeAllocator(.{}){}; 14 | 15 | const callbacks = alka.Callbacks{ 16 | .update = game.update, 17 | .fixed = game.fupdate, 18 | .draw = game.draw, 19 | .close = game.close, 20 | }; 21 | 22 | try alka.init(&gpa.allocator, callbacks, 1024, 768, "App", 0, false); 23 | alka.setBackgroundColour(0.18, 0.18, 0.18); 24 | 25 | { 26 | try alka.getAssetManager().loadTexture(1, "assets/kenney_simplespace/ship_F.png"); 27 | const texture = try alka.getAssetManager().getTexture(1); 28 | texture.setFilter(.filter_nearest, .filter_nearest); 29 | } 30 | 31 | { 32 | try alka.getAssetManager().loadTexture(2, "assets/kenney_simplespace/enemy_A.png"); 33 | const texture = try alka.getAssetManager().getTexture(2); 34 | texture.setFilter(.filter_nearest, .filter_nearest); 35 | } 36 | 37 | { 38 | try alka.getAssetManager().loadTexture(3, "assets/kenney_simplespace/station_B.png"); 39 | const texture = try alka.getAssetManager().getTexture(3); 40 | texture.setFilter(.filter_nearest, .filter_nearest); 41 | } 42 | 43 | { 44 | try alka.getAssetManager().loadTexture(10, "assets/station_heart.png"); 45 | const texture = try alka.getAssetManager().getTexture(10); 46 | texture.setFilter(.filter_nearest, .filter_nearest); 47 | } 48 | 49 | try alka.getAssetManager().loadFont(0, "assets/VCR_OSD_MONO.ttf", 128); 50 | const font = try alka.getAssetManager().getFont(0); 51 | font.texture.setFilter(.filter_nearest, .filter_nearest); 52 | 53 | var input = alka.getInput(); 54 | try input.bindMouse(.ButtonLeft); 55 | 56 | try input.bindKey(.A); 57 | try input.bindKey(.D); 58 | try input.bindKey(.W); 59 | try input.bindKey(.S); 60 | 61 | try input.bindKey(.LeftShift); 62 | 63 | try gui.init(); 64 | 65 | try game.open(); 66 | try game.run(); 67 | 68 | try gui.deinit(); 69 | 70 | try alka.deinit(); 71 | 72 | const leaked = gpa.deinit(); 73 | if (leaked) return error.Leak; 74 | } 75 | -------------------------------------------------------------------------------- /examples/example_shooter_game/src/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cd .. 4 | zig build run 5 | -------------------------------------------------------------------------------- /examples/gui.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const alka = @import("alka"); 3 | 4 | const gui = alka.gui; 5 | const m = alka.math; 6 | 7 | usingnamespace alka.log; 8 | 9 | pub const mlog = std.log.scoped(.app); 10 | pub const log_level: std.log.Level = .info; 11 | 12 | const virtualwidth: i32 = 1024; 13 | const virtualheight: i32 = 768; 14 | 15 | var vel: f32 = 0; 16 | var dir: f32 = 1; 17 | 18 | fn update(dt: f32) !void { 19 | const canvas = try gui.getCanvas(0); 20 | const pos = canvas.transform.getOriginated(); 21 | if (pos.x > 1024 - canvas.transform.size.x) { 22 | dir = -1; 23 | } else if (pos.x < 0) { 24 | dir = 1; 25 | } 26 | vel += 100 * dt * dir; 27 | try gui.update(dt); 28 | } 29 | 30 | fn fupdate(dt: f32) !void { 31 | var canvas = try gui.getCanvasPtr(0); 32 | var tr = try canvas.getTransformPtr(0); 33 | //canvas.transform.position.x += vel; 34 | //tr.position.x -= vel; 35 | vel = 0; 36 | try gui.fixed(dt); 37 | } 38 | 39 | fn draw() !void { 40 | const canvas = try gui.getCanvas(0); 41 | try gui.draw(); 42 | 43 | try canvas.drawLines(alka.Colour.rgba(255, 0, 0, 255)); 44 | } 45 | 46 | fn resize(w: i32, h: i32) void { 47 | alka.autoResize(virtualwidth, virtualheight, w, h); 48 | } 49 | 50 | fn updateButton(self: *gui.Element, dt: f32) !void { 51 | mlog.info("update: {}", .{self.id.?}); 52 | } 53 | 54 | fn fixedButton(self: *gui.Element, dt: f32) !void { 55 | mlog.info("fixed update: {}", .{self.id.?}); 56 | } 57 | 58 | fn drawButton(self: *gui.Element) !void { 59 | try alka.drawRectangleAdv( 60 | self.transform.getRectangleNoOrigin(), 61 | self.transform.origin, 62 | m.deg2radf(self.transform.rotation), 63 | self.colour, 64 | ); 65 | } 66 | 67 | fn onCreateButton(self: *gui.Element) !void { 68 | mlog.info("onCreate: {}", .{self.id.?}); 69 | } 70 | 71 | fn onDestroyButton(self: *gui.Element) !void { 72 | mlog.info("onDestroy: {}", .{self.id.?}); 73 | } 74 | 75 | fn onEnterButton(self: *gui.Element, position: m.Vec2f, relativepos: m.Vec2f) !void { 76 | mlog.notice("onEnter: {d}||{d} {d}||{d}", .{ position.x, position.y, relativepos.x, relativepos.y }); 77 | } 78 | 79 | fn onHoverButton(self: *gui.Element, position: m.Vec2f, relativepos: m.Vec2f) !void { 80 | mlog.notice("onHover: {d}||{d} {d}||{d}", .{ position.x, position.y, relativepos.x, relativepos.y }); 81 | } 82 | 83 | fn onClickButton(self: *gui.Element, position: m.Vec2f, relativepos: m.Vec2f, button: alka.input.Mouse) !void { 84 | mlog.notice("onClick[{}]: {d}||{d} {d}||{d}", .{ button, position.x, position.y, relativepos.x, relativepos.y }); 85 | } 86 | 87 | fn onPressedButton(self: *gui.Element, position: m.Vec2f, relativepos: m.Vec2f, button: alka.input.Mouse) !void { 88 | mlog.notice("onPressed[{}]: {d}||{d} {d}||{d}", .{ button, position.x, position.y, relativepos.x, relativepos.y }); 89 | } 90 | 91 | fn onDownButton(self: *gui.Element, position: m.Vec2f, relativepos: m.Vec2f, button: alka.input.Mouse) !void { 92 | mlog.notice("onDown[{}]: {d}||{d} {d}||{d}", .{ button, position.x, position.y, relativepos.x, relativepos.y }); 93 | } 94 | 95 | fn onReleasedButton(self: *gui.Element, position: m.Vec2f, relativepos: m.Vec2f, button: alka.input.Mouse) !void { 96 | mlog.notice("onReleased[{}]: {d}||{d} {d}||{d}", .{ button, position.x, position.y, relativepos.x, relativepos.y }); 97 | } 98 | 99 | fn onExitButton(self: *gui.Element, position: m.Vec2f, relativepos: m.Vec2f) !void { 100 | mlog.notice("onExit: {d}||{d} {d}||{d}", .{ position.x, position.y, relativepos.x, relativepos.y }); 101 | } 102 | 103 | pub fn main() !void { 104 | var gpa = std.heap.GeneralPurposeAllocator(.{}){}; 105 | 106 | const callbacks = alka.Callbacks{ 107 | .update = update, 108 | .fixed = fupdate, 109 | .draw = draw, 110 | .resize = resize, 111 | .close = null, 112 | }; 113 | 114 | try alka.init(&gpa.allocator, callbacks, 1024, 768, "GUI", 0, true); 115 | alka.autoResize(virtualwidth, virtualheight, 1024, 768); 116 | 117 | var inp = alka.getInput(); 118 | try inp.bindMouse(.ButtonLeft); 119 | try inp.bindMouse(.ButtonRight); 120 | 121 | // init the GUI 122 | try gui.init(alka.getAllocator()); 123 | 124 | // id, transform, colour 125 | var canvas = try gui.createCanvas(0, m.Transform2D{ 126 | .position = m.Vec2f{ .x = 500, .y = 300 }, 127 | .origin = m.Vec2f{ .x = 250, .y = 150 }, 128 | .size = m.Vec2f{ .x = 500, .y = 300 }, 129 | .rotation = 0, 130 | }, alka.Colour.rgba(255, 0, 0, 100)); 131 | 132 | // id, transform, colour, events 133 | var element = try canvas.createElement( 134 | 0, 135 | m.Transform2D{ 136 | .position = m.Vec2f{ .x = 100, .y = 200 }, 137 | .origin = m.Vec2f{ .x = 25, .y = 25 }, 138 | .size = m.Vec2f{ .x = 50, .y = 50 }, 139 | .rotation = 0, 140 | }, 141 | alka.Colour.rgba(30, 80, 200, 255), 142 | gui.Events{ 143 | .onCreate = onCreateButton, 144 | .onDestroy = onDestroyButton, 145 | //.onEnter = onEnterButton, 146 | //.onHover = onHoverButton, 147 | .onClick = onClickButton, 148 | //.onPressed = onPressedButton, 149 | //.onDown = onDownButton, 150 | //.onReleased = onReleasedButton, 151 | //.onExit = onExitButton, 152 | //.update = updateButton, 153 | //.fixed = fixedButton, 154 | .draw = drawButton, 155 | }, 156 | ); 157 | 158 | // id, transform, colour, events 159 | var element2 = try canvas.createElement( 160 | 1, 161 | m.Transform2D{ 162 | .position = m.Vec2f{ .x = 400, .y = 200 }, 163 | .origin = m.Vec2f{ .x = 25, .y = 25 }, 164 | .size = m.Vec2f{ .x = 50, .y = 50 }, 165 | .rotation = 0, 166 | }, 167 | alka.Colour.rgba(255, 255, 255, 255), 168 | gui.Events{ 169 | .onCreate = onCreateButton, 170 | .onDestroy = onDestroyButton, 171 | //.onEnter = onEnterButton, 172 | //.onHover = onHoverButton, 173 | //.onClick = onClickButton, 174 | //.onPressed = onPressedButton, 175 | //.onDown = onDownButton, 176 | .onReleased = onReleasedButton, 177 | //.onExit = onExitButton, 178 | //.update = updateButton, 179 | //.fixed = fixedButton, 180 | .draw = drawButton, 181 | }, 182 | ); 183 | 184 | // id 185 | //try canvas.destroyElement(1); 186 | 187 | try alka.open(); 188 | try alka.update(); 189 | try alka.close(); 190 | 191 | // deinit the GUI 192 | try gui.deinit(); 193 | 194 | try alka.deinit(); 195 | 196 | const leaked = gpa.deinit(); 197 | if (leaked) return error.Leak; 198 | } 199 | -------------------------------------------------------------------------------- /examples/input.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const alka = @import("alka"); 3 | 4 | usingnamespace alka.log; 5 | 6 | pub const mlog = std.log.scoped(.app); 7 | pub const log_level: std.log.Level = .info; 8 | 9 | var keyAPtr: *const alka.input.State = undefined; 10 | var mouseleftPtr: *const alka.input.State = undefined; 11 | 12 | fn update(dt: f32) !void { 13 | const input = alka.getInput(); 14 | 15 | const keyA = try input.keyState(alka.input.Key.A); 16 | const mouseleft = try input.mouseState(alka.input.Mouse.ButtonLeft); 17 | 18 | mlog.notice("keyA: {}, mouse left: {}", .{ keyA, mouseleft }); 19 | 20 | mlog.info("ptr keyA: {}, ptr mouse left: {}", .{ keyAPtr, mouseleftPtr }); 21 | } 22 | 23 | pub fn main() !void { 24 | var gpa = std.heap.GeneralPurposeAllocator(.{}){}; 25 | 26 | const callbacks = alka.Callbacks{ 27 | .update = update, 28 | .fixed = null, 29 | .draw = null, 30 | .resize = null, 31 | .close = null, 32 | }; 33 | 34 | try alka.init(&gpa.allocator, callbacks, 1024, 768, "Input", 0, false); 35 | 36 | var input = alka.getInput(); 37 | try input.bindKey(alka.input.Key.A); 38 | try input.bindMouse(alka.input.Mouse.ButtonLeft); 39 | 40 | keyAPtr = try input.keyStatePtr(alka.input.Key.A); 41 | mouseleftPtr = try input.mouseStatePtr(alka.input.Mouse.ButtonLeft); 42 | 43 | // to unbind 44 | //try input.unbindKey(alka.input.Mouse.ButtonLeft); 45 | //try input.unbindMouse(alka.input.Mouse.ButtonLeft); 46 | 47 | try alka.open(); 48 | try alka.update(); 49 | try alka.close(); 50 | 51 | try alka.deinit(); 52 | 53 | const leaked = gpa.deinit(); 54 | if (leaked) return error.Leak; 55 | } 56 | -------------------------------------------------------------------------------- /examples/shape_drawing.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const alka = @import("alka"); 3 | 4 | const m = alka.math; 5 | usingnamespace alka.log; 6 | 7 | pub const mlog = std.log.scoped(.app); 8 | pub const log_level: std.log.Level = .info; 9 | 10 | fn draw() !void { 11 | const r = m.Rectangle{ .position = m.Vec2f{ .x = 100.0, .y = 200.0 }, .size = m.Vec2f{ .x = 50.0, .y = 50.0 } }; 12 | const col = alka.Colour{ .r = 1, .g = 1, .b = 1, .a = 1 }; 13 | //try alka.drawRectangleAdv(r, m.Vec2f{ .x = 25, .y = 25 }, m.deg2radf(45), col); 14 | try alka.drawRectangleLinesAdv(r, m.Vec2f{ .x = 25, .y = 25 }, m.deg2radf(45), col); 15 | 16 | const r2 = m.Rectangle{ .position = m.Vec2f{ .x = 200.0, .y = 200.0 }, .size = m.Vec2f{ .x = 30.0, .y = 30.0 } }; 17 | const col2 = alka.Colour.rgba(30, 80, 200, 255); 18 | //try alka.drawRectangle(r2, col2); 19 | try alka.drawRectangleLines(r2, col2); 20 | 21 | // position, radius, colour 22 | // segment count is 16 by default 23 | //try alka.drawCircleLines(m.Vec2f{ .x = 350, .y = 260 }, 24, col); 24 | //try alka.drawCircle(m.Vec2f{ .x = 450, .y = 260 }, 24, col); 25 | // position, radius, segment count, startangle, endangle, colour 26 | try alka.drawCircleLinesAdv(m.Vec2f{ .x = 350, .y = 260 }, 24, 8, 0, 360, col); 27 | 28 | try alka.drawCircleLinesAdv(m.Vec2f{ .x = 350, .y = 360 }, 24, 32, 0, 360, col); 29 | 30 | try alka.drawCircleAdv(m.Vec2f{ .x = 450, .y = 260 }, 24, 32, 0, 360, col); 31 | try alka.drawCircleAdv(m.Vec2f{ .x = 450, .y = 360 }, 24, 8, 0, 360, col); 32 | 33 | // start, end, thickness, colour 34 | try alka.drawLine(m.Vec2f{ .x = 300, .y = 300 }, m.Vec2f{ .x = 400, .y = 350 }, 1, col); 35 | 36 | var i: f32 = 0; 37 | while (i < 10) : (i += 2) { 38 | try alka.drawPixel(m.Vec2f{ .x = 300 + i, .y = 400 }, col); 39 | } 40 | } 41 | 42 | pub fn main() !void { 43 | var gpa = std.heap.GeneralPurposeAllocator(.{}){}; 44 | 45 | const callbacks = alka.Callbacks{ 46 | .update = null, 47 | .fixed = null, 48 | .draw = draw, 49 | .resize = null, 50 | .close = null, 51 | }; 52 | 53 | try alka.init(&gpa.allocator, callbacks, 1024, 768, "Shape Drawing", 0, false); 54 | 55 | try alka.open(); 56 | try alka.update(); 57 | try alka.close(); 58 | 59 | try alka.deinit(); 60 | 61 | const leaked = gpa.deinit(); 62 | if (leaked) return error.Leak; 63 | } 64 | -------------------------------------------------------------------------------- /examples/text_rendering.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const alka = @import("alka"); 3 | 4 | const m = alka.math; 5 | usingnamespace alka.log; 6 | 7 | pub const mlog = std.log.scoped(.app); 8 | pub const log_level: std.log.Level = .info; 9 | 10 | fn draw() !void { 11 | const asset = alka.getAssetManager(); 12 | const staticfont = try asset.getTexture(1); 13 | const font = try asset.getFont(0); 14 | 15 | const r = m.Rectangle{ .position = m.Vec2f{ .x = 200.0, .y = 200.0 }, .size = m.Vec2f{ .x = 500.0, .y = 500.0 } }; 16 | const srect = m.Rectangle{ .position = m.Vec2f{ .x = 0.0, .y = 0.0 }, .size = m.Vec2f{ .x = @intToFloat(f32, staticfont.width), .y = @intToFloat(f32, staticfont.height) } }; 17 | const col = alka.Colour{ .r = 1, .g = 1, .b = 1, .a = 1 }; 18 | 19 | try alka.drawTexture(1, r, srect, col); 20 | 21 | // id, position, size, colour 22 | try alka.drawTextPoint(0, 'A', m.Vec2f{ .x = 200, .y = 300 }, 24, col); 23 | try alka.drawTextPoint(0, 'L', m.Vec2f{ .x = 200 + 15, .y = 300 }, 24, col); 24 | try alka.drawTextPoint(0, 'K', m.Vec2f{ .x = 200 + 15 * 2, .y = 300 }, 24, col); 25 | try alka.drawTextPoint(0, 'A', m.Vec2f{ .x = 200 + 15 * 3, .y = 300 }, 24, col); 26 | 27 | try alka.drawText(0, "This is rendered on the fly!", m.Vec2f{ .x = 100, .y = 500 }, 32, col); 28 | 29 | const alloc = alka.getAllocator(); 30 | var debug: []u8 = try alloc.alloc(u8, 255); 31 | defer alloc.free(debug); 32 | debug = try std.fmt.bufPrintZ(debug, "fps: {}", .{alka.getFps()}); 33 | 34 | try alka.drawText(0, debug, m.Vec2f{ .x = 20, .y = 20 }, 24, col); 35 | } 36 | 37 | pub fn main() !void { 38 | var gpa = std.heap.GeneralPurposeAllocator(.{}){}; 39 | 40 | const callbacks = alka.Callbacks{ 41 | .update = null, 42 | .fixed = null, 43 | .draw = draw, 44 | .resize = null, 45 | .close = null, 46 | }; 47 | 48 | try alka.init(&gpa.allocator, callbacks, 1024, 768, "Text Rendering", 0, false); 49 | 50 | // .. bitmap width & height, pixel size 51 | const texture = try alka.renderer.Texture.createFromTTF(&gpa.allocator, "assets/arial.ttf", "Hello", 500, 500, 24); 52 | // min, mag 53 | texture.setFilter(alka.gl.TextureParamater.filter_mipmap_nearest, alka.gl.TextureParamater.filter_linear); 54 | // id, texture 55 | try alka.getAssetManager().loadTexturePro(1, texture); // texture 0 & shader 0 is reserved for defaults 56 | 57 | // id, path, pixel size 58 | try alka.getAssetManager().loadFont(0, "assets/arial.ttf", 128); 59 | const font = try alka.getAssetManager().getFont(0); 60 | // min, mag 61 | font.texture.setFilter(alka.gl.TextureParamater.filter_mipmap_nearest, alka.gl.TextureParamater.filter_linear); 62 | 63 | try alka.open(); 64 | try alka.update(); 65 | try alka.close(); 66 | 67 | try alka.deinit(); 68 | 69 | const leaked = gpa.deinit(); 70 | if (leaked) return error.Leak; 71 | } 72 | -------------------------------------------------------------------------------- /examples/texture_drawing.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const alka = @import("alka"); 3 | 4 | const m = alka.math; 5 | usingnamespace alka.log; 6 | 7 | pub const mlog = std.log.scoped(.app); 8 | pub const log_level: std.log.Level = .info; 9 | 10 | fn draw() !void { 11 | const asset = alka.getAssetManager(); 12 | const testpng = try asset.getTexture(1); 13 | 14 | const srect = m.Rectangle{ .position = m.Vec2f{ .x = 0.0, .y = 0.0 }, .size = m.Vec2f{ .x = @intToFloat(f32, testpng.width), .y = @intToFloat(f32, testpng.height) } }; 15 | 16 | const r = m.Rectangle{ .position = m.Vec2f{ .x = 100.0, .y = 200.0 }, .size = m.Vec2f{ .x = 50.0, .y = 50.0 } }; 17 | const col = alka.Colour{ .r = 1, .g = 1, .b = 1, .a = 1 }; 18 | // id, rect, source rect, origin, angle in radians, colour 19 | try alka.drawTextureAdv(1, r, srect, m.Vec2f{ .x = 25, .y = 25 }, m.deg2radf(45), col); 20 | 21 | const r2 = m.Rectangle{ .position = m.Vec2f{ .x = 300.0, .y = 200.0 }, .size = m.Vec2f{ .x = 50.0, .y = 50.0 } }; 22 | const col2 = alka.Colour.rgba(30, 80, 200, 255); 23 | // id, rect, source rect, colour 24 | try alka.drawTexture(1, r2, srect, col2); 25 | } 26 | 27 | pub fn main() !void { 28 | var gpa = std.heap.GeneralPurposeAllocator(.{}){}; 29 | 30 | const callbacks = alka.Callbacks{ 31 | .update = null, 32 | .fixed = null, 33 | .draw = draw, 34 | .resize = null, 35 | .close = null, 36 | }; 37 | 38 | try alka.init(&gpa.allocator, callbacks, 1024, 768, "Texture Drawing", 0, false); 39 | 40 | // id, path 41 | try alka.getAssetManager().loadTexture(1, "assets/test.png"); 42 | { 43 | const texture = try alka.getAssetManager().getTexture(1); 44 | // min, mag 45 | texture.setFilter(alka.gl.TextureParamater.filter_nearest, alka.gl.TextureParamater.filter_nearest); 46 | } 47 | 48 | // or 49 | { 50 | const texture = try alka.renderer.Texture.createFromPNG(&gpa.allocator, "assets/test.png"); 51 | try alka.getAssetManager().loadTexturePro(2, texture); 52 | } 53 | 54 | // or 55 | { 56 | const mem = @embedFile("../assets/test.png"); 57 | const texture = try alka.renderer.Texture.createFromPNGMemory(mem); 58 | try alka.getAssetManager().loadTexturePro(3, texture); 59 | // or 60 | try alka.getAssetManager().loadTextureFromMemory(4, mem); 61 | } 62 | 63 | try alka.open(); 64 | try alka.update(); 65 | try alka.close(); 66 | 67 | try alka.deinit(); 68 | 69 | const leaked = gpa.deinit(); 70 | if (leaked) return error.Leak; 71 | } 72 | -------------------------------------------------------------------------------- /get-started.md: -------------------------------------------------------------------------------- 1 | ## How to compile? 2 | 3 | Clone this github repo or download the newest release and copy the "libbuild.zig" file to your project for zig's build system 4 | 5 | After that all you need to do put this code in `build.zig` file: 6 | 7 | ```zig 8 | const Builder = @import("std").build.Builder; 9 | const lib = @import("libbuild.zig"); 10 | 11 | pub fn build(b: *Builder) void { 12 | const target = b.standardTargetOptions(.{}); 13 | const mode = b.standardReleaseOptions(); 14 | 15 | lib.strip = b.option(bool, "strip", "Strip the exe?") orelse false; 16 | 17 | // Note: the 'enginepath' should be a relative path! 18 | const exe = lib.setup(b, target, app_name, path_to_main_src, enginepath); 19 | exe.setOutputDir("build"); 20 | exe.setBuildMode(mode); 21 | exe.install(); 22 | } 23 | ``` 24 | `zig build` and done! 25 | 26 | ### [Basic application](https://github.com/Kiakra/Alka/blob/master/examples/basic_setup.zig) 27 | 28 | #### More on [examples](https://github.com/Kiakra/Alka/tree/master/examples) 29 | -------------------------------------------------------------------------------- /include/glfw-3.3.4/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(common_HEADERS internal.h mappings.h 3 | "${GLFW_BINARY_DIR}/src/glfw_config.h" 4 | "${GLFW_SOURCE_DIR}/include/GLFW/glfw3.h" 5 | "${GLFW_SOURCE_DIR}/include/GLFW/glfw3native.h") 6 | set(common_SOURCES context.c init.c input.c monitor.c vulkan.c window.c) 7 | 8 | if (_GLFW_COCOA) 9 | set(glfw_HEADERS ${common_HEADERS} cocoa_platform.h cocoa_joystick.h 10 | posix_thread.h nsgl_context.h egl_context.h osmesa_context.h) 11 | set(glfw_SOURCES ${common_SOURCES} cocoa_init.m cocoa_joystick.m 12 | cocoa_monitor.m cocoa_window.m cocoa_time.c posix_thread.c 13 | nsgl_context.m egl_context.c osmesa_context.c) 14 | elseif (_GLFW_WIN32) 15 | set(glfw_HEADERS ${common_HEADERS} win32_platform.h win32_joystick.h 16 | wgl_context.h egl_context.h osmesa_context.h) 17 | set(glfw_SOURCES ${common_SOURCES} win32_init.c win32_joystick.c 18 | win32_monitor.c win32_time.c win32_thread.c win32_window.c 19 | wgl_context.c egl_context.c osmesa_context.c) 20 | elseif (_GLFW_X11) 21 | set(glfw_HEADERS ${common_HEADERS} x11_platform.h xkb_unicode.h posix_time.h 22 | posix_thread.h glx_context.h egl_context.h osmesa_context.h) 23 | set(glfw_SOURCES ${common_SOURCES} x11_init.c x11_monitor.c x11_window.c 24 | xkb_unicode.c posix_time.c posix_thread.c glx_context.c 25 | egl_context.c osmesa_context.c) 26 | elseif (_GLFW_WAYLAND) 27 | set(glfw_HEADERS ${common_HEADERS} wl_platform.h 28 | posix_time.h posix_thread.h xkb_unicode.h egl_context.h 29 | osmesa_context.h) 30 | set(glfw_SOURCES ${common_SOURCES} wl_init.c wl_monitor.c wl_window.c 31 | posix_time.c posix_thread.c xkb_unicode.c 32 | egl_context.c osmesa_context.c) 33 | 34 | ecm_add_wayland_client_protocol(glfw_SOURCES 35 | PROTOCOL 36 | "${WAYLAND_PROTOCOLS_PKGDATADIR}/stable/xdg-shell/xdg-shell.xml" 37 | BASENAME xdg-shell) 38 | ecm_add_wayland_client_protocol(glfw_SOURCES 39 | PROTOCOL 40 | "${WAYLAND_PROTOCOLS_PKGDATADIR}/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml" 41 | BASENAME xdg-decoration) 42 | ecm_add_wayland_client_protocol(glfw_SOURCES 43 | PROTOCOL 44 | "${WAYLAND_PROTOCOLS_PKGDATADIR}/stable/viewporter/viewporter.xml" 45 | BASENAME viewporter) 46 | ecm_add_wayland_client_protocol(glfw_SOURCES 47 | PROTOCOL 48 | "${WAYLAND_PROTOCOLS_PKGDATADIR}/unstable/relative-pointer/relative-pointer-unstable-v1.xml" 49 | BASENAME relative-pointer-unstable-v1) 50 | ecm_add_wayland_client_protocol(glfw_SOURCES 51 | PROTOCOL 52 | "${WAYLAND_PROTOCOLS_PKGDATADIR}/unstable/pointer-constraints/pointer-constraints-unstable-v1.xml" 53 | BASENAME pointer-constraints-unstable-v1) 54 | ecm_add_wayland_client_protocol(glfw_SOURCES 55 | PROTOCOL 56 | "${WAYLAND_PROTOCOLS_PKGDATADIR}/unstable/idle-inhibit/idle-inhibit-unstable-v1.xml" 57 | BASENAME idle-inhibit-unstable-v1) 58 | elseif (_GLFW_OSMESA) 59 | set(glfw_HEADERS ${common_HEADERS} null_platform.h null_joystick.h 60 | posix_time.h posix_thread.h osmesa_context.h) 61 | set(glfw_SOURCES ${common_SOURCES} null_init.c null_monitor.c null_window.c 62 | null_joystick.c posix_time.c posix_thread.c osmesa_context.c) 63 | endif() 64 | 65 | if (_GLFW_X11 OR _GLFW_WAYLAND) 66 | if (CMAKE_SYSTEM_NAME STREQUAL "Linux") 67 | set(glfw_HEADERS ${glfw_HEADERS} linux_joystick.h) 68 | set(glfw_SOURCES ${glfw_SOURCES} linux_joystick.c) 69 | else() 70 | set(glfw_HEADERS ${glfw_HEADERS} null_joystick.h) 71 | set(glfw_SOURCES ${glfw_SOURCES} null_joystick.c) 72 | endif() 73 | endif() 74 | 75 | # Workaround for CMake not knowing about .m files before version 3.16 76 | if (CMAKE_VERSION VERSION_LESS "3.16" AND APPLE) 77 | set_source_files_properties(cocoa_init.m cocoa_joystick.m cocoa_monitor.m 78 | cocoa_window.m nsgl_context.m PROPERTIES 79 | LANGUAGE C) 80 | endif() 81 | 82 | add_library(glfw ${glfw_SOURCES} ${glfw_HEADERS}) 83 | set_target_properties(glfw PROPERTIES 84 | OUTPUT_NAME ${GLFW_LIB_NAME} 85 | VERSION ${GLFW_VERSION_MAJOR}.${GLFW_VERSION_MINOR} 86 | SOVERSION ${GLFW_VERSION_MAJOR} 87 | POSITION_INDEPENDENT_CODE ON 88 | FOLDER "GLFW3") 89 | 90 | if (CMAKE_VERSION VERSION_EQUAL "3.1.0" OR 91 | CMAKE_VERSION VERSION_GREATER "3.1.0") 92 | 93 | set_target_properties(glfw PROPERTIES C_STANDARD 99) 94 | else() 95 | # Remove this fallback when removing support for CMake version less than 3.1 96 | target_compile_options(glfw PRIVATE 97 | "$<$:-std=c99>" 98 | "$<$:-std=c99>" 99 | "$<$:-std=c99>") 100 | endif() 101 | 102 | target_compile_definitions(glfw PRIVATE _GLFW_USE_CONFIG_H) 103 | target_include_directories(glfw PUBLIC 104 | "$" 105 | "$") 106 | target_include_directories(glfw PRIVATE 107 | "${GLFW_SOURCE_DIR}/src" 108 | "${GLFW_BINARY_DIR}/src" 109 | ${glfw_INCLUDE_DIRS}) 110 | target_link_libraries(glfw PRIVATE ${glfw_LIBRARIES}) 111 | 112 | # Make GCC warn about declarations that VS 2010 and 2012 won't accept for all 113 | # source files that VS will build (Clang ignores this because we set -std=c99) 114 | if (CMAKE_C_COMPILER_ID STREQUAL "GNU") 115 | set_source_files_properties(context.c init.c input.c monitor.c vulkan.c 116 | window.c win32_init.c win32_joystick.c 117 | win32_monitor.c win32_time.c win32_thread.c 118 | win32_window.c wgl_context.c egl_context.c 119 | osmesa_context.c PROPERTIES 120 | COMPILE_FLAGS -Wdeclaration-after-statement) 121 | endif() 122 | 123 | # Enable a reasonable set of warnings 124 | if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR 125 | CMAKE_C_COMPILER_ID STREQUAL "Clang" OR 126 | CMAKE_C_COMPILER_ID STREQUAL "AppleClang") 127 | 128 | if (CMAKE_C_SIMULATE_ID STREQUAL "MSVC") 129 | # Tell Clang-CL that this is a Clang flag 130 | target_compile_options(glfw PRIVATE "/clang:-Wall") 131 | else() 132 | target_compile_options(glfw PRIVATE "-Wall") 133 | endif() 134 | elseif (MSVC) 135 | target_compile_options(glfw PRIVATE "/W3") 136 | endif() 137 | 138 | if (WIN32) 139 | target_compile_definitions(glfw PRIVATE _UNICODE) 140 | endif() 141 | 142 | # HACK: When building on MinGW, WINVER and UNICODE need to be defined before 143 | # the inclusion of stddef.h (by glfw3.h), which is itself included before 144 | # win32_platform.h. We define them here until a saner solution can be found 145 | # NOTE: MinGW-w64 and Visual C++ do /not/ need this hack. 146 | if (MINGW) 147 | target_compile_definitions(glfw PRIVATE UNICODE WINVER=0x0501) 148 | endif() 149 | 150 | if (BUILD_SHARED_LIBS) 151 | if (WIN32) 152 | if (MINGW) 153 | # Remove the dependency on the shared version of libgcc 154 | # NOTE: MinGW-w64 has the correct default but MinGW needs this 155 | target_link_libraries(glfw PRIVATE "-static-libgcc") 156 | 157 | # Remove the lib prefix on the DLL (but not the import library) 158 | set_target_properties(glfw PROPERTIES PREFIX "") 159 | 160 | # Add a suffix to the import library to avoid naming conflicts 161 | set_target_properties(glfw PROPERTIES IMPORT_SUFFIX "dll.a") 162 | else() 163 | # Add a suffix to the import library to avoid naming conflicts 164 | set_target_properties(glfw PROPERTIES IMPORT_SUFFIX "dll.lib") 165 | endif() 166 | 167 | target_compile_definitions(glfw INTERFACE GLFW_DLL) 168 | elseif (APPLE) 169 | # Add -fno-common to work around a bug in Apple's GCC 170 | target_compile_options(glfw PRIVATE "-fno-common") 171 | endif() 172 | 173 | if (UNIX) 174 | # Hide symbols not explicitly tagged for export from the shared library 175 | target_compile_options(glfw PRIVATE "-fvisibility=hidden") 176 | endif() 177 | endif() 178 | 179 | if (MSVC) 180 | target_compile_definitions(glfw PRIVATE _CRT_SECURE_NO_WARNINGS) 181 | endif() 182 | 183 | if (GLFW_INSTALL) 184 | install(TARGETS glfw 185 | EXPORT glfwTargets 186 | RUNTIME DESTINATION "bin" 187 | ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" 188 | LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") 189 | endif() 190 | 191 | -------------------------------------------------------------------------------- /include/glfw-3.3.4/src/cocoa_joystick.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 Cocoa - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2006-2017 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #define _GLFW_PLATFORM_JOYSTICK_STATE _GLFWjoystickNS ns 33 | #define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE struct { int dummyJoystick; } 34 | 35 | #define _GLFW_PLATFORM_MAPPING_NAME "Mac OS X" 36 | 37 | // Cocoa-specific per-joystick data 38 | // 39 | typedef struct _GLFWjoystickNS 40 | { 41 | IOHIDDeviceRef device; 42 | CFMutableArrayRef axes; 43 | CFMutableArrayRef buttons; 44 | CFMutableArrayRef hats; 45 | } _GLFWjoystickNS; 46 | 47 | 48 | void _glfwInitJoysticksNS(void); 49 | void _glfwTerminateJoysticksNS(void); 50 | 51 | -------------------------------------------------------------------------------- /include/glfw-3.3.4/src/cocoa_platform.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 macOS - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2009-2019 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #include 28 | #include 29 | 30 | #include 31 | 32 | // NOTE: All of NSGL was deprecated in the 10.14 SDK 33 | // This disables the pointless warnings for every symbol we use 34 | #define GL_SILENCE_DEPRECATION 35 | 36 | #if defined(__OBJC__) 37 | #import 38 | #else 39 | typedef void* id; 40 | #endif 41 | 42 | // NOTE: Many Cocoa enum values have been renamed and we need to build across 43 | // SDK versions where one is unavailable or the other deprecated 44 | // We use the newer names in code and these macros to handle compatibility 45 | #if MAC_OS_X_VERSION_MAX_ALLOWED < 101200 46 | #define NSBitmapFormatAlphaNonpremultiplied NSAlphaNonpremultipliedBitmapFormat 47 | #define NSEventMaskAny NSAnyEventMask 48 | #define NSEventMaskKeyUp NSKeyUpMask 49 | #define NSEventModifierFlagCapsLock NSAlphaShiftKeyMask 50 | #define NSEventModifierFlagCommand NSCommandKeyMask 51 | #define NSEventModifierFlagControl NSControlKeyMask 52 | #define NSEventModifierFlagDeviceIndependentFlagsMask NSDeviceIndependentModifierFlagsMask 53 | #define NSEventModifierFlagOption NSAlternateKeyMask 54 | #define NSEventModifierFlagShift NSShiftKeyMask 55 | #define NSEventTypeApplicationDefined NSApplicationDefined 56 | #define NSWindowStyleMaskBorderless NSBorderlessWindowMask 57 | #define NSWindowStyleMaskClosable NSClosableWindowMask 58 | #define NSWindowStyleMaskMiniaturizable NSMiniaturizableWindowMask 59 | #define NSWindowStyleMaskResizable NSResizableWindowMask 60 | #define NSWindowStyleMaskTitled NSTitledWindowMask 61 | #endif 62 | 63 | typedef VkFlags VkMacOSSurfaceCreateFlagsMVK; 64 | typedef VkFlags VkMetalSurfaceCreateFlagsEXT; 65 | 66 | typedef struct VkMacOSSurfaceCreateInfoMVK 67 | { 68 | VkStructureType sType; 69 | const void* pNext; 70 | VkMacOSSurfaceCreateFlagsMVK flags; 71 | const void* pView; 72 | } VkMacOSSurfaceCreateInfoMVK; 73 | 74 | typedef struct VkMetalSurfaceCreateInfoEXT 75 | { 76 | VkStructureType sType; 77 | const void* pNext; 78 | VkMetalSurfaceCreateFlagsEXT flags; 79 | const void* pLayer; 80 | } VkMetalSurfaceCreateInfoEXT; 81 | 82 | typedef VkResult (APIENTRY *PFN_vkCreateMacOSSurfaceMVK)(VkInstance,const VkMacOSSurfaceCreateInfoMVK*,const VkAllocationCallbacks*,VkSurfaceKHR*); 83 | typedef VkResult (APIENTRY *PFN_vkCreateMetalSurfaceEXT)(VkInstance,const VkMetalSurfaceCreateInfoEXT*,const VkAllocationCallbacks*,VkSurfaceKHR*); 84 | 85 | #include "posix_thread.h" 86 | #include "cocoa_joystick.h" 87 | #include "nsgl_context.h" 88 | #include "egl_context.h" 89 | #include "osmesa_context.h" 90 | 91 | #define _glfw_dlopen(name) dlopen(name, RTLD_LAZY | RTLD_LOCAL) 92 | #define _glfw_dlclose(handle) dlclose(handle) 93 | #define _glfw_dlsym(handle, name) dlsym(handle, name) 94 | 95 | #define _GLFW_EGL_NATIVE_WINDOW ((EGLNativeWindowType) window->ns.layer) 96 | #define _GLFW_EGL_NATIVE_DISPLAY EGL_DEFAULT_DISPLAY 97 | 98 | #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowNS ns 99 | #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryNS ns 100 | #define _GLFW_PLATFORM_LIBRARY_TIMER_STATE _GLFWtimerNS ns 101 | #define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorNS ns 102 | #define _GLFW_PLATFORM_CURSOR_STATE _GLFWcursorNS ns 103 | 104 | // HIToolbox.framework pointer typedefs 105 | #define kTISPropertyUnicodeKeyLayoutData _glfw.ns.tis.kPropertyUnicodeKeyLayoutData 106 | typedef TISInputSourceRef (*PFN_TISCopyCurrentKeyboardLayoutInputSource)(void); 107 | #define TISCopyCurrentKeyboardLayoutInputSource _glfw.ns.tis.CopyCurrentKeyboardLayoutInputSource 108 | typedef void* (*PFN_TISGetInputSourceProperty)(TISInputSourceRef,CFStringRef); 109 | #define TISGetInputSourceProperty _glfw.ns.tis.GetInputSourceProperty 110 | typedef UInt8 (*PFN_LMGetKbdType)(void); 111 | #define LMGetKbdType _glfw.ns.tis.GetKbdType 112 | 113 | 114 | // Cocoa-specific per-window data 115 | // 116 | typedef struct _GLFWwindowNS 117 | { 118 | id object; 119 | id delegate; 120 | id view; 121 | id layer; 122 | 123 | GLFWbool maximized; 124 | GLFWbool occluded; 125 | GLFWbool retina; 126 | 127 | // Cached window properties to filter out duplicate events 128 | int width, height; 129 | int fbWidth, fbHeight; 130 | float xscale, yscale; 131 | 132 | // The total sum of the distances the cursor has been warped 133 | // since the last cursor motion event was processed 134 | // This is kept to counteract Cocoa doing the same internally 135 | double cursorWarpDeltaX, cursorWarpDeltaY; 136 | 137 | } _GLFWwindowNS; 138 | 139 | // Cocoa-specific global data 140 | // 141 | typedef struct _GLFWlibraryNS 142 | { 143 | CGEventSourceRef eventSource; 144 | id delegate; 145 | GLFWbool finishedLaunching; 146 | GLFWbool cursorHidden; 147 | TISInputSourceRef inputSource; 148 | IOHIDManagerRef hidManager; 149 | id unicodeData; 150 | id helper; 151 | id keyUpMonitor; 152 | id nibObjects; 153 | 154 | char keynames[GLFW_KEY_LAST + 1][17]; 155 | short int keycodes[256]; 156 | short int scancodes[GLFW_KEY_LAST + 1]; 157 | char* clipboardString; 158 | CGPoint cascadePoint; 159 | // Where to place the cursor when re-enabled 160 | double restoreCursorPosX, restoreCursorPosY; 161 | // The window whose disabled cursor mode is active 162 | _GLFWwindow* disabledCursorWindow; 163 | 164 | struct { 165 | CFBundleRef bundle; 166 | PFN_TISCopyCurrentKeyboardLayoutInputSource CopyCurrentKeyboardLayoutInputSource; 167 | PFN_TISGetInputSourceProperty GetInputSourceProperty; 168 | PFN_LMGetKbdType GetKbdType; 169 | CFStringRef kPropertyUnicodeKeyLayoutData; 170 | } tis; 171 | 172 | } _GLFWlibraryNS; 173 | 174 | // Cocoa-specific per-monitor data 175 | // 176 | typedef struct _GLFWmonitorNS 177 | { 178 | CGDirectDisplayID displayID; 179 | CGDisplayModeRef previousMode; 180 | uint32_t unitNumber; 181 | id screen; 182 | double fallbackRefreshRate; 183 | 184 | } _GLFWmonitorNS; 185 | 186 | // Cocoa-specific per-cursor data 187 | // 188 | typedef struct _GLFWcursorNS 189 | { 190 | id object; 191 | 192 | } _GLFWcursorNS; 193 | 194 | // Cocoa-specific global timer data 195 | // 196 | typedef struct _GLFWtimerNS 197 | { 198 | uint64_t frequency; 199 | 200 | } _GLFWtimerNS; 201 | 202 | 203 | void _glfwInitTimerNS(void); 204 | 205 | void _glfwPollMonitorsNS(void); 206 | void _glfwSetVideoModeNS(_GLFWmonitor* monitor, const GLFWvidmode* desired); 207 | void _glfwRestoreVideoModeNS(_GLFWmonitor* monitor); 208 | 209 | float _glfwTransformYNS(float y); 210 | 211 | void* _glfwLoadLocalVulkanLoaderNS(void); 212 | 213 | -------------------------------------------------------------------------------- /include/glfw-3.3.4/src/cocoa_time.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 macOS - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2009-2016 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | // It is fine to use C99 in this file because it will not be built with VS 27 | //======================================================================== 28 | 29 | #include "internal.h" 30 | 31 | #include 32 | 33 | 34 | ////////////////////////////////////////////////////////////////////////// 35 | ////// GLFW internal API ////// 36 | ////////////////////////////////////////////////////////////////////////// 37 | 38 | // Initialise timer 39 | // 40 | void _glfwInitTimerNS(void) 41 | { 42 | mach_timebase_info_data_t info; 43 | mach_timebase_info(&info); 44 | 45 | _glfw.timer.ns.frequency = (info.denom * 1e9) / info.numer; 46 | } 47 | 48 | 49 | ////////////////////////////////////////////////////////////////////////// 50 | ////// GLFW platform API ////// 51 | ////////////////////////////////////////////////////////////////////////// 52 | 53 | uint64_t _glfwPlatformGetTimerValue(void) 54 | { 55 | return mach_absolute_time(); 56 | } 57 | 58 | uint64_t _glfwPlatformGetTimerFrequency(void) 59 | { 60 | return _glfw.timer.ns.frequency; 61 | } 62 | 63 | -------------------------------------------------------------------------------- /include/glfw-3.3.4/src/glfw3.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ 4 | libdir=@CMAKE_INSTALL_FULL_LIBDIR@ 5 | 6 | Name: GLFW 7 | Description: A multi-platform library for OpenGL, window and input 8 | Version: @GLFW_VERSION@ 9 | URL: https://www.glfw.org/ 10 | Requires.private: @GLFW_PKG_DEPS@ 11 | Libs: -L${libdir} -l@GLFW_LIB_NAME@ 12 | Libs.private: @GLFW_PKG_LIBS@ 13 | Cflags: -I${includedir} 14 | -------------------------------------------------------------------------------- /include/glfw-3.3.4/src/glfw3Config.cmake.in: -------------------------------------------------------------------------------- 1 | include("${CMAKE_CURRENT_LIST_DIR}/glfw3Targets.cmake") 2 | -------------------------------------------------------------------------------- /include/glfw-3.3.4/src/glfw_config.h.in: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2010-2016 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | // As glfw_config.h.in, this file is used by CMake to produce the 27 | // glfw_config.h configuration header file. If you are adding a feature 28 | // requiring conditional compilation, this is where to add the macro. 29 | //======================================================================== 30 | // As glfw_config.h, this file defines compile-time option macros for a 31 | // specific platform and development environment. If you are using the 32 | // GLFW CMake files, modify glfw_config.h.in instead of this file. If you 33 | // are using your own build system, make this file define the appropriate 34 | // macros in whatever way is suitable. 35 | //======================================================================== 36 | 37 | // Define this to 1 if building GLFW for X11 38 | #cmakedefine _GLFW_X11 39 | // Define this to 1 if building GLFW for Win32 40 | #cmakedefine _GLFW_WIN32 41 | // Define this to 1 if building GLFW for Cocoa 42 | #cmakedefine _GLFW_COCOA 43 | // Define this to 1 if building GLFW for Wayland 44 | #cmakedefine _GLFW_WAYLAND 45 | // Define this to 1 if building GLFW for OSMesa 46 | #cmakedefine _GLFW_OSMESA 47 | 48 | // Define this to 1 if building as a shared library / dynamic library / DLL 49 | #cmakedefine _GLFW_BUILD_DLL 50 | // Define this to 1 to use Vulkan loader linked statically into application 51 | #cmakedefine _GLFW_VULKAN_STATIC 52 | 53 | // Define this to 1 to force use of high-performance GPU on hybrid systems 54 | #cmakedefine _GLFW_USE_HYBRID_HPG 55 | 56 | // Define this to 1 if xkbcommon supports the compose key 57 | #cmakedefine HAVE_XKBCOMMON_COMPOSE_H 58 | // Define this to 1 if the libc supports memfd_create() 59 | #cmakedefine HAVE_MEMFD_CREATE 60 | 61 | -------------------------------------------------------------------------------- /include/glfw-3.3.4/src/glx_context.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 GLX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #define GLX_VENDOR 1 29 | #define GLX_RGBA_BIT 0x00000001 30 | #define GLX_WINDOW_BIT 0x00000001 31 | #define GLX_DRAWABLE_TYPE 0x8010 32 | #define GLX_RENDER_TYPE 0x8011 33 | #define GLX_RGBA_TYPE 0x8014 34 | #define GLX_DOUBLEBUFFER 5 35 | #define GLX_STEREO 6 36 | #define GLX_AUX_BUFFERS 7 37 | #define GLX_RED_SIZE 8 38 | #define GLX_GREEN_SIZE 9 39 | #define GLX_BLUE_SIZE 10 40 | #define GLX_ALPHA_SIZE 11 41 | #define GLX_DEPTH_SIZE 12 42 | #define GLX_STENCIL_SIZE 13 43 | #define GLX_ACCUM_RED_SIZE 14 44 | #define GLX_ACCUM_GREEN_SIZE 15 45 | #define GLX_ACCUM_BLUE_SIZE 16 46 | #define GLX_ACCUM_ALPHA_SIZE 17 47 | #define GLX_SAMPLES 0x186a1 48 | #define GLX_VISUAL_ID 0x800b 49 | 50 | #define GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB 0x20b2 51 | #define GLX_CONTEXT_DEBUG_BIT_ARB 0x00000001 52 | #define GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002 53 | #define GLX_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001 54 | #define GLX_CONTEXT_PROFILE_MASK_ARB 0x9126 55 | #define GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x00000002 56 | #define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091 57 | #define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092 58 | #define GLX_CONTEXT_FLAGS_ARB 0x2094 59 | #define GLX_CONTEXT_ES2_PROFILE_BIT_EXT 0x00000004 60 | #define GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB 0x00000004 61 | #define GLX_LOSE_CONTEXT_ON_RESET_ARB 0x8252 62 | #define GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB 0x8256 63 | #define GLX_NO_RESET_NOTIFICATION_ARB 0x8261 64 | #define GLX_CONTEXT_RELEASE_BEHAVIOR_ARB 0x2097 65 | #define GLX_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB 0 66 | #define GLX_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB 0x2098 67 | #define GLX_CONTEXT_OPENGL_NO_ERROR_ARB 0x31b3 68 | 69 | typedef XID GLXWindow; 70 | typedef XID GLXDrawable; 71 | typedef struct __GLXFBConfig* GLXFBConfig; 72 | typedef struct __GLXcontext* GLXContext; 73 | typedef void (*__GLXextproc)(void); 74 | 75 | typedef int (*PFNGLXGETFBCONFIGATTRIBPROC)(Display*,GLXFBConfig,int,int*); 76 | typedef const char* (*PFNGLXGETCLIENTSTRINGPROC)(Display*,int); 77 | typedef Bool (*PFNGLXQUERYEXTENSIONPROC)(Display*,int*,int*); 78 | typedef Bool (*PFNGLXQUERYVERSIONPROC)(Display*,int*,int*); 79 | typedef void (*PFNGLXDESTROYCONTEXTPROC)(Display*,GLXContext); 80 | typedef Bool (*PFNGLXMAKECURRENTPROC)(Display*,GLXDrawable,GLXContext); 81 | typedef void (*PFNGLXSWAPBUFFERSPROC)(Display*,GLXDrawable); 82 | typedef const char* (*PFNGLXQUERYEXTENSIONSSTRINGPROC)(Display*,int); 83 | typedef GLXFBConfig* (*PFNGLXGETFBCONFIGSPROC)(Display*,int,int*); 84 | typedef GLXContext (*PFNGLXCREATENEWCONTEXTPROC)(Display*,GLXFBConfig,int,GLXContext,Bool); 85 | typedef __GLXextproc (* PFNGLXGETPROCADDRESSPROC)(const GLubyte *procName); 86 | typedef void (*PFNGLXSWAPINTERVALEXTPROC)(Display*,GLXDrawable,int); 87 | typedef XVisualInfo* (*PFNGLXGETVISUALFROMFBCONFIGPROC)(Display*,GLXFBConfig); 88 | typedef GLXWindow (*PFNGLXCREATEWINDOWPROC)(Display*,GLXFBConfig,Window,const int*); 89 | typedef void (*PFNGLXDESTROYWINDOWPROC)(Display*,GLXWindow); 90 | 91 | typedef int (*PFNGLXSWAPINTERVALMESAPROC)(int); 92 | typedef int (*PFNGLXSWAPINTERVALSGIPROC)(int); 93 | typedef GLXContext (*PFNGLXCREATECONTEXTATTRIBSARBPROC)(Display*,GLXFBConfig,GLXContext,Bool,const int*); 94 | 95 | // libGL.so function pointer typedefs 96 | #define glXGetFBConfigs _glfw.glx.GetFBConfigs 97 | #define glXGetFBConfigAttrib _glfw.glx.GetFBConfigAttrib 98 | #define glXGetClientString _glfw.glx.GetClientString 99 | #define glXQueryExtension _glfw.glx.QueryExtension 100 | #define glXQueryVersion _glfw.glx.QueryVersion 101 | #define glXDestroyContext _glfw.glx.DestroyContext 102 | #define glXMakeCurrent _glfw.glx.MakeCurrent 103 | #define glXSwapBuffers _glfw.glx.SwapBuffers 104 | #define glXQueryExtensionsString _glfw.glx.QueryExtensionsString 105 | #define glXCreateNewContext _glfw.glx.CreateNewContext 106 | #define glXGetVisualFromFBConfig _glfw.glx.GetVisualFromFBConfig 107 | #define glXCreateWindow _glfw.glx.CreateWindow 108 | #define glXDestroyWindow _glfw.glx.DestroyWindow 109 | 110 | #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextGLX glx 111 | #define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE _GLFWlibraryGLX glx 112 | 113 | 114 | // GLX-specific per-context data 115 | // 116 | typedef struct _GLFWcontextGLX 117 | { 118 | GLXContext handle; 119 | GLXWindow window; 120 | 121 | } _GLFWcontextGLX; 122 | 123 | // GLX-specific global data 124 | // 125 | typedef struct _GLFWlibraryGLX 126 | { 127 | int major, minor; 128 | int eventBase; 129 | int errorBase; 130 | 131 | // dlopen handle for libGL.so.1 132 | void* handle; 133 | 134 | // GLX 1.3 functions 135 | PFNGLXGETFBCONFIGSPROC GetFBConfigs; 136 | PFNGLXGETFBCONFIGATTRIBPROC GetFBConfigAttrib; 137 | PFNGLXGETCLIENTSTRINGPROC GetClientString; 138 | PFNGLXQUERYEXTENSIONPROC QueryExtension; 139 | PFNGLXQUERYVERSIONPROC QueryVersion; 140 | PFNGLXDESTROYCONTEXTPROC DestroyContext; 141 | PFNGLXMAKECURRENTPROC MakeCurrent; 142 | PFNGLXSWAPBUFFERSPROC SwapBuffers; 143 | PFNGLXQUERYEXTENSIONSSTRINGPROC QueryExtensionsString; 144 | PFNGLXCREATENEWCONTEXTPROC CreateNewContext; 145 | PFNGLXGETVISUALFROMFBCONFIGPROC GetVisualFromFBConfig; 146 | PFNGLXCREATEWINDOWPROC CreateWindow; 147 | PFNGLXDESTROYWINDOWPROC DestroyWindow; 148 | 149 | // GLX 1.4 and extension functions 150 | PFNGLXGETPROCADDRESSPROC GetProcAddress; 151 | PFNGLXGETPROCADDRESSPROC GetProcAddressARB; 152 | PFNGLXSWAPINTERVALSGIPROC SwapIntervalSGI; 153 | PFNGLXSWAPINTERVALEXTPROC SwapIntervalEXT; 154 | PFNGLXSWAPINTERVALMESAPROC SwapIntervalMESA; 155 | PFNGLXCREATECONTEXTATTRIBSARBPROC CreateContextAttribsARB; 156 | GLFWbool SGI_swap_control; 157 | GLFWbool EXT_swap_control; 158 | GLFWbool MESA_swap_control; 159 | GLFWbool ARB_multisample; 160 | GLFWbool ARB_framebuffer_sRGB; 161 | GLFWbool EXT_framebuffer_sRGB; 162 | GLFWbool ARB_create_context; 163 | GLFWbool ARB_create_context_profile; 164 | GLFWbool ARB_create_context_robustness; 165 | GLFWbool EXT_create_context_es2_profile; 166 | GLFWbool ARB_create_context_no_error; 167 | GLFWbool ARB_context_flush_control; 168 | 169 | } _GLFWlibraryGLX; 170 | 171 | GLFWbool _glfwInitGLX(void); 172 | void _glfwTerminateGLX(void); 173 | GLFWbool _glfwCreateContextGLX(_GLFWwindow* window, 174 | const _GLFWctxconfig* ctxconfig, 175 | const _GLFWfbconfig* fbconfig); 176 | void _glfwDestroyContextGLX(_GLFWwindow* window); 177 | GLFWbool _glfwChooseVisualGLX(const _GLFWwndconfig* wndconfig, 178 | const _GLFWctxconfig* ctxconfig, 179 | const _GLFWfbconfig* fbconfig, 180 | Visual** visual, int* depth); 181 | 182 | -------------------------------------------------------------------------------- /include/glfw-3.3.4/src/linux_joystick.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 Linux - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2014 Jonas Ådahl 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #define _GLFW_PLATFORM_JOYSTICK_STATE _GLFWjoystickLinux linjs 32 | #define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE _GLFWlibraryLinux linjs 33 | 34 | #define _GLFW_PLATFORM_MAPPING_NAME "Linux" 35 | 36 | // Linux-specific joystick data 37 | // 38 | typedef struct _GLFWjoystickLinux 39 | { 40 | int fd; 41 | char path[PATH_MAX]; 42 | int keyMap[KEY_CNT - BTN_MISC]; 43 | int absMap[ABS_CNT]; 44 | struct input_absinfo absInfo[ABS_CNT]; 45 | int hats[4][2]; 46 | } _GLFWjoystickLinux; 47 | 48 | // Linux-specific joystick API data 49 | // 50 | typedef struct _GLFWlibraryLinux 51 | { 52 | int inotify; 53 | int watch; 54 | regex_t regex; 55 | GLFWbool dropped; 56 | } _GLFWlibraryLinux; 57 | 58 | 59 | GLFWbool _glfwInitJoysticksLinux(void); 60 | void _glfwTerminateJoysticksLinux(void); 61 | void _glfwDetectJoystickConnectionLinux(void); 62 | 63 | -------------------------------------------------------------------------------- /include/glfw-3.3.4/src/mappings.h.in: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2006-2018 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | // As mappings.h.in, this file is used by CMake to produce the mappings.h 27 | // header file. If you are adding a GLFW specific gamepad mapping, this is 28 | // where to put it. 29 | //======================================================================== 30 | // As mappings.h, this provides all pre-defined gamepad mappings, including 31 | // all available in SDL_GameControllerDB. Do not edit this file. Any gamepad 32 | // mappings not specific to GLFW should be submitted to SDL_GameControllerDB. 33 | // This file can be re-generated from mappings.h.in and the upstream 34 | // gamecontrollerdb.txt with the GenerateMappings.cmake script. 35 | //======================================================================== 36 | 37 | // All gamepad mappings not labeled GLFW are copied from the 38 | // SDL_GameControllerDB project under the following license: 39 | // 40 | // Simple DirectMedia Layer 41 | // Copyright (C) 1997-2013 Sam Lantinga 42 | // 43 | // This software is provided 'as-is', without any express or implied warranty. 44 | // In no event will the authors be held liable for any damages arising from the 45 | // use of this software. 46 | // 47 | // Permission is granted to anyone to use this software for any purpose, 48 | // including commercial applications, and to alter it and redistribute it 49 | // freely, subject to the following restrictions: 50 | // 51 | // 1. The origin of this software must not be misrepresented; you must not 52 | // claim that you wrote the original software. If you use this software 53 | // in a product, an acknowledgment in the product documentation would 54 | // be appreciated but is not required. 55 | // 56 | // 2. Altered source versions must be plainly marked as such, and must not be 57 | // misrepresented as being the original software. 58 | // 59 | // 3. This notice may not be removed or altered from any source distribution. 60 | 61 | const char* _glfwDefaultMappings[] = 62 | { 63 | @GLFW_GAMEPAD_MAPPINGS@ 64 | "78696e70757401000000000000000000,XInput Gamepad (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,", 65 | "78696e70757402000000000000000000,XInput Wheel (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,", 66 | "78696e70757403000000000000000000,XInput Arcade Stick (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,", 67 | "78696e70757404000000000000000000,XInput Flight Stick (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,", 68 | "78696e70757405000000000000000000,XInput Dance Pad (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,", 69 | "78696e70757406000000000000000000,XInput Guitar (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,", 70 | "78696e70757408000000000000000000,XInput Drum Kit (GLFW),platform:Windows,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,back:b6,start:b7,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,", 71 | NULL 72 | }; 73 | 74 | -------------------------------------------------------------------------------- /include/glfw-3.3.4/src/nsgl_context.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 macOS - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2009-2019 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | // NOTE: Many Cocoa enum values have been renamed and we need to build across 28 | // SDK versions where one is unavailable or the other deprecated 29 | // We use the newer names in code and these macros to handle compatibility 30 | #if MAC_OS_X_VERSION_MAX_ALLOWED < 101400 31 | #define NSOpenGLContextParameterSwapInterval NSOpenGLCPSwapInterval 32 | #define NSOpenGLContextParameterSurfaceOpacity NSOpenGLCPSurfaceOpacity 33 | #endif 34 | 35 | #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextNSGL nsgl 36 | #define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE _GLFWlibraryNSGL nsgl 37 | 38 | #include 39 | 40 | 41 | // NSGL-specific per-context data 42 | // 43 | typedef struct _GLFWcontextNSGL 44 | { 45 | id pixelFormat; 46 | id object; 47 | 48 | } _GLFWcontextNSGL; 49 | 50 | // NSGL-specific global data 51 | // 52 | typedef struct _GLFWlibraryNSGL 53 | { 54 | // dlopen handle for OpenGL.framework (for glfwGetProcAddress) 55 | CFBundleRef framework; 56 | 57 | } _GLFWlibraryNSGL; 58 | 59 | 60 | GLFWbool _glfwInitNSGL(void); 61 | void _glfwTerminateNSGL(void); 62 | GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window, 63 | const _GLFWctxconfig* ctxconfig, 64 | const _GLFWfbconfig* fbconfig); 65 | void _glfwDestroyContextNSGL(_GLFWwindow* window); 66 | 67 | -------------------------------------------------------------------------------- /include/glfw-3.3.4/src/null_init.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2016 Google Inc. 5 | // Copyright (c) 2016-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | // It is fine to use C99 in this file because it will not be built with VS 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | 33 | ////////////////////////////////////////////////////////////////////////// 34 | ////// GLFW platform API ////// 35 | ////////////////////////////////////////////////////////////////////////// 36 | 37 | int _glfwPlatformInit(void) 38 | { 39 | _glfwInitTimerPOSIX(); 40 | return GLFW_TRUE; 41 | } 42 | 43 | void _glfwPlatformTerminate(void) 44 | { 45 | _glfwTerminateOSMesa(); 46 | } 47 | 48 | const char* _glfwPlatformGetVersionString(void) 49 | { 50 | return _GLFW_VERSION_NUMBER " null OSMesa"; 51 | } 52 | 53 | -------------------------------------------------------------------------------- /include/glfw-3.3.4/src/null_joystick.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2016-2017 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | // It is fine to use C99 in this file because it will not be built with VS 27 | //======================================================================== 28 | 29 | #include "internal.h" 30 | 31 | 32 | ////////////////////////////////////////////////////////////////////////// 33 | ////// GLFW platform API ////// 34 | ////////////////////////////////////////////////////////////////////////// 35 | 36 | int _glfwPlatformPollJoystick(_GLFWjoystick* js, int mode) 37 | { 38 | return GLFW_FALSE; 39 | } 40 | 41 | void _glfwPlatformUpdateGamepadGUID(char* guid) 42 | { 43 | } 44 | 45 | -------------------------------------------------------------------------------- /include/glfw-3.3.4/src/null_joystick.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2006-2017 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #define _GLFW_PLATFORM_JOYSTICK_STATE struct { int dummyJoystick; } 28 | #define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE struct { int dummyLibraryJoystick; } 29 | 30 | #define _GLFW_PLATFORM_MAPPING_NAME "" 31 | 32 | -------------------------------------------------------------------------------- /include/glfw-3.3.4/src/null_monitor.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2016 Google Inc. 5 | // Copyright (c) 2016-2019 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | // It is fine to use C99 in this file because it will not be built with VS 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | 33 | ////////////////////////////////////////////////////////////////////////// 34 | ////// GLFW platform API ////// 35 | ////////////////////////////////////////////////////////////////////////// 36 | 37 | void _glfwPlatformFreeMonitor(_GLFWmonitor* monitor) 38 | { 39 | } 40 | 41 | void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos) 42 | { 43 | } 44 | 45 | void _glfwPlatformGetMonitorContentScale(_GLFWmonitor* monitor, 46 | float* xscale, float* yscale) 47 | { 48 | if (xscale) 49 | *xscale = 1.f; 50 | if (yscale) 51 | *yscale = 1.f; 52 | } 53 | 54 | void _glfwPlatformGetMonitorWorkarea(_GLFWmonitor* monitor, 55 | int* xpos, int* ypos, 56 | int* width, int* height) 57 | { 58 | } 59 | 60 | GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found) 61 | { 62 | return NULL; 63 | } 64 | 65 | void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode) 66 | { 67 | } 68 | 69 | GLFWbool _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp) 70 | { 71 | return GLFW_FALSE; 72 | } 73 | 74 | void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp) 75 | { 76 | } 77 | 78 | -------------------------------------------------------------------------------- /include/glfw-3.3.4/src/null_platform.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2016 Google Inc. 5 | // Copyright (c) 2016-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #include 29 | 30 | #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowNull null 31 | 32 | #define _GLFW_PLATFORM_CONTEXT_STATE struct { int dummyContext; } 33 | #define _GLFW_PLATFORM_MONITOR_STATE struct { int dummyMonitor; } 34 | #define _GLFW_PLATFORM_CURSOR_STATE struct { int dummyCursor; } 35 | #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE struct { int dummyLibraryWindow; } 36 | #define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE struct { int dummyLibraryContext; } 37 | #define _GLFW_EGL_CONTEXT_STATE struct { int dummyEGLContext; } 38 | #define _GLFW_EGL_LIBRARY_CONTEXT_STATE struct { int dummyEGLLibraryContext; } 39 | 40 | #include "osmesa_context.h" 41 | #include "posix_time.h" 42 | #include "posix_thread.h" 43 | #include "null_joystick.h" 44 | 45 | #if defined(_GLFW_WIN32) 46 | #define _glfw_dlopen(name) LoadLibraryA(name) 47 | #define _glfw_dlclose(handle) FreeLibrary((HMODULE) handle) 48 | #define _glfw_dlsym(handle, name) GetProcAddress((HMODULE) handle, name) 49 | #else 50 | #define _glfw_dlopen(name) dlopen(name, RTLD_LAZY | RTLD_LOCAL) 51 | #define _glfw_dlclose(handle) dlclose(handle) 52 | #define _glfw_dlsym(handle, name) dlsym(handle, name) 53 | #endif 54 | 55 | // Null-specific per-window data 56 | // 57 | typedef struct _GLFWwindowNull 58 | { 59 | int width; 60 | int height; 61 | } _GLFWwindowNull; 62 | 63 | -------------------------------------------------------------------------------- /include/glfw-3.3.4/src/osmesa_context.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 OSMesa - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2016 Google Inc. 5 | // Copyright (c) 2016-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #define OSMESA_RGBA 0x1908 29 | #define OSMESA_FORMAT 0x22 30 | #define OSMESA_DEPTH_BITS 0x30 31 | #define OSMESA_STENCIL_BITS 0x31 32 | #define OSMESA_ACCUM_BITS 0x32 33 | #define OSMESA_PROFILE 0x33 34 | #define OSMESA_CORE_PROFILE 0x34 35 | #define OSMESA_COMPAT_PROFILE 0x35 36 | #define OSMESA_CONTEXT_MAJOR_VERSION 0x36 37 | #define OSMESA_CONTEXT_MINOR_VERSION 0x37 38 | 39 | typedef void* OSMesaContext; 40 | typedef void (*OSMESAproc)(void); 41 | 42 | typedef OSMesaContext (GLAPIENTRY * PFN_OSMesaCreateContextExt)(GLenum,GLint,GLint,GLint,OSMesaContext); 43 | typedef OSMesaContext (GLAPIENTRY * PFN_OSMesaCreateContextAttribs)(const int*,OSMesaContext); 44 | typedef void (GLAPIENTRY * PFN_OSMesaDestroyContext)(OSMesaContext); 45 | typedef int (GLAPIENTRY * PFN_OSMesaMakeCurrent)(OSMesaContext,void*,int,int,int); 46 | typedef int (GLAPIENTRY * PFN_OSMesaGetColorBuffer)(OSMesaContext,int*,int*,int*,void**); 47 | typedef int (GLAPIENTRY * PFN_OSMesaGetDepthBuffer)(OSMesaContext,int*,int*,int*,void**); 48 | typedef GLFWglproc (GLAPIENTRY * PFN_OSMesaGetProcAddress)(const char*); 49 | #define OSMesaCreateContextExt _glfw.osmesa.CreateContextExt 50 | #define OSMesaCreateContextAttribs _glfw.osmesa.CreateContextAttribs 51 | #define OSMesaDestroyContext _glfw.osmesa.DestroyContext 52 | #define OSMesaMakeCurrent _glfw.osmesa.MakeCurrent 53 | #define OSMesaGetColorBuffer _glfw.osmesa.GetColorBuffer 54 | #define OSMesaGetDepthBuffer _glfw.osmesa.GetDepthBuffer 55 | #define OSMesaGetProcAddress _glfw.osmesa.GetProcAddress 56 | 57 | #define _GLFW_OSMESA_CONTEXT_STATE _GLFWcontextOSMesa osmesa 58 | #define _GLFW_OSMESA_LIBRARY_CONTEXT_STATE _GLFWlibraryOSMesa osmesa 59 | 60 | 61 | // OSMesa-specific per-context data 62 | // 63 | typedef struct _GLFWcontextOSMesa 64 | { 65 | OSMesaContext handle; 66 | int width; 67 | int height; 68 | void* buffer; 69 | 70 | } _GLFWcontextOSMesa; 71 | 72 | // OSMesa-specific global data 73 | // 74 | typedef struct _GLFWlibraryOSMesa 75 | { 76 | void* handle; 77 | 78 | PFN_OSMesaCreateContextExt CreateContextExt; 79 | PFN_OSMesaCreateContextAttribs CreateContextAttribs; 80 | PFN_OSMesaDestroyContext DestroyContext; 81 | PFN_OSMesaMakeCurrent MakeCurrent; 82 | PFN_OSMesaGetColorBuffer GetColorBuffer; 83 | PFN_OSMesaGetDepthBuffer GetDepthBuffer; 84 | PFN_OSMesaGetProcAddress GetProcAddress; 85 | 86 | } _GLFWlibraryOSMesa; 87 | 88 | 89 | GLFWbool _glfwInitOSMesa(void); 90 | void _glfwTerminateOSMesa(void); 91 | GLFWbool _glfwCreateContextOSMesa(_GLFWwindow* window, 92 | const _GLFWctxconfig* ctxconfig, 93 | const _GLFWfbconfig* fbconfig); 94 | 95 | -------------------------------------------------------------------------------- /include/glfw-3.3.4/src/posix_thread.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | // It is fine to use C99 in this file because it will not be built with VS 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | #include 33 | #include 34 | 35 | 36 | ////////////////////////////////////////////////////////////////////////// 37 | ////// GLFW platform API ////// 38 | ////////////////////////////////////////////////////////////////////////// 39 | 40 | GLFWbool _glfwPlatformCreateTls(_GLFWtls* tls) 41 | { 42 | assert(tls->posix.allocated == GLFW_FALSE); 43 | 44 | if (pthread_key_create(&tls->posix.key, NULL) != 0) 45 | { 46 | _glfwInputError(GLFW_PLATFORM_ERROR, 47 | "POSIX: Failed to create context TLS"); 48 | return GLFW_FALSE; 49 | } 50 | 51 | tls->posix.allocated = GLFW_TRUE; 52 | return GLFW_TRUE; 53 | } 54 | 55 | void _glfwPlatformDestroyTls(_GLFWtls* tls) 56 | { 57 | if (tls->posix.allocated) 58 | pthread_key_delete(tls->posix.key); 59 | memset(tls, 0, sizeof(_GLFWtls)); 60 | } 61 | 62 | void* _glfwPlatformGetTls(_GLFWtls* tls) 63 | { 64 | assert(tls->posix.allocated == GLFW_TRUE); 65 | return pthread_getspecific(tls->posix.key); 66 | } 67 | 68 | void _glfwPlatformSetTls(_GLFWtls* tls, void* value) 69 | { 70 | assert(tls->posix.allocated == GLFW_TRUE); 71 | pthread_setspecific(tls->posix.key, value); 72 | } 73 | 74 | GLFWbool _glfwPlatformCreateMutex(_GLFWmutex* mutex) 75 | { 76 | assert(mutex->posix.allocated == GLFW_FALSE); 77 | 78 | if (pthread_mutex_init(&mutex->posix.handle, NULL) != 0) 79 | { 80 | _glfwInputError(GLFW_PLATFORM_ERROR, "POSIX: Failed to create mutex"); 81 | return GLFW_FALSE; 82 | } 83 | 84 | return mutex->posix.allocated = GLFW_TRUE; 85 | } 86 | 87 | void _glfwPlatformDestroyMutex(_GLFWmutex* mutex) 88 | { 89 | if (mutex->posix.allocated) 90 | pthread_mutex_destroy(&mutex->posix.handle); 91 | memset(mutex, 0, sizeof(_GLFWmutex)); 92 | } 93 | 94 | void _glfwPlatformLockMutex(_GLFWmutex* mutex) 95 | { 96 | assert(mutex->posix.allocated == GLFW_TRUE); 97 | pthread_mutex_lock(&mutex->posix.handle); 98 | } 99 | 100 | void _glfwPlatformUnlockMutex(_GLFWmutex* mutex) 101 | { 102 | assert(mutex->posix.allocated == GLFW_TRUE); 103 | pthread_mutex_unlock(&mutex->posix.handle); 104 | } 105 | 106 | -------------------------------------------------------------------------------- /include/glfw-3.3.4/src/posix_thread.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #include 29 | 30 | #define _GLFW_PLATFORM_TLS_STATE _GLFWtlsPOSIX posix 31 | #define _GLFW_PLATFORM_MUTEX_STATE _GLFWmutexPOSIX posix 32 | 33 | 34 | // POSIX-specific thread local storage data 35 | // 36 | typedef struct _GLFWtlsPOSIX 37 | { 38 | GLFWbool allocated; 39 | pthread_key_t key; 40 | 41 | } _GLFWtlsPOSIX; 42 | 43 | // POSIX-specific mutex data 44 | // 45 | typedef struct _GLFWmutexPOSIX 46 | { 47 | GLFWbool allocated; 48 | pthread_mutex_t handle; 49 | 50 | } _GLFWmutexPOSIX; 51 | 52 | -------------------------------------------------------------------------------- /include/glfw-3.3.4/src/posix_time.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | // It is fine to use C99 in this file because it will not be built with VS 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | #include 33 | #include 34 | 35 | 36 | ////////////////////////////////////////////////////////////////////////// 37 | ////// GLFW internal API ////// 38 | ////////////////////////////////////////////////////////////////////////// 39 | 40 | // Initialise timer 41 | // 42 | void _glfwInitTimerPOSIX(void) 43 | { 44 | #if defined(CLOCK_MONOTONIC) 45 | struct timespec ts; 46 | 47 | if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) 48 | { 49 | _glfw.timer.posix.monotonic = GLFW_TRUE; 50 | _glfw.timer.posix.frequency = 1000000000; 51 | } 52 | else 53 | #endif 54 | { 55 | _glfw.timer.posix.monotonic = GLFW_FALSE; 56 | _glfw.timer.posix.frequency = 1000000; 57 | } 58 | } 59 | 60 | 61 | ////////////////////////////////////////////////////////////////////////// 62 | ////// GLFW platform API ////// 63 | ////////////////////////////////////////////////////////////////////////// 64 | 65 | uint64_t _glfwPlatformGetTimerValue(void) 66 | { 67 | #if defined(CLOCK_MONOTONIC) 68 | if (_glfw.timer.posix.monotonic) 69 | { 70 | struct timespec ts; 71 | clock_gettime(CLOCK_MONOTONIC, &ts); 72 | return (uint64_t) ts.tv_sec * (uint64_t) 1000000000 + (uint64_t) ts.tv_nsec; 73 | } 74 | else 75 | #endif 76 | { 77 | struct timeval tv; 78 | gettimeofday(&tv, NULL); 79 | return (uint64_t) tv.tv_sec * (uint64_t) 1000000 + (uint64_t) tv.tv_usec; 80 | } 81 | } 82 | 83 | uint64_t _glfwPlatformGetTimerFrequency(void) 84 | { 85 | return _glfw.timer.posix.frequency; 86 | } 87 | 88 | -------------------------------------------------------------------------------- /include/glfw-3.3.4/src/posix_time.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #define _GLFW_PLATFORM_LIBRARY_TIMER_STATE _GLFWtimerPOSIX posix 29 | 30 | #include 31 | 32 | 33 | // POSIX-specific global timer data 34 | // 35 | typedef struct _GLFWtimerPOSIX 36 | { 37 | GLFWbool monotonic; 38 | uint64_t frequency; 39 | 40 | } _GLFWtimerPOSIX; 41 | 42 | 43 | void _glfwInitTimerPOSIX(void); 44 | 45 | -------------------------------------------------------------------------------- /include/glfw-3.3.4/src/wgl_context.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 WGL - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2018 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000 29 | #define WGL_SUPPORT_OPENGL_ARB 0x2010 30 | #define WGL_DRAW_TO_WINDOW_ARB 0x2001 31 | #define WGL_PIXEL_TYPE_ARB 0x2013 32 | #define WGL_TYPE_RGBA_ARB 0x202b 33 | #define WGL_ACCELERATION_ARB 0x2003 34 | #define WGL_NO_ACCELERATION_ARB 0x2025 35 | #define WGL_RED_BITS_ARB 0x2015 36 | #define WGL_RED_SHIFT_ARB 0x2016 37 | #define WGL_GREEN_BITS_ARB 0x2017 38 | #define WGL_GREEN_SHIFT_ARB 0x2018 39 | #define WGL_BLUE_BITS_ARB 0x2019 40 | #define WGL_BLUE_SHIFT_ARB 0x201a 41 | #define WGL_ALPHA_BITS_ARB 0x201b 42 | #define WGL_ALPHA_SHIFT_ARB 0x201c 43 | #define WGL_ACCUM_BITS_ARB 0x201d 44 | #define WGL_ACCUM_RED_BITS_ARB 0x201e 45 | #define WGL_ACCUM_GREEN_BITS_ARB 0x201f 46 | #define WGL_ACCUM_BLUE_BITS_ARB 0x2020 47 | #define WGL_ACCUM_ALPHA_BITS_ARB 0x2021 48 | #define WGL_DEPTH_BITS_ARB 0x2022 49 | #define WGL_STENCIL_BITS_ARB 0x2023 50 | #define WGL_AUX_BUFFERS_ARB 0x2024 51 | #define WGL_STEREO_ARB 0x2012 52 | #define WGL_DOUBLE_BUFFER_ARB 0x2011 53 | #define WGL_SAMPLES_ARB 0x2042 54 | #define WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB 0x20a9 55 | #define WGL_CONTEXT_DEBUG_BIT_ARB 0x00000001 56 | #define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x00000002 57 | #define WGL_CONTEXT_PROFILE_MASK_ARB 0x9126 58 | #define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001 59 | #define WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002 60 | #define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091 61 | #define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092 62 | #define WGL_CONTEXT_FLAGS_ARB 0x2094 63 | #define WGL_CONTEXT_ES2_PROFILE_BIT_EXT 0x00000004 64 | #define WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB 0x00000004 65 | #define WGL_LOSE_CONTEXT_ON_RESET_ARB 0x8252 66 | #define WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB 0x8256 67 | #define WGL_NO_RESET_NOTIFICATION_ARB 0x8261 68 | #define WGL_CONTEXT_RELEASE_BEHAVIOR_ARB 0x2097 69 | #define WGL_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB 0 70 | #define WGL_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB 0x2098 71 | #define WGL_CONTEXT_OPENGL_NO_ERROR_ARB 0x31b3 72 | #define WGL_COLORSPACE_EXT 0x309d 73 | #define WGL_COLORSPACE_SRGB_EXT 0x3089 74 | 75 | #define ERROR_INVALID_VERSION_ARB 0x2095 76 | #define ERROR_INVALID_PROFILE_ARB 0x2096 77 | #define ERROR_INCOMPATIBLE_DEVICE_CONTEXTS_ARB 0x2054 78 | 79 | // WGL extension pointer typedefs 80 | typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC)(int); 81 | typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVARBPROC)(HDC,int,int,UINT,const int*,int*); 82 | typedef const char* (WINAPI * PFNWGLGETEXTENSIONSSTRINGEXTPROC)(void); 83 | typedef const char* (WINAPI * PFNWGLGETEXTENSIONSSTRINGARBPROC)(HDC); 84 | typedef HGLRC (WINAPI * PFNWGLCREATECONTEXTATTRIBSARBPROC)(HDC,HGLRC,const int*); 85 | #define wglSwapIntervalEXT _glfw.wgl.SwapIntervalEXT 86 | #define wglGetPixelFormatAttribivARB _glfw.wgl.GetPixelFormatAttribivARB 87 | #define wglGetExtensionsStringEXT _glfw.wgl.GetExtensionsStringEXT 88 | #define wglGetExtensionsStringARB _glfw.wgl.GetExtensionsStringARB 89 | #define wglCreateContextAttribsARB _glfw.wgl.CreateContextAttribsARB 90 | 91 | // opengl32.dll function pointer typedefs 92 | typedef HGLRC (WINAPI * PFN_wglCreateContext)(HDC); 93 | typedef BOOL (WINAPI * PFN_wglDeleteContext)(HGLRC); 94 | typedef PROC (WINAPI * PFN_wglGetProcAddress)(LPCSTR); 95 | typedef HDC (WINAPI * PFN_wglGetCurrentDC)(void); 96 | typedef HGLRC (WINAPI * PFN_wglGetCurrentContext)(void); 97 | typedef BOOL (WINAPI * PFN_wglMakeCurrent)(HDC,HGLRC); 98 | typedef BOOL (WINAPI * PFN_wglShareLists)(HGLRC,HGLRC); 99 | #define wglCreateContext _glfw.wgl.CreateContext 100 | #define wglDeleteContext _glfw.wgl.DeleteContext 101 | #define wglGetProcAddress _glfw.wgl.GetProcAddress 102 | #define wglGetCurrentDC _glfw.wgl.GetCurrentDC 103 | #define wglGetCurrentContext _glfw.wgl.GetCurrentContext 104 | #define wglMakeCurrent _glfw.wgl.MakeCurrent 105 | #define wglShareLists _glfw.wgl.ShareLists 106 | 107 | #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextWGL wgl 108 | #define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE _GLFWlibraryWGL wgl 109 | 110 | 111 | // WGL-specific per-context data 112 | // 113 | typedef struct _GLFWcontextWGL 114 | { 115 | HDC dc; 116 | HGLRC handle; 117 | int interval; 118 | 119 | } _GLFWcontextWGL; 120 | 121 | // WGL-specific global data 122 | // 123 | typedef struct _GLFWlibraryWGL 124 | { 125 | HINSTANCE instance; 126 | PFN_wglCreateContext CreateContext; 127 | PFN_wglDeleteContext DeleteContext; 128 | PFN_wglGetProcAddress GetProcAddress; 129 | PFN_wglGetCurrentDC GetCurrentDC; 130 | PFN_wglGetCurrentContext GetCurrentContext; 131 | PFN_wglMakeCurrent MakeCurrent; 132 | PFN_wglShareLists ShareLists; 133 | 134 | PFNWGLSWAPINTERVALEXTPROC SwapIntervalEXT; 135 | PFNWGLGETPIXELFORMATATTRIBIVARBPROC GetPixelFormatAttribivARB; 136 | PFNWGLGETEXTENSIONSSTRINGEXTPROC GetExtensionsStringEXT; 137 | PFNWGLGETEXTENSIONSSTRINGARBPROC GetExtensionsStringARB; 138 | PFNWGLCREATECONTEXTATTRIBSARBPROC CreateContextAttribsARB; 139 | GLFWbool EXT_swap_control; 140 | GLFWbool EXT_colorspace; 141 | GLFWbool ARB_multisample; 142 | GLFWbool ARB_framebuffer_sRGB; 143 | GLFWbool EXT_framebuffer_sRGB; 144 | GLFWbool ARB_pixel_format; 145 | GLFWbool ARB_create_context; 146 | GLFWbool ARB_create_context_profile; 147 | GLFWbool EXT_create_context_es2_profile; 148 | GLFWbool ARB_create_context_robustness; 149 | GLFWbool ARB_create_context_no_error; 150 | GLFWbool ARB_context_flush_control; 151 | 152 | } _GLFWlibraryWGL; 153 | 154 | 155 | GLFWbool _glfwInitWGL(void); 156 | void _glfwTerminateWGL(void); 157 | GLFWbool _glfwCreateContextWGL(_GLFWwindow* window, 158 | const _GLFWctxconfig* ctxconfig, 159 | const _GLFWfbconfig* fbconfig); 160 | 161 | -------------------------------------------------------------------------------- /include/glfw-3.3.4/src/win32_joystick.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2006-2017 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #define _GLFW_PLATFORM_JOYSTICK_STATE _GLFWjoystickWin32 win32 28 | #define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE struct { int dummyLibraryJoystick; } 29 | 30 | #define _GLFW_PLATFORM_MAPPING_NAME "Windows" 31 | 32 | // Joystick element (axis, button or slider) 33 | // 34 | typedef struct _GLFWjoyobjectWin32 35 | { 36 | int offset; 37 | int type; 38 | } _GLFWjoyobjectWin32; 39 | 40 | // Win32-specific per-joystick data 41 | // 42 | typedef struct _GLFWjoystickWin32 43 | { 44 | _GLFWjoyobjectWin32* objects; 45 | int objectCount; 46 | IDirectInputDevice8W* device; 47 | DWORD index; 48 | GUID guid; 49 | } _GLFWjoystickWin32; 50 | 51 | 52 | void _glfwInitJoysticksWin32(void); 53 | void _glfwTerminateJoysticksWin32(void); 54 | void _glfwDetectJoystickConnectionWin32(void); 55 | void _glfwDetectJoystickDisconnectionWin32(void); 56 | 57 | -------------------------------------------------------------------------------- /include/glfw-3.3.4/src/win32_thread.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | // Please use C89 style variable declarations in this file because VS 2010 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | #include 33 | 34 | 35 | ////////////////////////////////////////////////////////////////////////// 36 | ////// GLFW platform API ////// 37 | ////////////////////////////////////////////////////////////////////////// 38 | 39 | GLFWbool _glfwPlatformCreateTls(_GLFWtls* tls) 40 | { 41 | assert(tls->win32.allocated == GLFW_FALSE); 42 | 43 | tls->win32.index = TlsAlloc(); 44 | if (tls->win32.index == TLS_OUT_OF_INDEXES) 45 | { 46 | _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, 47 | "Win32: Failed to allocate TLS index"); 48 | return GLFW_FALSE; 49 | } 50 | 51 | tls->win32.allocated = GLFW_TRUE; 52 | return GLFW_TRUE; 53 | } 54 | 55 | void _glfwPlatformDestroyTls(_GLFWtls* tls) 56 | { 57 | if (tls->win32.allocated) 58 | TlsFree(tls->win32.index); 59 | memset(tls, 0, sizeof(_GLFWtls)); 60 | } 61 | 62 | void* _glfwPlatformGetTls(_GLFWtls* tls) 63 | { 64 | assert(tls->win32.allocated == GLFW_TRUE); 65 | return TlsGetValue(tls->win32.index); 66 | } 67 | 68 | void _glfwPlatformSetTls(_GLFWtls* tls, void* value) 69 | { 70 | assert(tls->win32.allocated == GLFW_TRUE); 71 | TlsSetValue(tls->win32.index, value); 72 | } 73 | 74 | GLFWbool _glfwPlatformCreateMutex(_GLFWmutex* mutex) 75 | { 76 | assert(mutex->win32.allocated == GLFW_FALSE); 77 | InitializeCriticalSection(&mutex->win32.section); 78 | return mutex->win32.allocated = GLFW_TRUE; 79 | } 80 | 81 | void _glfwPlatformDestroyMutex(_GLFWmutex* mutex) 82 | { 83 | if (mutex->win32.allocated) 84 | DeleteCriticalSection(&mutex->win32.section); 85 | memset(mutex, 0, sizeof(_GLFWmutex)); 86 | } 87 | 88 | void _glfwPlatformLockMutex(_GLFWmutex* mutex) 89 | { 90 | assert(mutex->win32.allocated == GLFW_TRUE); 91 | EnterCriticalSection(&mutex->win32.section); 92 | } 93 | 94 | void _glfwPlatformUnlockMutex(_GLFWmutex* mutex) 95 | { 96 | assert(mutex->win32.allocated == GLFW_TRUE); 97 | LeaveCriticalSection(&mutex->win32.section); 98 | } 99 | 100 | -------------------------------------------------------------------------------- /include/glfw-3.3.4/src/win32_time.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | // Please use C89 style variable declarations in this file because VS 2010 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | 33 | ////////////////////////////////////////////////////////////////////////// 34 | ////// GLFW internal API ////// 35 | ////////////////////////////////////////////////////////////////////////// 36 | 37 | // Initialise timer 38 | // 39 | void _glfwInitTimerWin32(void) 40 | { 41 | uint64_t frequency; 42 | 43 | if (QueryPerformanceFrequency((LARGE_INTEGER*) &frequency)) 44 | { 45 | _glfw.timer.win32.hasPC = GLFW_TRUE; 46 | _glfw.timer.win32.frequency = frequency; 47 | } 48 | else 49 | { 50 | _glfw.timer.win32.hasPC = GLFW_FALSE; 51 | _glfw.timer.win32.frequency = 1000; 52 | } 53 | } 54 | 55 | 56 | ////////////////////////////////////////////////////////////////////////// 57 | ////// GLFW platform API ////// 58 | ////////////////////////////////////////////////////////////////////////// 59 | 60 | uint64_t _glfwPlatformGetTimerValue(void) 61 | { 62 | if (_glfw.timer.win32.hasPC) 63 | { 64 | uint64_t value; 65 | QueryPerformanceCounter((LARGE_INTEGER*) &value); 66 | return value; 67 | } 68 | else 69 | return (uint64_t) timeGetTime(); 70 | } 71 | 72 | uint64_t _glfwPlatformGetTimerFrequency(void) 73 | { 74 | return _glfw.timer.win32.frequency; 75 | } 76 | 77 | -------------------------------------------------------------------------------- /include/glfw-3.3.4/src/wl_monitor.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 Wayland - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2014 Jonas Ådahl 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | // It is fine to use C99 in this file because it will not be built with VS 27 | //======================================================================== 28 | 29 | #include "internal.h" 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | 38 | static void outputHandleGeometry(void* data, 39 | struct wl_output* output, 40 | int32_t x, 41 | int32_t y, 42 | int32_t physicalWidth, 43 | int32_t physicalHeight, 44 | int32_t subpixel, 45 | const char* make, 46 | const char* model, 47 | int32_t transform) 48 | { 49 | struct _GLFWmonitor *monitor = data; 50 | char name[1024]; 51 | 52 | monitor->wl.x = x; 53 | monitor->wl.y = y; 54 | monitor->widthMM = physicalWidth; 55 | monitor->heightMM = physicalHeight; 56 | 57 | snprintf(name, sizeof(name), "%s %s", make, model); 58 | monitor->name = _glfw_strdup(name); 59 | } 60 | 61 | static void outputHandleMode(void* data, 62 | struct wl_output* output, 63 | uint32_t flags, 64 | int32_t width, 65 | int32_t height, 66 | int32_t refresh) 67 | { 68 | struct _GLFWmonitor *monitor = data; 69 | GLFWvidmode mode; 70 | 71 | mode.width = width; 72 | mode.height = height; 73 | mode.redBits = 8; 74 | mode.greenBits = 8; 75 | mode.blueBits = 8; 76 | mode.refreshRate = (int) round(refresh / 1000.0); 77 | 78 | monitor->modeCount++; 79 | monitor->modes = 80 | realloc(monitor->modes, monitor->modeCount * sizeof(GLFWvidmode)); 81 | monitor->modes[monitor->modeCount - 1] = mode; 82 | 83 | if (flags & WL_OUTPUT_MODE_CURRENT) 84 | monitor->wl.currentMode = monitor->modeCount - 1; 85 | } 86 | 87 | static void outputHandleDone(void* data, struct wl_output* output) 88 | { 89 | struct _GLFWmonitor *monitor = data; 90 | 91 | if (monitor->widthMM <= 0 || monitor->heightMM <= 0) 92 | { 93 | // If Wayland does not provide a physical size, assume the default 96 DPI 94 | const GLFWvidmode* mode = &monitor->modes[monitor->wl.currentMode]; 95 | monitor->widthMM = (int) (mode->width * 25.4f / 96.f); 96 | monitor->heightMM = (int) (mode->height * 25.4f / 96.f); 97 | } 98 | 99 | _glfwInputMonitor(monitor, GLFW_CONNECTED, _GLFW_INSERT_LAST); 100 | } 101 | 102 | static void outputHandleScale(void* data, 103 | struct wl_output* output, 104 | int32_t factor) 105 | { 106 | struct _GLFWmonitor *monitor = data; 107 | 108 | monitor->wl.scale = factor; 109 | } 110 | 111 | static const struct wl_output_listener outputListener = { 112 | outputHandleGeometry, 113 | outputHandleMode, 114 | outputHandleDone, 115 | outputHandleScale, 116 | }; 117 | 118 | 119 | ////////////////////////////////////////////////////////////////////////// 120 | ////// GLFW internal API ////// 121 | ////////////////////////////////////////////////////////////////////////// 122 | 123 | void _glfwAddOutputWayland(uint32_t name, uint32_t version) 124 | { 125 | _GLFWmonitor *monitor; 126 | struct wl_output *output; 127 | 128 | if (version < 2) 129 | { 130 | _glfwInputError(GLFW_PLATFORM_ERROR, 131 | "Wayland: Unsupported output interface version"); 132 | return; 133 | } 134 | 135 | // The actual name of this output will be set in the geometry handler. 136 | monitor = _glfwAllocMonitor(NULL, 0, 0); 137 | 138 | output = wl_registry_bind(_glfw.wl.registry, 139 | name, 140 | &wl_output_interface, 141 | 2); 142 | if (!output) 143 | { 144 | _glfwFreeMonitor(monitor); 145 | return; 146 | } 147 | 148 | monitor->wl.scale = 1; 149 | monitor->wl.output = output; 150 | monitor->wl.name = name; 151 | 152 | wl_output_add_listener(output, &outputListener, monitor); 153 | } 154 | 155 | 156 | ////////////////////////////////////////////////////////////////////////// 157 | ////// GLFW platform API ////// 158 | ////////////////////////////////////////////////////////////////////////// 159 | 160 | void _glfwPlatformFreeMonitor(_GLFWmonitor* monitor) 161 | { 162 | if (monitor->wl.output) 163 | wl_output_destroy(monitor->wl.output); 164 | } 165 | 166 | void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos) 167 | { 168 | if (xpos) 169 | *xpos = monitor->wl.x; 170 | if (ypos) 171 | *ypos = monitor->wl.y; 172 | } 173 | 174 | void _glfwPlatformGetMonitorContentScale(_GLFWmonitor* monitor, 175 | float* xscale, float* yscale) 176 | { 177 | if (xscale) 178 | *xscale = (float) monitor->wl.scale; 179 | if (yscale) 180 | *yscale = (float) monitor->wl.scale; 181 | } 182 | 183 | void _glfwPlatformGetMonitorWorkarea(_GLFWmonitor* monitor, 184 | int* xpos, int* ypos, 185 | int* width, int* height) 186 | { 187 | if (xpos) 188 | *xpos = monitor->wl.x; 189 | if (ypos) 190 | *ypos = monitor->wl.y; 191 | if (width) 192 | *width = monitor->modes[monitor->wl.currentMode].width; 193 | if (height) 194 | *height = monitor->modes[monitor->wl.currentMode].height; 195 | } 196 | 197 | GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found) 198 | { 199 | *found = monitor->modeCount; 200 | return monitor->modes; 201 | } 202 | 203 | void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode) 204 | { 205 | *mode = monitor->modes[monitor->wl.currentMode]; 206 | } 207 | 208 | GLFWbool _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp) 209 | { 210 | _glfwInputError(GLFW_PLATFORM_ERROR, 211 | "Wayland: Gamma ramp access is not available"); 212 | return GLFW_FALSE; 213 | } 214 | 215 | void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, 216 | const GLFWgammaramp* ramp) 217 | { 218 | _glfwInputError(GLFW_PLATFORM_ERROR, 219 | "Wayland: Gamma ramp access is not available"); 220 | } 221 | 222 | 223 | ////////////////////////////////////////////////////////////////////////// 224 | ////// GLFW native API ////// 225 | ////////////////////////////////////////////////////////////////////////// 226 | 227 | GLFWAPI struct wl_output* glfwGetWaylandMonitor(GLFWmonitor* handle) 228 | { 229 | _GLFWmonitor* monitor = (_GLFWmonitor*) handle; 230 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 231 | return monitor->wl.output; 232 | } 233 | 234 | -------------------------------------------------------------------------------- /include/glfw-3.3.4/src/xkb_unicode.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.3 Linux - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2014 Jonas Ådahl 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | long _glfwKeySym2Unicode(unsigned int keysym); 28 | 29 | -------------------------------------------------------------------------------- /include/onefile/GLAD/gl.c: -------------------------------------------------------------------------------- 1 | #define GLAD_GL_IMPLEMENTATION 2 | #include "gl.h" 3 | 4 | -------------------------------------------------------------------------------- /include/onefile/GLAD/glx.c: -------------------------------------------------------------------------------- 1 | #if !defined(_WIN32) 2 | #define GLAD_GLX_IMPLEMENTATION 3 | #include "glx.h" 4 | #endif 5 | 6 | -------------------------------------------------------------------------------- /include/onefile/stb/image.c: -------------------------------------------------------------------------------- 1 | #define STB_IMAGE_IMPLEMENTATION 2 | #include "image.h" 3 | -------------------------------------------------------------------------------- /include/onefile/stb/rect_pack.c: -------------------------------------------------------------------------------- 1 | #define STB_RECT_PACK_IMPLEMENTATION 2 | #include "rect_pack.h" -------------------------------------------------------------------------------- /include/onefile/stb/truetype.c: -------------------------------------------------------------------------------- 1 | #define STB_TRUETYPE_IMPLEMENTATION 2 | #include "rect_pack.h" 3 | #include "truetype.h" -------------------------------------------------------------------------------- /libbuild.zig: -------------------------------------------------------------------------------- 1 | // ----------------------------------------- 2 | // | Alka 1.0.0 | 3 | // ----------------------------------------- 4 | // 5 | //Copyright © 2020-2021 Mehmet Kaan Uluç 6 | // 7 | //This software is provided 'as-is', without any express or implied 8 | //warranty. In no event will the authors be held liable for any damages 9 | //arising from the use of this software. 10 | // 11 | //Permission is granted to anyone to use this software for any purpose, 12 | //including commercial applications, and to alter it and redistribute it 13 | //freely, subject to the following restrictions: 14 | // 15 | //1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | //2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | //3. This notice may not be removed or altered from any source 24 | // distribution. 25 | 26 | const std = @import("std"); 27 | const Builder = @import("std").build.Builder; 28 | const Build = @import("std").build; 29 | const Builtin = @import("std").builtin; 30 | const Zig = @import("std").zig; 31 | 32 | const globalflags = [_][]const u8{"-std=c99"}; 33 | 34 | pub var strip = false; 35 | 36 | pub fn compileGLFWWin32(exe: *Build.LibExeObjStep, comptime engine_path: []const u8) void { 37 | const flags = [_][]const u8{"-O2"} ++ globalflags; 38 | exe.linkSystemLibrary("gdi32"); 39 | exe.linkSystemLibrary("opengl32"); 40 | 41 | exe.defineCMacro("_GLFW_WIN32"); 42 | 43 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/wgl_context.c", &flags); 44 | 45 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/win32_init.c", &flags); 46 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/win32_joystick.c", &flags); 47 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/win32_monitor.c", &flags); 48 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/win32_thread.c", &flags); 49 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/win32_time.c", &flags); 50 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/win32_window.c", &flags); 51 | } 52 | 53 | pub fn compileGLFWLinux(exe: *Build.LibExeObjStep, comptime engine_path: []const u8) void { 54 | const flags = [_][]const u8{"-O2"} ++ globalflags; 55 | exe.linkSystemLibrary("X11"); 56 | 57 | exe.defineCMacro("_GLFW_X11"); 58 | 59 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/glx_context.c", &flags); 60 | 61 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/posix_thread.c", &flags); 62 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/posix_time.c", &flags); 63 | 64 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/x11_init.c", &flags); 65 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/x11_window.c", &flags); 66 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/x11_monitor.c", &flags); 67 | 68 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/xkb_unicode.c", &flags); 69 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/linux_joystick.c", &flags); 70 | } 71 | 72 | pub fn compileGLFWShared(exe: *Build.LibExeObjStep, comptime engine_path: []const u8) void { 73 | const flags = [_][]const u8{"-O2"} ++ globalflags; 74 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/init.c", &flags); 75 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/context.c", &flags); 76 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/input.c", &flags); 77 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/monitor.c", &flags); 78 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/window.c", &flags); 79 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/vulkan.c", &flags); 80 | 81 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/osmesa_context.c", &flags); 82 | exe.addCSourceFile(engine_path ++ "include/glfw-3.3.4/src/egl_context.c", &flags); 83 | } 84 | 85 | pub fn compileOneFile(exe: *Build.LibExeObjStep, comptime engine_path: []const u8) void { 86 | const flags = [_][]const u8{"-O3"} ++ globalflags; 87 | exe.addCSourceFile(engine_path ++ "include/onefile/GLAD/gl.c", &flags); 88 | exe.addCSourceFile(engine_path ++ "include/onefile/stb/image.c", &flags); 89 | exe.addCSourceFile(engine_path ++ "include/onefile/stb/rect_pack.c", &flags); 90 | exe.addCSourceFile(engine_path ++ "include/onefile/stb/truetype.c", &flags); 91 | exe.addCSourceFile(engine_path ++ "src/core/private.c", &flags); 92 | } 93 | 94 | pub fn include(exe: *Build.LibExeObjStep, comptime engine_path: []const u8) void { 95 | exe.addIncludeDir(engine_path ++ "include/glfw-3.3.4/include/"); 96 | exe.addIncludeDir(engine_path ++ "include/onefile/"); 97 | } 98 | 99 | pub fn setup(b: *Builder, target: Zig.CrossTarget, gamename: []const u8, gamepath: []const u8, comptime engine_path: []const u8) *Build.LibExeObjStep { 100 | const exe = b.addExecutable(gamename, gamepath); 101 | 102 | exe.addPackagePath("alka", engine_path ++ "src/alka.zig"); 103 | 104 | exe.strip = strip; 105 | exe.linkSystemLibrary("c"); 106 | 107 | include(exe, engine_path); 108 | 109 | compileOneFile(exe, engine_path); 110 | 111 | const target_os = target.getOsTag(); 112 | switch (target_os) { 113 | .windows => { 114 | exe.setTarget(target); 115 | 116 | exe.linkSystemLibrary("gdi32"); 117 | exe.linkSystemLibrary("opengl32"); 118 | 119 | exe.subsystem = .Console; 120 | 121 | compileGLFWWin32(exe, engine_path); 122 | }, 123 | .linux => { 124 | exe.setTarget(target); 125 | exe.linkSystemLibrary("X11"); 126 | 127 | compileGLFWLinux(exe, engine_path); 128 | }, 129 | else => {}, 130 | } 131 | 132 | compileGLFWShared(exe, engine_path); 133 | 134 | return exe; 135 | } 136 | -------------------------------------------------------------------------------- /src/core/audio/audio.zig: -------------------------------------------------------------------------------- 1 | //Copyright © 2020-2021 Mehmet Kaan Uluç 2 | // 3 | //This software is provided 'as-is', without any express or implied 4 | //warranty. In no event will the authors be held liable for any damages 5 | //arising from the use of this software. 6 | // 7 | //Permission is granted to anyone to use this software for any purpose, 8 | //including commercial applications, and to alter it and redistribute it 9 | //freely, subject to the following restrictions: 10 | // 11 | //1. The origin of this software must not be misrepresented; you must not 12 | // claim that you wrote the original software. If you use this software 13 | // in a product, an acknowledgment in the product documentation would 14 | // be appreciated but is not required. 15 | // 16 | //2. Altered source versions must be plainly marked as such, and must not 17 | // be misrepresented as being the original software. 18 | // 19 | //3. This notice may not be removed or altered from any source 20 | // distribution. 21 | 22 | const std = @import("std"); 23 | const c = @import("../c.zig"); 24 | 25 | const aloga = std.log.scoped(.nil_core_audio); 26 | 27 | pub const Error = error{ 28 | FailedToInitializeDevice, 29 | }; 30 | 31 | /// Initializes the audio devices 32 | pub fn initDevices() Error!void {} 33 | 34 | /// Denitializes the audio devices 35 | pub fn deinitDevices() void {} 36 | -------------------------------------------------------------------------------- /src/core/c.zig: -------------------------------------------------------------------------------- 1 | //Copyright © 2020-2021 Mehmet Kaan Uluç 2 | // 3 | //This software is provided 'as-is', without any express or implied 4 | //warranty. In no event will the authors be held liable for any damages 5 | //arising from the use of this software. 6 | // 7 | //Permission is granted to anyone to use this software for any purpose, 8 | //including commercial applications, and to alter it and redistribute it 9 | //freely, subject to the following restrictions: 10 | // 11 | //1. The origin of this software must not be misrepresented; you must not 12 | // claim that you wrote the original software. If you use this software 13 | // in a product, an acknowledgment in the product documentation would 14 | // be appreciated but is not required. 15 | // 16 | //2. Altered source versions must be plainly marked as such, and must not 17 | // be misrepresented as being the original software. 18 | // 19 | //3. This notice may not be removed or altered from any source 20 | // distribution. 21 | 22 | pub usingnamespace @cImport({ 23 | @cInclude("GLAD/gl.h"); 24 | @cInclude("GLFW/glfw3.h"); 25 | @cInclude("stb/image.h"); 26 | @cInclude("stb/truetype.h"); 27 | @cInclude("stb/rect_pack.h"); 28 | }); 29 | -------------------------------------------------------------------------------- /src/core/core.zig: -------------------------------------------------------------------------------- 1 | //Copyright © 2020-2021 Mehmet Kaan Uluç 2 | // 3 | //This software is provided 'as-is', without any express or implied 4 | //warranty. In no event will the authors be held liable for any damages 5 | //arising from the use of this software. 6 | // 7 | //Permission is granted to anyone to use this software for any purpose, 8 | //including commercial applications, and to alter it and redistribute it 9 | //freely, subject to the following restrictions: 10 | // 11 | //1. The origin of this software must not be misrepresented; you must not 12 | // claim that you wrote the original software. If you use this software 13 | // in a product, an acknowledgment in the product documentation would 14 | // be appreciated but is not required. 15 | // 16 | //2. Altered source versions must be plainly marked as such, and must not 17 | // be misrepresented as being the original software. 18 | // 19 | //3. This notice may not be removed or altered from any source 20 | // distribution. 21 | 22 | pub const c = @import("c.zig"); 23 | pub const gl = @import("gl.zig"); 24 | pub const fs = @import("fs.zig"); 25 | pub const utf8 = @import("utf8.zig"); 26 | pub const utils = @import("utils.zig"); 27 | pub const audio = @import("audio/audio.zig"); 28 | pub const ecs = @import("ecs.zig"); 29 | pub const math = @import("math/math.zig"); 30 | pub const glfw = @import("glfw.zig"); 31 | pub const input = @import("input.zig"); 32 | pub const log = @import("log.zig"); 33 | pub const renderer = @import("renderer.zig"); 34 | pub const window = @import("window.zig"); 35 | 36 | pub const Error = gl.Error || fs.Error || utils.Error || audio.Error || ecs.Error || glfw.GLFWError || input.Error || renderer.Error || window.Error; 37 | -------------------------------------------------------------------------------- /src/core/fs.zig: -------------------------------------------------------------------------------- 1 | //Copyright © 2020-2021 Mehmet Kaan Uluç 2 | // 3 | //This software is provided 'as-is', without any express or implied 4 | //warranty. In no event will the authors be held liable for any damages 5 | //arising from the use of this software. 6 | // 7 | //Permission is granted to anyone to use this software for any purpose, 8 | //including commercial applications, and to alter it and redistribute it 9 | //freely, subject to the following restrictions: 10 | // 11 | //1. The origin of this software must not be misrepresented; you must not 12 | // claim that you wrote the original software. If you use this software 13 | // in a product, an acknowledgment in the product documentation would 14 | // be appreciated but is not required. 15 | // 16 | //2. Altered source versions must be plainly marked as such, and must not 17 | // be misrepresented as being the original software. 18 | // 19 | //3. This notice may not be removed or altered from any source 20 | // distribution. 21 | 22 | const std = @import("std"); 23 | pub const Error = error{ FailedToReadFile, FailedToWriteFile }; 24 | 25 | pub fn readFile(alloc: *std.mem.Allocator, path: []const u8) Error![]u8 { 26 | var f = std.fs.cwd().openFile(path, .{ .read = true }) catch return Error.FailedToReadFile; 27 | defer f.close(); 28 | 29 | f.seekFromEnd(0) catch return Error.FailedToReadFile; 30 | const size = f.getPos() catch return Error.FailedToReadFile; 31 | f.seekTo(0) catch return Error.FailedToReadFile; 32 | var mem = f.readToEndAlloc(alloc, size) catch return Error.FailedToReadFile; 33 | return mem; 34 | } 35 | 36 | pub fn writeFile(path: []const u8, data: []const u8) Error!void { 37 | var f = std.fs.cwd().openFile(path, .{ .write = true }) catch return Error.FailedToReadFile; 38 | defer f.close(); 39 | 40 | f.write(data) catch return Error.FailedToWriteFile; 41 | } 42 | -------------------------------------------------------------------------------- /src/core/log.zig: -------------------------------------------------------------------------------- 1 | //Copyright © 2020-2021 Mehmet Kaan Uluç 2 | // 3 | //This software is provided 'as-is', without any express or implied 4 | //warranty. In no event will the authors be held liable for any damages 5 | //arising from the use of this software. 6 | // 7 | //Permission is granted to anyone to use this software for any purpose, 8 | //including commercial applications, and to alter it and redistribute it 9 | //freely, subject to the following restrictions: 10 | // 11 | //1. The origin of this software must not be misrepresented; you must not 12 | // claim that you wrote the original software. If you use this software 13 | // in a product, an acknowledgment in the product documentation would 14 | // be appreciated but is not required. 15 | // 16 | //2. Altered source versions must be plainly marked as such, and must not 17 | // be misrepresented as being the original software. 18 | // 19 | //3. This notice may not be removed or altered from any source 20 | // distribution. 21 | 22 | const std = @import("std"); 23 | const util = @import("utils.zig"); 24 | 25 | const log_coloured = comptime if (std.Target.current.os.tag == .linux) true else false; 26 | 27 | // Source: https://en.wikipedia.org/wiki/ANSI_escape_code#Colors 28 | /// Static colour defines 29 | const colours = comptime [_][]const u8{ 30 | "\x1b[1;31m", // emerg 31 | "\x1b[1;91m", // alert 32 | "\x1b[1;35m", // crit 33 | "\x1b[95m", // err 34 | "\x1b[93m", // warn 35 | "\x1b[32m", // notice 36 | "\x1b[94m", // info 37 | "\x1b[36m", // debug 38 | }; 39 | 40 | const colour_reset = "\x1b[0m"; 41 | const colour_gray = "\x1b[90m"; 42 | const colour_white = "\x1b[97m"; 43 | 44 | // Define root.log to override the std implementation 45 | pub fn log( 46 | comptime level: std.log.Level, 47 | comptime scope: @TypeOf(.EnumLiteral), 48 | comptime format: []const u8, 49 | args: anytype, 50 | ) void { 51 | const held = std.debug.getStderrMutex().acquire(); 52 | defer held.release(); 53 | const stderr = std.io.getStdErr().writer(); 54 | 55 | if (!log_coloured) { 56 | const scope_prefix = "(" ++ @tagName(scope) ++ ") -> "; 57 | const prefix = "[" ++ @tagName(level) ++ "] " ++ scope_prefix; 58 | 59 | nosuspend stderr.print(prefix ++ format ++ "\n", args) catch return; 60 | } else { 61 | const scope_prefix = "(" ++ @tagName(scope) ++ ")" ++ "\x1b[37m" ++ " -> "; 62 | const prefix = "[" ++ colours[@enumToInt(level)] ++ @tagName(level) ++ colour_reset ++ "] " ++ colour_gray ++ scope_prefix ++ colour_reset; 63 | 64 | nosuspend stderr.print(prefix ++ colour_white ++ format ++ "\n" ++ colour_reset, args) catch return; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/core/math/common.zig: -------------------------------------------------------------------------------- 1 | //Copyright © 2020-2021 Mehmet Kaan Uluç 2 | // 3 | //This software is provided 'as-is', without any express or implied 4 | //warranty. In no event will the authors be held liable for any damages 5 | //arising from the use of this software. 6 | // 7 | //Permission is granted to anyone to use this software for any purpose, 8 | //including commercial applications, and to alter it and redistribute it 9 | //freely, subject to the following restrictions: 10 | // 11 | //1. The origin of this software must not be misrepresented; you must not 12 | // claim that you wrote the original software. If you use this software 13 | // in a product, an acknowledgment in the product documentation would 14 | // be appreciated but is not required. 15 | // 16 | //2. Altered source versions must be plainly marked as such, and must not 17 | // be misrepresented as being the original software. 18 | // 19 | //3. This notice may not be removed or altered from any source 20 | // distribution. 21 | 22 | const assert = @import("std").debug.assert; 23 | pub const PI = comptime 3.14159265358979323846; 24 | 25 | /// Convert degree to radians 26 | pub fn deg2radf(deg: f32) f32 { 27 | var ndeg = deg; 28 | if (ndeg > 360) { 29 | ndeg -= 360; 30 | if (ndeg > 360) return deg2radf(ndeg); 31 | } 32 | return ndeg * (PI / 180.0); 33 | } 34 | 35 | /// Convert radians to degree 36 | pub fn rad2degf(rad: f32) f32 { 37 | return rad * (180.0 / PI); 38 | } 39 | 40 | /// Find minimum value 41 | pub fn min(value1: anytype, value2: anytype) @TypeOf(value1) { 42 | return if (value1 < value2) value1 else value2; 43 | } 44 | 45 | /// Find maximum value 46 | pub fn max(value1: anytype, value2: anytype) @TypeOf(value1) { 47 | return if (value1 < value2) value2 else value1; 48 | } 49 | 50 | /// Clamp value 51 | pub fn clamp(value: anytype, low: anytype, high: anytype) @TypeOf(value) { 52 | assert(low <= high); 53 | return if (value < low) low else if (high < value) high else value; 54 | } 55 | 56 | /// Calculate linear interpolation between two value 57 | pub fn lerp(start: anytype, end: anytype, amount: anytype) @TypeOf(start) { 58 | return start + amount * (end - start); 59 | } 60 | 61 | /// Normalize input value within input range 62 | pub fn normalize(value: anytype, start: anytype, end: anytype) @TypeOf(value) { 63 | return (value - start) / (end - start); 64 | } 65 | 66 | /// Remap input value within input range to output range 67 | pub fn remap(value: anytype, inputStart: anytype, inputEnd: anytype, outputStart: anytype, outputEnd: anytype) @TypeOf(value) { 68 | return (value - inputStart) / (inputEnd - inputStart) * (outputEnd - outputStart) + outputStart; 69 | } 70 | 71 | /// Returns the absolute value 72 | pub fn abs(value: anytype) @TypeOf(value) { 73 | return if (value >= 0) value else -value; 74 | } 75 | 76 | /// AABB collision check 77 | pub fn aabb(x0: anytype, y0: anytype, w0: anytype, h0: anytype, x1: anytype, y1: anytype, w1: anytype, h1: anytype) bool { 78 | return if (x0 < x1 + w1 and 79 | x1 < x0 + w0 and 80 | y0 < y1 + h1 and 81 | y1 < y0 + h0) true else false; 82 | } 83 | 84 | /// AABB collision check 85 | pub fn aabbMeeting(meetx: anytype, meety: anytype, x0: anytype, y0: anytype, w0: anytype, h0: anytype, x1: anytype, y1: anytype, w1: anytype, h1: anytype) bool { 86 | return if (x0 + meetx < x1 + w1 and 87 | x1 < x0 + w0 + meetx and 88 | y0 + meety < y1 + h1 and 89 | y1 < y0 + h0 + meety) true else false; 90 | } 91 | -------------------------------------------------------------------------------- /src/core/math/math.zig: -------------------------------------------------------------------------------- 1 | //Copyright © 2020-2021 Mehmet Kaan Uluç 2 | // 3 | //This software is provided 'as-is', without any express or implied 4 | //warranty. In no event will the authors be held liable for any damages 5 | //arising from the use of this software. 6 | // 7 | //Permission is granted to anyone to use this software for any purpose, 8 | //including commercial applications, and to alter it and redistribute it 9 | //freely, subject to the following restrictions: 10 | // 11 | //1. The origin of this software must not be misrepresented; you must not 12 | // claim that you wrote the original software. If you use this software 13 | // in a product, an acknowledgment in the product documentation would 14 | // be appreciated but is not required. 15 | // 16 | //2. Altered source versions must be plainly marked as such, and must not 17 | // be misrepresented as being the original software. 18 | // 19 | //3. This notice may not be removed or altered from any source 20 | // distribution. 21 | 22 | pub usingnamespace @import("common.zig"); 23 | const p = @import("common.zig"); 24 | pub const vec2 = @import("vec2.zig"); 25 | pub const vec3 = @import("vec3.zig"); 26 | pub const mat4x4 = @import("mat4x4.zig"); 27 | 28 | pub const Mat4x4f = mat4x4.Generic(f32); 29 | pub const Vec2f = vec2.Generic(f32); 30 | pub const Vec3f = vec3.Generic(f32); 31 | 32 | /// Helper type for using MVP's 33 | pub const ModelMatrix = struct { 34 | model: Mat4x4f = Mat4x4f.identity(), 35 | trans: Mat4x4f = Mat4x4f.identity(), 36 | rot: Mat4x4f = Mat4x4f.identity(), 37 | sc: Mat4x4f = Mat4x4f.identity(), 38 | 39 | /// Apply the changes were made 40 | pub fn update(self: *ModelMatrix) void { 41 | self.model = Mat4x4f.mul(self.sc, Mat4x4f.mul(self.trans, self.rot)); 42 | } 43 | 44 | /// Translate the matrix 45 | pub fn translate(self: *ModelMatrix, x: f32, y: f32, z: f32) void { 46 | self.trans = Mat4x4f.translate(x, y, z); 47 | self.update(); 48 | } 49 | 50 | /// Rotate the matrix 51 | pub fn rotate(self: *ModelMatrix, x: f32, y: f32, z: f32, angle: f32) void { 52 | self.rot = Mat4x4f.rotate(x, y, z, angle); 53 | self.update(); 54 | } 55 | 56 | /// Scale the matrix 57 | pub fn scale(self: *ModelMatrix, x: f32, y: f32, z: f32) void { 58 | self.sc = Mat4x4f.scale(x, y, z); 59 | self.update(); 60 | } 61 | }; 62 | 63 | pub const Rectangle = struct { 64 | position: Vec2f = .{ .x = 0, .y = 0 }, 65 | size: Vec2f = .{ .x = 0, .y = 0 }, 66 | 67 | /// Get the originated position of the rectangle 68 | pub fn getOriginated(self: Rectangle) Vec2f { 69 | return .{ 70 | .x = self.position.x + (self.size.x * 0.5), 71 | .y = self.position.y + (self.size.y * 0.5), 72 | }; 73 | } 74 | 75 | /// Get origin of the rectangle 76 | pub fn getOrigin(self: Rectangle) Vec2f { 77 | return .{ 78 | .x = self.size.x * 0.5, 79 | .y = self.size.y * 0.5, 80 | }; 81 | } 82 | 83 | /// AABB collision detection 84 | /// between to rectangles 85 | pub fn aabb(self: Rectangle, other: Rectangle) bool { 86 | return p.aabb(self.position.x, self.position.y, self.size.x, self.size.y, other.position.x, other.position.y, other.size.x, other.size.y); 87 | } 88 | 89 | /// AABB collision detection 90 | /// between to rectangles 91 | pub fn aabbMeeting(self: Rectangle, other: Rectangle, meeting: Vec2f) bool { 92 | return p.aabbMeeting(meeting.x, meeting.y, self.position.x, self.position.y, self.size.x, self.size.y, other.position.x, other.position.y, other.size.x, other.size.y); 93 | } 94 | }; 95 | 96 | /// Transform 2D 97 | pub const Transform2D = struct { 98 | position: Vec2f = undefined, 99 | size: Vec2f = undefined, 100 | origin: Vec2f = undefined, 101 | /// in degrees 102 | rotation: f32 = undefined, 103 | 104 | /// Get the originated position 105 | pub fn getOriginated(self: Transform2D) Vec2f { 106 | return Vec2f{ 107 | .x = self.position.x - self.origin.x, 108 | .y = self.position.y - self.origin.y, 109 | }; 110 | } 111 | 112 | pub fn getRectangle(self: Transform2D) Rectangle { 113 | return Rectangle{ .position = self.getOriginated(), .size = self.size }; 114 | } 115 | 116 | pub fn getRectangleNoOrigin(self: Transform2D) Rectangle { 117 | return Rectangle{ .position = self.position, .size = self.size }; 118 | } 119 | 120 | /// AABB collision detection 121 | /// between to transform(rotation does not count) 122 | pub fn aabb(self: Transform2D, other: Transform2D) bool { 123 | return self.getRectangle().aabb(other.getRectangle()); 124 | } 125 | 126 | /// AABB collision detection 127 | /// between to transform(rotation does not count) 128 | /// origin does not count 129 | pub fn aabbNoOrigin(self: Transform2D, other: Transform2D) bool { 130 | return Rectangle.aabb(self.getRectangleNoOrigin(), other.getRectangleNoOrigin()); 131 | } 132 | 133 | /// AABB collision detection 134 | /// between to transform(rotation does not count) 135 | pub fn aabbMeeting(self: Transform2D, other: Transform2D, meeting: Vec2f) bool { 136 | return self.getRectangle().aabbMeeting(other.getRectangle(), meeting); 137 | } 138 | 139 | /// AABB collision detection 140 | /// between to transform(rotation does not count) 141 | /// origin does not count 142 | pub fn aabbMeetingNoOrigin(self: Transform2D, other: Transform2D, meeting: Vec2f) bool { 143 | return Rectangle.aabbMeeting(self.getRectangleNoOrigin(), other.getRectangleNoOrigin(), meeting); 144 | } 145 | }; 146 | 147 | /// 2D Camera 148 | pub const Camera2D = struct { 149 | position: Vec2f = Vec2f{ .x = 0, .y = 0 }, 150 | offset: Vec2f = Vec2f{ .x = 0, .y = 0 }, 151 | zoom: Vec2f = Vec2f{ .x = 1, .y = 1 }, 152 | 153 | /// In radians 154 | rotation: f32 = 0, 155 | 156 | ortho: Mat4x4f = comptime Mat4x4f.identity(), 157 | view: Mat4x4f = comptime Mat4x4f.identity(), 158 | 159 | /// Returns the camera matrix 160 | pub fn matrix(self: Camera2D) Mat4x4f { 161 | const origin = Mat4x4f.translate(self.position.x, self.position.y, 0); 162 | const rot = Mat4x4f.rotate(0, 0, 1, self.rotation); 163 | const scale = Mat4x4f.scale(self.zoom.x, self.zoom.y, 0); 164 | const offset = Mat4x4f.translate(self.offset.x, self.offset.y, 0); 165 | 166 | return Mat4x4f.mul(Mat4x4f.mul(origin, Mat4x4f.mul(scale, rot)), offset); 167 | } 168 | 169 | /// Attaches the camera 170 | pub fn attach(self: *Camera2D) void { 171 | self.view = Mat4x4f.mul(self.matrix(), self.ortho); 172 | } 173 | 174 | /// Detaches the camera 175 | pub fn detach(self: *Camera2D) void { 176 | self.view = Mat4x4f.identity(); 177 | } 178 | 179 | /// Returns the screen space position for a 2d camera world space position 180 | pub fn worldToScreen(self: Camera2D, position: Vec2f) Vec2f { 181 | const m = self.matrix(); 182 | const v = Vec3f.transform(Vec3f{ .x = position.x, .y = position.y, .z = 0.0 }, m); 183 | return .{ .x = v.x, .y = v.y }; 184 | } 185 | 186 | /// Returns the world space position for a 2d camera screen space position 187 | pub fn screenToWorld(self: Camera2D, position: Vec2f) Vec2f { 188 | const m = Mat4x4f.invert(self.matrix()); 189 | const v = Vec3f.transform(Vec3f{ .x = position.x, .y = position.y, .z = 0.0 }, m); 190 | return .{ .x = v.x, .y = v.y }; 191 | } 192 | }; 193 | -------------------------------------------------------------------------------- /src/core/math/vec2.zig: -------------------------------------------------------------------------------- 1 | //Copyright © 2020-2021 Mehmet Kaan Uluç 2 | // 3 | //This software is provided 'as-is', without any express or implied 4 | //warranty. In no event will the authors be held liable for any damages 5 | //arising from the use of this software. 6 | // 7 | //Permission is granted to anyone to use this software for any purpose, 8 | //including commercial applications, and to alter it and redistribute it 9 | //freely, subject to the following restrictions: 10 | // 11 | //1. The origin of this software must not be misrepresented; you must not 12 | // claim that you wrote the original software. If you use this software 13 | // in a product, an acknowledgment in the product documentation would 14 | // be appreciated but is not required. 15 | // 16 | //2. Altered source versions must be plainly marked as such, and must not 17 | // be misrepresented as being the original software. 18 | // 19 | //3. This notice may not be removed or altered from any source 20 | // distribution. 21 | 22 | const atan2 = @import("std").math.atan2; 23 | const c = @import("common.zig"); 24 | 25 | /// Generic Vector2 Type 26 | pub fn Generic(comptime T: type) type { 27 | switch (T) { 28 | i16, i32, i64, i128, f16, f32, f64, f128 => { 29 | return struct { 30 | const Self = @This(); 31 | /// X value 32 | x: T = 0, 33 | /// Y value 34 | y: T = 0, 35 | 36 | /// Adds two Vector2s and returns the result 37 | pub fn add(self: Self, other: Self) Self { 38 | return .{ .x = self.x + other.x, .y = self.y + other.y }; 39 | } 40 | 41 | /// Add values to the self and returns the result 42 | pub fn addValues(self: Self, x: T, y: T) Self { 43 | return .{ .x = self.x + x, .y = self.y + y }; 44 | } 45 | 46 | /// Subtracts two Vector2s and returns the result 47 | pub fn sub(self: Self, other: Self) Self { 48 | return .{ .x = self.x - other.x, .y = self.y - other.y }; 49 | } 50 | 51 | /// Subtract values to the self and returns the result 52 | pub fn subValues(self: Self, x: T, y: T) Self { 53 | return .{ .x = self.x - x, .y = self.y - y }; 54 | } 55 | 56 | /// Divides two Vector2s and returns the result 57 | pub fn div(self: Self, other: Self) Self { 58 | return .{ .x = self.x / other.x, .y = self.y / other.y }; 59 | } 60 | 61 | /// Divide values to the self and returns the result 62 | pub fn divValues(self: Self, x: T, y: T) Self { 63 | return .{ .x = self.x / x, .y = self.y / y }; 64 | } 65 | 66 | /// Multiplies two Vector2s and returns the result 67 | pub fn mul(self: Self, other: Self) Self { 68 | return .{ .x = self.x * other.x, .y = self.y * other.y }; 69 | } 70 | 71 | /// Multiply values to the self and returns the result 72 | pub fn mulValues(self: Self, x: T, y: T) Self { 73 | return .{ .x = self.x * x, .y = self.y * y }; 74 | } 75 | 76 | /// Calculate angle from two Vector2s in X-axis in degrees 77 | pub fn angle(v1: Self, v2: Self) T { 78 | const result: T = atan2(T, v2.y - v1.y, v2.x - v1.x) * @as(T, (180 / c.PI)); 79 | if (result < 0) return result + 360; 80 | return result; 81 | } 82 | 83 | /// Calculate angle from two Vector2s in X-axis in radians 84 | pub fn angleRad(v1: Self, v2: Self) T { 85 | return atan2(T, v2.y - v1.y, v2.x - v1.x); 86 | } 87 | 88 | /// Calculate the toward position 89 | pub fn moveTowards(v1: Self, v2: Self, speed: Self) Self { 90 | const ang: T = atan2(T, v2.y - v1.y, v2.x - v1.x); 91 | return Self{ 92 | .x = v1.x + @cos(ang) * speed.x, 93 | .y = v1.y + @sin(ang) * speed.y, 94 | }; 95 | } 96 | 97 | /// Calculate the distance between two points 98 | pub fn distance(v1: Self, v2: Self) T { 99 | const dx = v1.x - v2.x; 100 | const dy = v1.y - v2.y; 101 | return @sqrt(dx * dx + dy * dy); 102 | } 103 | 104 | /// Make it absolute 105 | pub fn abs(self: Self) Self { 106 | return Self{ 107 | .x = c.abs(self.x), 108 | .y = c.abs(self.y), 109 | }; 110 | } 111 | 112 | /// Converts the vec2 into the array 113 | pub fn toArray(self: Self) [2]T { 114 | return [2]T{ self.x, self.y }; 115 | } 116 | }; 117 | }, 118 | else => @compileError("Vector2 not implemented for " ++ @typeName(T)), 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /src/core/math/vec3.zig: -------------------------------------------------------------------------------- 1 | //Copyright © 2020-2021 Mehmet Kaan Uluç 2 | // 3 | //This software is provided 'as-is', without any express or implied 4 | //warranty. In no event will the authors be held liable for any damages 5 | //arising from the use of this software. 6 | // 7 | //Permission is granted to anyone to use this software for any purpose, 8 | //including commercial applications, and to alter it and redistribute it 9 | //freely, subject to the following restrictions: 10 | // 11 | //1. The origin of this software must not be misrepresented; you must not 12 | // claim that you wrote the original software. If you use this software 13 | // in a product, an acknowledgment in the product documentation would 14 | // be appreciated but is not required. 15 | // 16 | //2. Altered source versions must be plainly marked as such, and must not 17 | // be misrepresented as being the original software. 18 | // 19 | //3. This notice may not be removed or altered from any source 20 | // distribution. 21 | 22 | const mat4x4 = @import("mat4x4.zig"); 23 | const c = @import("common.zig"); 24 | 25 | /// Generic Vector3 Type 26 | pub fn Generic(comptime T: type) type { 27 | switch (T) { 28 | i16, i32, i64, i128, f16, f32, f64, f128 => { 29 | return struct { 30 | const Self = @This(); 31 | /// X value 32 | x: T = 0, 33 | /// Y value 34 | y: T = 0, 35 | /// Z value 36 | z: T = 0, 37 | 38 | /// Adds two Vector3s and returns the result 39 | pub fn add(self: Self, other: Self) Self { 40 | return .{ .x = self.x + other.x, .y = self.y + other.y, .z = self.z + other.z }; 41 | } 42 | 43 | /// Add values to the self and returns the result 44 | pub fn addValues(self: Self, x: T, y: T, z: T) Self { 45 | return .{ .x = self.x + x, .y = self.y + y, .z = self.z + z }; 46 | } 47 | 48 | /// Subtracts two Vector3s and returns the result 49 | pub fn sub(self: Self, other: Self) Self { 50 | return .{ .x = self.x - other.x, .y = self.y - other.y, .z = self.z - other.z }; 51 | } 52 | 53 | /// Subtract values to the self and returns the result 54 | pub fn subValues(self: Self, x: T, y: T, z: T) Self { 55 | return .{ .x = self.x - x, .y = self.y - y, .z = self.z - z }; 56 | } 57 | 58 | /// Divides two Vector3s and returns the result 59 | pub fn div(self: Self, other: Self) Self { 60 | return .{ .x = self.x / other.x, .y = self.y / other.y, .z = self.z / other.z }; 61 | } 62 | 63 | /// Divide values to the self and returns the result 64 | pub fn divValues(self: Self, x: T, y: T, z: T) Self { 65 | return .{ .x = self.x / x, .y = self.y / y, .z = self.z / z }; 66 | } 67 | 68 | /// Multiplies two Vector3s and returns the result 69 | pub fn mul(self: Self, other: Self) Self { 70 | return .{ .x = self.x * other.x, .y = self.y * other.y, .z = self.z * other.z }; 71 | } 72 | 73 | /// Multiply values to the self and returns the result 74 | pub fn mulValues(self: Self, x: T, y: T, z: T) Self { 75 | return .{ .x = self.x * x, .y = self.y * y, .z = self.z * z }; 76 | } 77 | 78 | /// Transforms a Vector3 by a given 4x4 Matrix 79 | pub fn transform(v1: Self, mat: mat4x4.Generic(T)) Self { 80 | const x = v1.x; 81 | const y = v1.y; 82 | const z = v1.z; 83 | 84 | return Self{ 85 | .x = mat.m0 * x + mat.m4 * y + mat.m8 * z + mat.m12, 86 | .y = mat.m1 * x + mat.m5 * y + mat.m9 * z + mat.m13, 87 | .z = mat.m2 * x + mat.m6 * y + mat.m10 * z + mat.m14, 88 | }; 89 | } 90 | 91 | /// Make it absolute 92 | pub fn abs(self: Self) Self { 93 | return Self{ 94 | .x = c.abs(self.x), 95 | .y = c.abs(self.y), 96 | .z = c.abs(self.z), 97 | }; 98 | } 99 | 100 | /// Converts the vec3 into the array 101 | pub fn toArray(self: Self) [3]T { 102 | return [3]T{ self.x, self.y, self.z }; 103 | } 104 | }; 105 | }, 106 | else => @compileError("Vector3 not implemented for " ++ @typeName(T)), 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/core/private.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | 6 | bool alkaLoadIcon(GLFWwindow *window, const char* path) { 7 | GLFWimage images[1]; 8 | images[0].pixels = stbi_load(path, &images[0].width, &images[0].height, 0, 4); //rgba channels 9 | if (images[0].pixels == NULL) return false; 10 | glfwSetWindowIcon(window, 1, images); 11 | stbi_image_free(images[0].pixels); 12 | return true; 13 | } 14 | -------------------------------------------------------------------------------- /src/core/utf8.zig: -------------------------------------------------------------------------------- 1 | //Copyright © 2020-2021 Mehmet Kaan Uluç 2 | // 3 | //This software is provided 'as-is', without any express or implied 4 | //warranty. In no event will the authors be held liable for any damages 5 | //arising from the use of this software. 6 | // 7 | //Permission is granted to anyone to use this software for any purpose, 8 | //including commercial applications, and to alter it and redistribute it 9 | //freely, subject to the following restrictions: 10 | // 11 | //1. The origin of this software must not be misrepresented; you must not 12 | // claim that you wrote the original software. If you use this software 13 | // in a product, an acknowledgment in the product documentation would 14 | // be appreciated but is not required. 15 | // 16 | //2. Altered source versions must be plainly marked as such, and must not 17 | // be misrepresented as being the original software. 18 | // 19 | //3. This notice may not be removed or altered from any source 20 | // distribution. 21 | 22 | const std = @import("std"); 23 | 24 | // source: https://github.com/raysan5/raylib/blob/cba412cc313e4f95eafb3fba9303400e65c98984/src/str.c#L1615 25 | pub fn nextCodepoint(str: []const u8, bytesprocessed: *i32) i32 { 26 | var code: i32 = 0x3f; // codepoint (defaults to '?'); 27 | var octet: i32 = @intCast(i32, str[0]); // the first UTF8 octet 28 | 29 | bytesprocessed.* = 1; 30 | 31 | if (octet <= 0x7f) { 32 | // Only one octet (ASCII range x00-7F) 33 | code = str[0]; 34 | } else if ((octet & 0xe0) == 0xc0) { 35 | // Two octets 36 | // [0]xC2-DF [1]UTF8-tail(x80-BF) 37 | var octet1 = str[1]; 38 | 39 | if ((octet1 == 0) or ((octet1 >> 6) != 2)) { 40 | bytesprocessed.* = 2; 41 | return code; 42 | } // Unexpected sequence 43 | 44 | if ((octet >= 0xc2) and (octet <= 0xdf)) { 45 | code = ((octet & 0x1f) << 6) | (octet1 & 0x3f); 46 | bytesprocessed.* = 2; 47 | } 48 | } else if ((octet & 0xf0) == 0xe0) { 49 | // Three octets 50 | var octet1 = str[1]; 51 | var octet2: u8 = 0; 52 | 53 | if ((octet1 == 0) or ((octet1 >> 6) != 2)) { 54 | bytesprocessed.* = 2; 55 | return code; 56 | } // Unexpected sequence 57 | 58 | octet2 = str[2]; 59 | 60 | if ((octet2 == 0) or ((octet2 >> 6) != 2)) { 61 | bytesprocessed.* = 3; 62 | return code; 63 | } // Unexpected sequence 64 | 65 | // 66 | // [0]xE0 [1]xA0-BF [2]UTF8-tail(x80-BF) 67 | // [0]xE1-EC [1]UTF8-tail [2]UTF8-tail(x80-BF) 68 | // [0]xED [1]x80-9F [2]UTF8-tail(x80-BF) 69 | // [0]xEE-EF [1]UTF8-tail [2]UTF8-tail(x80-BF) 70 | // 71 | 72 | if (((octet == 0xe0) and !((octet1 >= 0xa0) and (octet1 <= 0xbf))) or 73 | ((octet == 0xed) and !((octet1 >= 0x80) and (octet1 <= 0x9f)))) 74 | { 75 | bytesprocessed.* = 2; 76 | return code; 77 | } 78 | 79 | if ((octet >= 0xe0) and (0 <= 0xef)) { 80 | code = ((octet & 0xf) << 12) | ((octet1 & 0x3f) << 6) | (octet2 & 0x3f); 81 | bytesprocessed.* = 3; 82 | } 83 | } else if ((octet & 0xf8) == 0xf0) { 84 | // Four octets 85 | if (octet > 0xf4) 86 | return code; 87 | 88 | var octet1 = str[1]; 89 | var octet2: u8 = 0; 90 | var octet3: u8 = 0; 91 | 92 | if ((octet1 == 0) or ((octet1 >> 6) != 2)) { 93 | bytesprocessed.* = 2; 94 | return code; 95 | } // Unexpected sequence 96 | 97 | octet2 = str[2]; 98 | 99 | if ((octet2 == 0) or ((octet2 >> 6) != 2)) { 100 | bytesprocessed.* = 3; 101 | return code; 102 | } // Unexpected sequence 103 | 104 | octet3 = str[3]; 105 | 106 | if ((octet3 == 0) or ((octet3 >> 6) != 2)) { 107 | bytesprocessed.* = 4; 108 | return code; 109 | } // Unexpected sequence 110 | 111 | // 112 | // [0]xF0 [1]x90-BF [2]UTF8-tail [3]UTF8-tail 113 | // [0]xF1-F3 [1]UTF8-tail [2]UTF8-tail [3]UTF8-tail 114 | // [0]xF4 [1]x80-8F [2]UTF8-tail [3]UTF8-tail 115 | // 116 | 117 | if (((octet == 0xf0) and !((octet1 >= 0x90) and (octet1 <= 0xbf))) or 118 | ((octet == 0xf4) and !((octet1 >= 0x80) and (octet1 <= 0x8f)))) 119 | { 120 | bytesprocessed.* = 2; 121 | return code; 122 | } // Unexpected sequence 123 | 124 | if (octet >= 0xf0) { 125 | code = ((octet & 0x7) << 18) | ((octet1 & 0x3f) << @truncate(u3, 12)) | 126 | ((octet2 & 0x3f) << 6) | (octet3 & 0x3f); 127 | bytesprocessed.* = 4; 128 | } 129 | } 130 | 131 | // codepoints after U+10ffff are invalid 132 | if (code > 0x10ffff) code = 0x3f; 133 | 134 | return code; 135 | } 136 | -------------------------------------------------------------------------------- /src/main.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const alka = @import("alka.zig"); 3 | const m = alka.math; 4 | 5 | usingnamespace alka.log; 6 | pub const mlog = std.log.scoped(.app); 7 | pub const log_level: std.log.Level = .debug; 8 | 9 | const RectangleStore = alka.ecs.StoreComponent("Rectangle", m.Rectangle, maxent); 10 | const SpeedStore = alka.ecs.StoreComponent("Speed", f32, maxent); 11 | const VelocityStore = alka.ecs.StoreComponent("Velocity", m.Vec2f, maxent); 12 | const ColourStore = alka.ecs.StoreComponent("Colour", alka.Colour, maxent); 13 | const World = alka.ecs.World(struct { r: RectangleStore, col: ColourStore, sp: SpeedStore, vl: VelocityStore }); 14 | 15 | const maxent: u64 = 1024 * 100; 16 | var random: *std.rand.Random = undefined; 17 | 18 | var world: World = undefined; 19 | 20 | var mouseleftPtr: *const alka.input.State = undefined; 21 | var index: u64 = 0; 22 | 23 | fn createEntity(i: u64) !void { 24 | var reg = try world.createRegister(i); 25 | try reg.create(); 26 | 27 | try reg.attach("Rectangle", m.Rectangle{ 28 | .position = alka.getMousePosition(), 29 | .size = m.Vec2f{ 30 | .x = @intToFloat(f32, random.intRangeAtMost(i32, 10, 50)), 31 | .y = @intToFloat(f32, random.intRangeAtMost(i32, 10, 50)), 32 | }, 33 | }); 34 | 35 | const speed: f32 = 200 * @intToFloat(f32, random.intRangeAtMost(i32, -1, 1)); 36 | try reg.attach("Speed", speed); 37 | 38 | try reg.attach("Velocity", m.Vec2f{}); 39 | 40 | try reg.attach("Colour", alka.Colour.rgba(random.intRangeAtMost(u8, 0, 200), random.intRangeAtMost(u8, 0, 200), random.intRangeAtMost(u8, 0, 200), 255)); 41 | //mlog.info("created {}", .{i}); 42 | } 43 | 44 | fn update(dt: f32) !void { 45 | if (mouseleftPtr.* == alka.input.State.down) { 46 | if (index < maxent) { 47 | var i: u64 = index; 48 | while (i < index + 1) : (i += 1) { 49 | try createEntity(i); 50 | } 51 | index = i; 52 | } 53 | } 54 | 55 | const comps = [_][]const u8{ "Velocity", "Speed", "Rectangle" }; 56 | 57 | var it = World.iterator(comps.len, comps){ .world = &world }; 58 | while (it.next()) |entry| { 59 | if (entry.value) |entity| { 60 | var vel = try entity.getPtr("Velocity", m.Vec2f); 61 | var speed = try entity.getPtr("Speed", f32); 62 | const rect = try entity.get("Rectangle", m.Rectangle); 63 | 64 | if (rect.position.x > 1024 - rect.size.x) { 65 | speed.* = -speed.*; 66 | } else if (rect.position.x < 0) { 67 | speed.* = m.abs(speed.*); 68 | } 69 | 70 | vel.x += speed.* * dt; 71 | } 72 | } 73 | } 74 | 75 | fn fupdate(dt: f32) !void { 76 | const comps = [_][]const u8{ "Velocity", "Rectangle" }; 77 | 78 | var it = World.iterator(comps.len, comps){ .world = &world }; 79 | while (it.next()) |entry| { 80 | if (entry.value) |entity| { 81 | var rect = try entity.getPtr("Rectangle", m.Rectangle); 82 | var vel = try entity.getPtr("Velocity", m.Vec2f); 83 | 84 | rect.position.x += vel.x; 85 | vel.* = m.Vec2f{}; 86 | } 87 | } 88 | } 89 | 90 | fn draw() !void { 91 | const comps = [_][]const u8{ "Rectangle", "Colour" }; 92 | 93 | var it = World.iterator(comps.len, comps){ .world = &world }; 94 | 95 | while (it.next()) |entry| { 96 | if (entry.value) |entity| { 97 | const rect = try entity.get("Rectangle", m.Rectangle); 98 | const colour = try entity.get("Colour", alka.Colour); 99 | 100 | try alka.drawRectangle(rect, colour); 101 | } 102 | } 103 | 104 | const asset = alka.getAssetManager(); 105 | const font = try asset.getFont(0); 106 | 107 | const col = alka.Colour.rgba(200, 30, 70, 255); 108 | 109 | var debug = try alka.getDebug(); 110 | defer alka.getAllocator().free(debug); 111 | 112 | try alka.drawText(0, debug, m.Vec2f{ .x = 20, .y = 20 }, 24, col); 113 | mlog.info("{s}", .{debug}); 114 | 115 | debug = try std.fmt.bufPrint(debug, "total: {}", .{index}); 116 | try alka.drawText(0, debug, m.Vec2f{ .x = 20, .y = 45 }, 24, col); 117 | mlog.info("{s}", .{debug}); 118 | } 119 | 120 | pub fn main() !void { 121 | var gpa = std.heap.GeneralPurposeAllocator(.{ 122 | .enable_memory_limit = false, 123 | }){}; 124 | //gpa.setRequestedMemoryLimit(1048 * 1000 * 5); 125 | 126 | const callbacks = alka.Callbacks{ 127 | .update = update, 128 | .fixed = fupdate, 129 | .draw = draw, 130 | }; 131 | 132 | try alka.init(&gpa.allocator, callbacks, 1024, 768, "ECS Benchmark", 1000, false); 133 | 134 | var prng = std.rand.DefaultPrng.init(blk: { 135 | var seed: u64 = undefined; 136 | try std.os.getrandom(std.mem.asBytes(&seed)); 137 | break :blk seed; 138 | }); 139 | random = &prng.random; 140 | 141 | var input = alka.getInput(); 142 | try input.bindMouse(alka.input.Mouse.ButtonLeft); 143 | mouseleftPtr = try input.mouseStatePtr(alka.input.Mouse.ButtonLeft); 144 | 145 | try alka.getAssetManager().loadFont(0, "assets/arial.ttf", 128); 146 | const font = try alka.getAssetManager().getFont(0); 147 | font.texture.setFilter(alka.gl.TextureParamater.filter_mipmap_nearest, alka.gl.TextureParamater.filter_linear); 148 | 149 | world = try World.init(&gpa.allocator); 150 | 151 | try alka.open(); 152 | try alka.update(); 153 | try alka.close(); 154 | 155 | world.deinit(); 156 | 157 | try alka.deinit(); 158 | 159 | const leaked = gpa.deinit(); 160 | if (leaked) return error.Leak; 161 | } 162 | -------------------------------------------------------------------------------- /src/run.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/sh 2 | 3 | cd .. 4 | zig build run -Dmain=true 5 | --------------------------------------------------------------------------------