mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
gb_math
This commit is contained in:
@ -3,7 +3,6 @@ const Builder = std.build.Builder;
|
||||
const LibExeObjStep = std.build.LibExeObjStep;
|
||||
const glfw = @import("vendor/mach/glfw/build.zig");
|
||||
const ft = @import("src/freetype/build.zig");
|
||||
const cglm = @import("src/cglm.zig");
|
||||
|
||||
pub fn build(b: *std.build.Builder) !void {
|
||||
const target = b.standardTargetOptions(.{});
|
||||
@ -13,13 +12,13 @@ pub fn build(b: *std.build.Builder) !void {
|
||||
exe.setTarget(target);
|
||||
exe.setBuildMode(mode);
|
||||
exe.install();
|
||||
exe.addIncludeDir("src/");
|
||||
exe.addCSourceFile("src/gb_math.c", &.{});
|
||||
exe.addPackagePath("glfw", "vendor/mach/glfw/src/main.zig");
|
||||
glfw.link(b, exe, .{});
|
||||
|
||||
exe.linkSystemLibrary("epoxy");
|
||||
|
||||
try cglm.build(b, exe, target, mode, .{});
|
||||
|
||||
const ftlib = try ft.create(b, target, mode, .{});
|
||||
ftlib.link(exe);
|
||||
// to link to system:
|
||||
|
13
src/App.zig
13
src/App.zig
@ -32,12 +32,6 @@ pub fn init(alloc: std.mem.Allocator) !App {
|
||||
// renderer at some point.
|
||||
try glfw.makeContextCurrent(window);
|
||||
try glfw.swapInterval(1);
|
||||
window.setSizeCallback((struct {
|
||||
fn callback(_: glfw.Window, width: i32, height: i32) void {
|
||||
log.info("set viewport {} {}", .{ width, height });
|
||||
try gl.viewport(0, 0, width, height);
|
||||
}
|
||||
}).callback);
|
||||
|
||||
// Blending for text
|
||||
gl.c.glEnable(gl.c.GL_CULL_FACE);
|
||||
@ -48,6 +42,13 @@ pub fn init(alloc: std.mem.Allocator) !App {
|
||||
var texter = try TextRenderer.init(alloc);
|
||||
errdefer texter.deinit();
|
||||
|
||||
window.setSizeCallback((struct {
|
||||
fn callback(_: glfw.Window, width: i32, height: i32) void {
|
||||
log.info("set viewport {} {}", .{ width, height });
|
||||
try gl.viewport(0, 0, width, height);
|
||||
}
|
||||
}).callback);
|
||||
|
||||
return App{
|
||||
.window = window,
|
||||
.text = texter,
|
||||
|
@ -3,6 +3,7 @@ const TextRenderer = @This();
|
||||
const std = @import("std");
|
||||
const ftc = @import("freetype/c.zig");
|
||||
const gl = @import("opengl.zig");
|
||||
const gb = @import("gb_math.zig");
|
||||
|
||||
alloc: std.mem.Allocator,
|
||||
ft: ftc.FT_Library,
|
||||
@ -113,6 +114,10 @@ pub fn init(alloc: std.mem.Allocator) !TextRenderer {
|
||||
@embedFile("../shaders/text.f.glsl"),
|
||||
);
|
||||
|
||||
// Our project
|
||||
var proj: gb.gbMat4 = undefined;
|
||||
gb.gb_mat4_ortho2d(&proj, 0, 640, 0, 480);
|
||||
|
||||
return TextRenderer{
|
||||
.alloc = alloc,
|
||||
.ft = ft,
|
||||
|
78
src/cglm.zig
78
src/cglm.zig
@ -1,78 +0,0 @@
|
||||
const std = @import("std");
|
||||
|
||||
/// Compile-time options for the library. These mostly correspond to
|
||||
/// options exposed by the native build system used by the library.
|
||||
pub const BuildOptions = struct {};
|
||||
|
||||
// Build and link this library.
|
||||
pub fn build(
|
||||
b: *std.build.Builder,
|
||||
step: *std.build.LibExeObjStep,
|
||||
target: std.zig.CrossTarget,
|
||||
mode: std.builtin.Mode,
|
||||
opts: BuildOptions,
|
||||
) !void {
|
||||
_ = opts;
|
||||
|
||||
const ret = b.addStaticLibrary("cglm", null);
|
||||
ret.setTarget(target);
|
||||
ret.setBuildMode(mode);
|
||||
|
||||
var flags = std.ArrayList([]const u8).init(b.allocator);
|
||||
defer flags.deinit();
|
||||
|
||||
try flags.appendSlice(&.{
|
||||
"-DCGLM_STATIC",
|
||||
});
|
||||
|
||||
// C files
|
||||
ret.addCSourceFiles(srcs, flags.items);
|
||||
ret.addIncludeDir(include_dir);
|
||||
ret.linkLibC();
|
||||
|
||||
step.addIncludeDir(include_dir);
|
||||
step.linkLibrary(ret);
|
||||
}
|
||||
|
||||
fn root() []const u8 {
|
||||
return (std.fs.path.dirname(@src().file) orelse unreachable) ++ "/../vendor/cglm/";
|
||||
}
|
||||
|
||||
/// Directories with our includes.
|
||||
const include_dir = root() ++ "include";
|
||||
|
||||
const srcs = &.{
|
||||
root() ++ "src/euler.c",
|
||||
root() ++ "src/affine.c",
|
||||
root() ++ "src/io.c",
|
||||
root() ++ "src/quat.c",
|
||||
root() ++ "src/cam.c",
|
||||
root() ++ "src/vec2.c",
|
||||
root() ++ "src/vec3.c",
|
||||
root() ++ "src/vec4.c",
|
||||
root() ++ "src/mat2.c",
|
||||
root() ++ "src/mat3.c",
|
||||
root() ++ "src/mat4.c",
|
||||
root() ++ "src/plane.c",
|
||||
root() ++ "src/frustum.c",
|
||||
root() ++ "src/box.c",
|
||||
root() ++ "src/project.c",
|
||||
root() ++ "src/sphere.c",
|
||||
root() ++ "src/ease.c",
|
||||
root() ++ "src/curve.c",
|
||||
root() ++ "src/bezier.c",
|
||||
root() ++ "src/ray.c",
|
||||
root() ++ "src/affine2d.c",
|
||||
root() ++ "src/clipspace/persp_lh_zo.c",
|
||||
root() ++ "src/clipspace/persp_rh_zo.c",
|
||||
root() ++ "src/clipspace/persp_lh_no.c",
|
||||
root() ++ "src/clipspace/persp_rh_no.c",
|
||||
root() ++ "src/clipspace/ortho_lh_zo.c",
|
||||
root() ++ "src/clipspace/ortho_rh_zo.c",
|
||||
root() ++ "src/clipspace/ortho_lh_no.c",
|
||||
root() ++ "src/clipspace/ortho_rh_no.c",
|
||||
root() ++ "src/clipspace/view_lh_zo.c",
|
||||
root() ++ "src/clipspace/view_rh_zo.c",
|
||||
root() ++ "src/clipspace/view_lh_no.c",
|
||||
root() ++ "src/clipspace/view_rh_no.c",
|
||||
};
|
6
src/gb_math.c
Normal file
6
src/gb_math.c
Normal file
@ -0,0 +1,6 @@
|
||||
// This file defines the implementation of gb_math and is compiled using clang.
|
||||
// gb_math.zig then imports gb_math.h without the implementation define set
|
||||
// so that it can just get the function prototypes.
|
||||
|
||||
#define GB_MATH_IMPLEMENTATION
|
||||
#include "gb_math.h"
|
2234
src/gb_math.h
Normal file
2234
src/gb_math.h
Normal file
File diff suppressed because it is too large
Load Diff
3
src/gb_math.zig
Normal file
3
src/gb_math.zig
Normal file
@ -0,0 +1,3 @@
|
||||
pub usingnamespace @cImport({
|
||||
@cInclude("gb_math.h");
|
||||
});
|
Reference in New Issue
Block a user