Skip to content

Commit

Permalink
update SDL, SDL_ttf
Browse files Browse the repository at this point in the history
  • Loading branch information
jethrodaniel committed Sep 29, 2024
1 parent c883aec commit 0af12b6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
32 changes: 23 additions & 9 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -781,14 +781,26 @@ pub fn build(b: *std.Build) !void {
};

const sdl_examples = [_]SdlExample{
SdlExample{ .path = "examples/audio/01-simple-playback", .name = "simple-playback" },
SdlExample{ .path = "examples/audio/02-simple-playback-callback", .name = "simple-playback-callback" },
SdlExample{ .path = "examples/audio/03-load-wav", .name = "load-wav" },
SdlExample{ .path = "examples/camera/01-read-and-draw", .name = "read-and-draw" },
SdlExample{ .path = "examples/game/01-snake", .name = "snake" },
SdlExample{ .path = "examples/pen/01-drawing-lines", .name = "drawing-lines" },
SdlExample{ .path = "examples/renderer/01-clear", .name = "renderer-clear" },
SdlExample{ .path = "examples/renderer/02-primitives", .name = "renderer-primitives" },
SdlExample{ .path = "examples/audio/01-simple-playback/simple-playback.c", .name = "simple-playback" },
SdlExample{ .path = "examples/audio/02-simple-playback-callback/simple-playback-callback.c", .name = "simple-playback-callback" },
SdlExample{ .path = "examples/audio/03-load-wav/load-wav.c", .name = "load-wav" },
SdlExample{ .path = "examples/camera/01-read-and-draw/read-and-draw.c", .name = "read-and-draw" },
SdlExample{ .path = "examples/game/01-snake/snake.c", .name = "snake" },
SdlExample{ .path = "examples/pen/01-drawing-lines/drawing-lines.c", .name = "drawing-lines" },
SdlExample{ .path = "examples/renderer/01-clear/clear.c", .name = "clear" },
SdlExample{ .path = "examples/renderer/02-primitives/primitives.c", .name = "primitives" },
SdlExample{ .path = "examples/renderer/03-lines/lines.c", .name = "lines" },
SdlExample{ .path = "examples/renderer/04-points/points.c", .name = "points" },
SdlExample{ .path = "examples/renderer/05-rectangles/rectangles.c", .name = "rectangles" },
SdlExample{ .path = "examples/renderer/06-textures/textures.c", .name = "textures" },
SdlExample{ .path = "examples/renderer/07-streaming-textures/streaming-textures.c", .name = "streaming-textures" },
SdlExample{ .path = "examples/renderer/08-rotating-textures/rotating-textures.c", .name = "rotating-textures" },
SdlExample{ .path = "examples/renderer/09-scaling-textures/scaling-textures.c", .name = "scaling-textures" },
SdlExample{ .path = "examples/renderer/10-geometry/geometry.c", .name = "geometry" },
SdlExample{ .path = "examples/renderer/11-color-mods/color-mods.c", .name = "color-mods" },
SdlExample{ .path = "examples/renderer/14-viewport/viewport.c", .name = "viewport" },
SdlExample{ .path = "examples/renderer/15-cliprect/cliprect.c", .name = "cliprect" },
SdlExample{ .path = "examples/renderer/17-read-pixels/read-pixels.c", .name = "read-pixels" },
};

for (sdl_examples) |sdl_example| {
Expand All @@ -801,7 +813,7 @@ pub fn build(b: *std.Build) !void {
.optimize = optimize,
});
exe.addCSourceFile(.{
.file = sdl_dep.path(b.fmt("{s}/{s}.c", .{ path, name })),
.file = sdl_dep.path(path),
.flags = &.{},
});
exe.linkLibrary(lib);
Expand Down Expand Up @@ -1006,6 +1018,7 @@ const generic_src_files = [_][]const u8{
"src/stdlib/SDL_stdlib.c",
"src/stdlib/SDL_string.c",
"src/stdlib/SDL_strtokr.c",
"src/stdlib/SDL_murmur3.c",

"src/storage/SDL_storage.c",
"src/storage/generic/SDL_genericstorage.c",
Expand Down Expand Up @@ -1158,6 +1171,7 @@ const linux_src_files = [_][]const u8{
"src/joystick/hidapi/SDL_hidapi_xboxone.c",
"src/joystick/hidapi/SDL_hidapijoystick.c",
"src/joystick/linux/SDL_sysjoystick.c",
"src/joystick/hidapi/SDL_hidapi_steam_hori.c",

// "src/joystick/n3ds/SDL_sysjoystick.c",
// "src/joystick/ps2/SDL_sysjoystick.c",
Expand Down
10 changes: 4 additions & 6 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@
.paths = .{""},
.dependencies = .{
.sdl = .{
.url = "git+https://github.com/libsdl-org/SDL?ref=main#4f722d372ae7246f123762b0407cbec1e6e71d65",
.hash = "122003b98a58e3b549bbed69d8aa1713f01d53d337dd512e80251918af385da96ef1",
.url = "git+https://github.com/libsdl-org/SDL?ref=main#62938837c239309500d0c078209ace4760909ec8",
.hash = "12204cc7c5c5885c0d804ded40698480a38786a5b30efeab15588e6d53de80682a4a",
},
.sdl_ttf = .{
.url = "git+https://github.com/libsdl-org/SDL_ttf?ref=main#8cb1095cc20a5395bef011051ff625de4d2598c8",
.hash = "1220369b99f58e79b6aeeac68703210f8e32367079ce58e2811192a7a92bee4a81bb",
.url = "git+https://github.com/libsdl-org/SDL_ttf?ref=main#41342890704ef3cac661a0d301f3dd122d96a039",
.hash = "1220c2c929aa0731a6ed363d4aa5beac07d3224e52f3b7a28052efee71ce43512e9c",
},
.freetype = .{
.path = "build/freetype",
// .url = "git+https://gitlab.freedesktop.org/freetype/freetype.git#VER-2-13-2",
// .hash = "1220b81f6ecfb3fd222f76cf9106fecfa6554ab07ec7fdc4124b9bb063ae2adf969d",
},
.fonts = .{
.path = "build/fonts",
Expand Down
9 changes: 1 addition & 8 deletions src/ttf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ const sdl = @import("sdl").c;
const font_file = @import("sdl").fonts.intel_one_mono_regular;

pub fn main() !void {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
const allocator = arena.allocator();

//

if (!sdl.SDL_Init(sdl.SDL_INIT_VIDEO)) {
std.log.err("Unable to initialize SDL: {s}", .{sdl.SDL_GetError()});
return error.SDLInitializationFailed;
Expand Down Expand Up @@ -114,8 +108,7 @@ pub fn main() !void {
.a = @floor(0.87 * 255),
};

const c_str = try allocator.dupeZ(u8, text);
const text_surface = sdl.TTF_RenderText_Solid(font, c_str, color) orelse {
const text_surface = sdl.TTF_RenderText_Blended(font, text.ptr, text.len, color) orelse {
std.log.err("TTF_RenderText_Solid: {s}", .{sdl.SDL_GetError()});
return error.TTF_RenderText_Solid;
};
Expand Down

0 comments on commit 0af12b6

Please sign in to comment.