Repository navigation
SDL callbacks and iOS simulator support #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cwindolf
wants to merge
10
commits into
allyourcodebase:main
Choose a base branch
from
cwindolf:cw-dev
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ba81850
mac: build complaining about extra defines
cwindolf 1cd7a14
include SDL_main
cwindolf 781ef70
sdl: callbacks working on mac and at least compiling for ios simulator
cwindolf d7bbda8
get ios simulator running
cwindolf 7ecdd9d
merge upstream: mostly --theirs, since there was duplicated work (ios…
cwindolf d9969ab
refactor to better support -Dinclude_path etc rather than calling xcr…
cwindolf 83c333b
merge upstream: use their system path handling
cwindolf f458a57
ios ubsan problem: track down and disable ubsan as narrowly as I can
cwindolf b7f27a8
callbacks: only include the SDL3_main library when using callbacks ra…
cwindolf 41a3149
callbacks: port the example to callbacks and add run-callbacks-example
cwindolf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| const std = @import("std"); | ||
| const sdl = @import("sdl3"); | ||
|
|
||
| // main is provided by SDL_main.h, which calls the SDL_App* callbacks below | ||
| pub extern fn main(argc: c_int, argv: [*c][*c]u8) c_int; | ||
|
|
||
| var window: ?*sdl.SDL_Window = null; | ||
| var renderer: ?*sdl.SDL_Renderer = null; | ||
|
|
||
| export fn SDL_AppInit(appstate: ?*?*anyopaque, argc: c_int, argv: [*c][*c]u8) sdl.SDL_AppResult { | ||
| _ = appstate; | ||
| _ = argc; | ||
| _ = argv; | ||
|
|
||
| // Initialize SDL | ||
| if (!sdl.SDL_Init(sdl.SDL_INIT_VIDEO)) { | ||
| std.debug.panic("{s}", .{sdl.SDL_GetError()}); | ||
| } | ||
|
|
||
| std.debug.print("video driver: {s}\n", .{sdl.SDL_GetCurrentVideoDriver() orelse @as([*c]const u8, "null")}); | ||
|
|
||
| // Create a window and renderer | ||
| if (!sdl.SDL_CreateWindowAndRenderer( | ||
| "example", | ||
| 960, | ||
| 540, | ||
| sdl.SDL_WINDOW_RESIZABLE | sdl.SDL_WINDOW_HIGH_PIXEL_DENSITY, | ||
| &window, | ||
| &renderer, | ||
| )) { | ||
| std.debug.panic("{s}", .{sdl.SDL_GetError()}); | ||
| } | ||
|
|
||
| return sdl.SDL_APP_CONTINUE; | ||
| } | ||
|
|
||
| export fn SDL_AppEvent(appstate: ?*anyopaque, event: ?*sdl.SDL_Event) sdl.SDL_AppResult { | ||
| _ = appstate; | ||
|
|
||
| if (event.?.type == sdl.SDL_EVENT_QUIT) { | ||
| return sdl.SDL_APP_SUCCESS; | ||
| } | ||
| return sdl.SDL_APP_CONTINUE; | ||
| } | ||
|
|
||
| export fn SDL_AppIterate(appstate: ?*anyopaque) sdl.SDL_AppResult { | ||
| _ = appstate; | ||
|
|
||
| // Update the background color | ||
| const now = @as(f64, @floatFromInt(sdl.SDL_GetTicks())) / 1000.0; | ||
| const r: f32 = @floatCast(0.5 + 0.5 * @sin(now)); | ||
| const g: f32 = @floatCast(0.5 + 0.5 * @sin(now + std.math.pi * 2 / 3.0)); | ||
| const b: f32 = @floatCast(0.5 + 0.5 * @sin(now + std.math.pi * 4 / 3.0)); | ||
|
|
||
| if (!sdl.SDL_SetRenderDrawColorFloat(renderer, r, g, b, sdl.SDL_ALPHA_OPAQUE_FLOAT)) { | ||
| std.debug.panic("{s}", .{sdl.SDL_GetError()}); | ||
| } | ||
| if (!sdl.SDL_RenderClear(renderer)) { | ||
| std.debug.panic("{s}", .{sdl.SDL_GetError()}); | ||
| } | ||
| if (!sdl.SDL_RenderPresent(renderer)) { | ||
| std.debug.panic("{s}", .{sdl.SDL_GetError()}); | ||
| } | ||
|
|
||
| return sdl.SDL_APP_CONTINUE; | ||
| } | ||
|
|
||
| export fn SDL_AppQuit(appstate: ?*anyopaque, result: sdl.SDL_AppResult) void { | ||
| _ = appstate; | ||
| _ = result; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| #include <SDL3/SDL_main.h> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be reasonable to duplicate the example program and rename it to
callbacks_example, and make use of this feature there.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, this is added! (Runs with
zig build run-callbacks-example -Dmain_callbacks.) I decided to have it error out if no-Dmain_callbacks.