Skip to content

Commit

Permalink
Cocoa Metal example (no SDL).
Browse files Browse the repository at this point in the history
  • Loading branch information
yay committed Aug 27, 2024
1 parent 3f631b9 commit adf48a6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@

**.exp
tetroid.lib
build.bat
build.bat
ols.json

.vscode
.idea
44 changes: 24 additions & 20 deletions learn_metal/02-argbuffers-no-sdl/02-argbuffers-no-sdl.odin
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ main :: proc() {
}

metal_main :: proc() -> (err: ^NS.Error) {
NS.scoped_autoreleasepool()

app := NS.Application.sharedApplication()
app->setActivationPolicy(.Regular) // without this window is not brought to foreground on launch
defer app->release()
Expand Down Expand Up @@ -74,24 +72,29 @@ metal_main :: proc() -> (err: ^NS.Error) {
command_queue := device->newCommandQueue()
defer command_queue->release()

for {
event := app->nextEventMatchingMask(NS.EventMaskAny, NS.Date.distantFuture(), NS.DefaultRunLoopMode, true)

@static angle: f32

event_type := event->type()
#partial switch event_type {
case .KeyDown, .KeyUp:
code := NS.kVK(event->keyCode())
#partial switch code {
case .LeftArrow:
angle -= 0.02
case .RightArrow:
angle += 0.02
@static angle: f32

for quit := false; !quit; {
{
NS.scoped_autoreleasepool()
event := app->nextEventMatchingMask(NS.EventMaskAny, NS.Date.distantFuture(), NS.DefaultRunLoopMode, true)
event_type := event->type()
#partial switch event_type {
case .KeyDown, .KeyUp:
code := NS.kVK(event->keyCode())
#partial switch code {
case .Escape:
quit = true
case .LeftArrow:
angle -= 0.02
case .RightArrow:
angle += 0.02
}
fmt.println(event_type, code)
case:
fmt.println(event_type, event->locationInWindow(), event->modifierFlags())
}
fmt.println(event_type, code)
case:
fmt.println(event_type, event->locationInWindow(), event->modifierFlags())
app->sendEvent(event)
}

frame_data := (^Frame_Data)(frame_data_buffer->contentsPointer())
Expand Down Expand Up @@ -129,9 +132,10 @@ metal_main :: proc() -> (err: ^NS.Error) {
command_buffer->presentDrawable(drawable)
command_buffer->commit()

app->sendEvent(event)
app->updateWindows()
}

return nil
}

Frame_Data :: struct {
Expand Down
2 changes: 1 addition & 1 deletion learn_metal/02-argbuffers/02-argbuffers.odin
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ metal_main :: proc() -> (err: ^NS.Error) {
defer command_queue->release()

SDL.ShowWindow(window)
for quit := false; !quit; {
for quit := false; !quit; {
for e: SDL.Event; SDL.PollEvent(&e); {
#partial switch e.type {
case .QUIT:
Expand Down

0 comments on commit adf48a6

Please sign in to comment.