Last active
October 13, 2025 01:15
-
-
Save gcatlin/987be74e2d58da96093a7598f3fbfb27 to your computer and use it in GitHub Desktop.
Revisions
-
gcatlin revised this gist
Dec 14, 2022 . 1 changed file with 1 addition and 1 deletion.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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ // // cc glfw-metal-example.m `pkg-config --cflags --libs glfw3` -framework AppKit -framework Metal -framework QuartzCore // #define GLFW_INCLUDE_NONE #define GLFW_EXPOSE_NATIVE_COCOA -
gcatlin revised this gist
May 22, 2019 . 1 changed file with 1 addition and 1 deletion.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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ // // cc glfw-metal-example.m -lGLFW -framework AppKit -framework Metal -framework QuartzCore // #define GLFW_INCLUDE_NONE #define GLFW_EXPOSE_NATIVE_COCOA -
gcatlin renamed this gist
Nov 29, 2018 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
gcatlin created this gist
Nov 4, 2018 .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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,63 @@ // // cc sdl-glfw-exampl.m -lGLFW -framework AppKit -framework Metal -framework QuartzCore // #define GLFW_INCLUDE_NONE #define GLFW_EXPOSE_NATIVE_COCOA #include <GLFW/glfw3.h> #include <GLFW/glfw3native.h> #import <Metal/Metal.h> #import <QuartzCore/CAMetalLayer.h> static void quit(GLFWwindow *window, int key, int scancode, int action, int mods) { if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) { glfwSetWindowShouldClose(window, GLFW_TRUE); } } int main(void) { const id<MTLDevice> gpu = MTLCreateSystemDefaultDevice(); const id<MTLCommandQueue> queue = [gpu newCommandQueue]; CAMetalLayer *swapchain = [CAMetalLayer layer]; swapchain.device = gpu; swapchain.opaque = YES; glfwInit(); glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); GLFWwindow *window = glfwCreateWindow(640, 480, "GLFW Metal", NULL, NULL); NSWindow *nswindow = glfwGetCocoaWindow(window); nswindow.contentView.layer = swapchain; nswindow.contentView.wantsLayer = YES; glfwSetKeyCallback(window, quit); MTLClearColor color = MTLClearColorMake(0, 0, 0, 1); while (!glfwWindowShouldClose(window)) { glfwPollEvents(); @autoreleasepool { color.red = (color.red > 1.0) ? 0 : color.red + 0.01; id<CAMetalDrawable> surface = [swapchain nextDrawable]; MTLRenderPassDescriptor *pass = [MTLRenderPassDescriptor renderPassDescriptor]; pass.colorAttachments[0].clearColor = color; pass.colorAttachments[0].loadAction = MTLLoadActionClear; pass.colorAttachments[0].storeAction = MTLStoreActionStore; pass.colorAttachments[0].texture = surface.texture; id<MTLCommandBuffer> buffer = [queue commandBuffer]; id<MTLRenderCommandEncoder> encoder = [buffer renderCommandEncoderWithDescriptor:pass]; [encoder endEncoding]; [buffer presentDrawable:surface]; [buffer commit]; } } glfwDestroyWindow(window); glfwTerminate(); return 0; }