mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
setup opengl
This commit is contained in:
87
build.zig
87
build.zig
@ -1,6 +1,7 @@
|
||||
const std = @import("std");
|
||||
const Builder = std.build.Builder;
|
||||
const LibExeObjStep = std.build.LibExeObjStep;
|
||||
const glfw = @import("vendor/mach/glfw/build.zig");
|
||||
|
||||
pub fn build(b: *std.build.Builder) void {
|
||||
const target = b.standardTargetOptions(.{});
|
||||
@ -10,8 +11,10 @@ pub fn build(b: *std.build.Builder) void {
|
||||
exe.setTarget(target);
|
||||
exe.setBuildMode(mode);
|
||||
exe.install();
|
||||
exe.linkLibrary(addRaylib(exe.builder, exe.target));
|
||||
exe.addIncludeDir("vendor/raylib/src"); // for raylib.h
|
||||
exe.addPackagePath("glfw", "vendor/mach/glfw/src/main.zig");
|
||||
glfw.link(b, exe, .{});
|
||||
|
||||
exe.linkSystemLibrary("epoxy");
|
||||
|
||||
const run_cmd = exe.run();
|
||||
run_cmd.step.dependOn(b.getInstallStep());
|
||||
@ -22,83 +25,3 @@ pub fn build(b: *std.build.Builder) void {
|
||||
const run_step = b.step("run", "Run the app");
|
||||
run_step.dependOn(&run_cmd.step);
|
||||
}
|
||||
|
||||
pub fn addRaylib(b: *std.build.Builder, target: std.zig.CrossTarget) *std.build.LibExeObjStep {
|
||||
// Standard release options allow the person running `zig build` to select
|
||||
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
|
||||
const mode = b.standardReleaseOptions();
|
||||
|
||||
const raylib_flags = &[_][]const u8{
|
||||
"-std=gnu99",
|
||||
"-DPLATFORM_DESKTOP",
|
||||
"-DGL_SILENCE_DEPRECATION=199309L",
|
||||
"-fno-sanitize=undefined", // https://github.com/raysan5/raylib/issues/1891
|
||||
"-DSUPPORT_EVENTS_WAITING", // for waiting, not polling on events
|
||||
};
|
||||
|
||||
const srcdir = "vendor/raylib/src";
|
||||
|
||||
const raylib = b.addStaticLibrary("raylib", srcdir ++ "/raylib.h");
|
||||
raylib.setTarget(target);
|
||||
raylib.setBuildMode(mode);
|
||||
raylib.linkLibC();
|
||||
|
||||
raylib.addIncludeDir(srcdir ++ "/external/glfw/include");
|
||||
|
||||
raylib.addCSourceFiles(&.{
|
||||
srcdir ++ "/raudio.c",
|
||||
srcdir ++ "/rcore.c",
|
||||
srcdir ++ "/rmodels.c",
|
||||
srcdir ++ "/rshapes.c",
|
||||
srcdir ++ "/rtext.c",
|
||||
srcdir ++ "/rtextures.c",
|
||||
srcdir ++ "/utils.c",
|
||||
}, raylib_flags);
|
||||
|
||||
switch (raylib.target.toTarget().os.tag) {
|
||||
.windows => {
|
||||
raylib.addCSourceFiles(&.{srcdir ++ "/rglfw.c"}, raylib_flags);
|
||||
raylib.linkSystemLibrary("winmm");
|
||||
raylib.linkSystemLibrary("gdi32");
|
||||
raylib.linkSystemLibrary("opengl32");
|
||||
raylib.addIncludeDir("external/glfw/deps/mingw");
|
||||
},
|
||||
.linux => {
|
||||
raylib.addCSourceFiles(&.{srcdir ++ "/rglfw.c"}, raylib_flags);
|
||||
raylib.linkSystemLibrary("GL");
|
||||
raylib.linkSystemLibrary("rt");
|
||||
raylib.linkSystemLibrary("dl");
|
||||
raylib.linkSystemLibrary("m");
|
||||
raylib.linkSystemLibrary("X11");
|
||||
},
|
||||
.freebsd, .openbsd, .netbsd, .dragonfly => {
|
||||
raylib.addCSourceFiles(&.{srcdir ++ "/rglfw.c"}, raylib_flags);
|
||||
raylib.linkSystemLibrary("GL");
|
||||
raylib.linkSystemLibrary("rt");
|
||||
raylib.linkSystemLibrary("dl");
|
||||
raylib.linkSystemLibrary("m");
|
||||
raylib.linkSystemLibrary("X11");
|
||||
raylib.linkSystemLibrary("Xrandr");
|
||||
raylib.linkSystemLibrary("Xinerama");
|
||||
raylib.linkSystemLibrary("Xi");
|
||||
raylib.linkSystemLibrary("Xxf86vm");
|
||||
raylib.linkSystemLibrary("Xcursor");
|
||||
},
|
||||
.macos => {
|
||||
// On macos rglfw.c include Objective-C files.
|
||||
const raylib_flags_extra_macos = &[_][]const u8{
|
||||
"-ObjC",
|
||||
};
|
||||
raylib.addCSourceFiles(
|
||||
&.{srcdir ++ "/rglfw.c"},
|
||||
raylib_flags ++ raylib_flags_extra_macos,
|
||||
);
|
||||
raylib.linkFramework("Foundation");
|
||||
},
|
||||
else => {
|
||||
@panic("Unsupported OS");
|
||||
},
|
||||
}
|
||||
|
||||
return raylib;
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
, vttest
|
||||
, zig
|
||||
|
||||
, libepoxy
|
||||
, libGL
|
||||
, libX11
|
||||
, libXcursor
|
||||
@ -29,7 +30,9 @@
|
||||
buildInputs = [
|
||||
# TODO: non-linux
|
||||
] ++ lib.optionals stdenv.isLinux [
|
||||
libepoxy
|
||||
libGL
|
||||
|
||||
libX11
|
||||
libXcursor
|
||||
libXext
|
||||
|
35
src/main.zig
35
src/main.zig
@ -1,21 +1,30 @@
|
||||
const std = @import("std");
|
||||
const c = @import("c.zig");
|
||||
const glfw = @import("glfw");
|
||||
const c = @cImport({
|
||||
@cInclude("epoxy/gl.h");
|
||||
});
|
||||
|
||||
pub fn main() !void {
|
||||
// Set the window as resizable. This is particularly important for
|
||||
// tiling window managers such as i3 since if they are not resizable they
|
||||
// usually default to floating and we do not want to float by default!
|
||||
c.SetConfigFlags(c.FLAG_WINDOW_RESIZABLE | c.FLAG_VSYNC_HINT);
|
||||
try glfw.init(.{});
|
||||
defer glfw.terminate();
|
||||
|
||||
// Create our window
|
||||
c.InitWindow(640, 480, "ghostty");
|
||||
c.SetTargetFPS(60);
|
||||
defer c.CloseWindow();
|
||||
const window = try glfw.Window.create(640, 480, "ghostty", null, null, .{});
|
||||
defer window.destroy();
|
||||
|
||||
// Draw
|
||||
while (!c.WindowShouldClose()) {
|
||||
c.BeginDrawing();
|
||||
c.ClearBackground(c.BLACK);
|
||||
c.EndDrawing();
|
||||
// Setup OpenGL
|
||||
try glfw.makeContextCurrent(window);
|
||||
try glfw.swapInterval(1);
|
||||
|
||||
// Setup basic OpenGL settings
|
||||
c.glClearColor(0.0, 0.0, 0.0, 0.0);
|
||||
|
||||
// Wait for the user to close the window.
|
||||
while (!window.shouldClose()) {
|
||||
const pos = try window.getCursorPos();
|
||||
std.log.info("CURSOR: {}", .{pos});
|
||||
|
||||
try window.swapBuffers();
|
||||
try glfw.waitEvents();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user