{"id":15047394,"url":"https://github.com/klihe/sdl2-setup-macos","last_synced_at":"2025-03-13T20:20:37.503Z","repository":{"id":223062163,"uuid":"759207299","full_name":"Klihe/SDL2-Setup-MACOS","owner":"Klihe","description":"One day I was trying to search for something like pygame for C++ and I found SDL2, but the implementation of this library was not easy for me. I decided to make this tutorial on how to implement SDL2 on MACOS which works for me","archived":false,"fork":false,"pushed_at":"2024-02-18T20:22:00.000Z","size":3,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-20T15:59:11.955Z","etag":null,"topics":["c","c11","cpp","cpp11","game","library","sdl","sdl2","sdl2-library","tutorail"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Klihe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-17T23:59:06.000Z","updated_at":"2024-06-19T17:02:32.000Z","dependencies_parsed_at":"2024-02-18T02:25:09.154Z","dependency_job_id":"d2a14f17-9904-4081-8ae9-9ebef5b15b74","html_url":"https://github.com/Klihe/SDL2-Setup-MACOS","commit_stats":null,"previous_names":["klihe/sdl2-for-macos","klihe/sdl2-setup-macos"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Klihe%2FSDL2-Setup-MACOS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Klihe%2FSDL2-Setup-MACOS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Klihe%2FSDL2-Setup-MACOS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Klihe%2FSDL2-Setup-MACOS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Klihe","download_url":"https://codeload.github.com/Klihe/SDL2-Setup-MACOS/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243475328,"owners_count":20296714,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","c11","cpp","cpp11","game","library","sdl","sdl2","sdl2-library","tutorail"],"created_at":"2024-09-24T20:57:40.154Z","updated_at":"2025-03-13T20:20:37.472Z","avatar_url":"https://github.com/Klihe.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# SDL2 for MACOS\n#### It's can be also for C (with small changes)\n\n### Stracture of Project\n```tree\n├── Makefile\n├── build\n│   └── debug\n├── include\n│   ├── SDL2 -\u003e /opt/homebrew/Cellar/sdl2/2.30.0/include/SDL2\n│   ├── SDL2_image -\u003e /opt/homebrew/Cellar/sdl2_image/2.8.2/include/SDL2\n│   └── SDL2_ttf -\u003e /opt/homebrew/Cellar/sdl2_ttf/2.22.0/include\n├── lib\n│   ├── SDL2 -\u003e /opt/homebrew/Cellar/sdl2/2.30.0/lib\n│   ├── SDL2_image -\u003e /opt/homebrew/Cellar/sdl2_image/2.8.2/lib\n│   └── SDL2_ttf -\u003e /opt/homebrew/Cellar/sdl2_ttf/2.22.0/lib\n└── src\n    └── main.cpp\n```\n# Steps\n\n1. Install brew:\\\n    `\"/bin/bash -c \"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\"`\n   \n2. `brew install sdl2`\\\n   `brew install sdl2_image`\\\n   `brew install sdl2_ttf`\n\n3. Open the project file terminal\n\n4. Create project layout: `mkdir -p build/debug include lib src`\n   \n5. Finding the location of the sdl2:\\\n    `brew list sdl2`\\\n    `brew list sdl2_image`\\\n    `brew list sdl2_ttf`\n\n6. My location of files:\n    ## SDL2\n    ```\n    /opt/homebrew/Cellar/sdl2/2.30.0/bin/sdl2-config\n    /opt/homebrew/Cellar/sdl2/2.30.0/include/SDL2/ (78 files)\n    /opt/homebrew/Cellar/sdl2/2.30.0/lib/libSDL2-2.0.0.dylib\n    /opt/homebrew/Cellar/sdl2/2.30.0/lib/cmake/ (2 files)\n    /opt/homebrew/Cellar/sdl2/2.30.0/lib/pkgconfig/sdl2.pc\n    /opt/homebrew/Cellar/sdl2/2.30.0/lib/ (4 other files)\n    /opt/homebrew/Cellar/sdl2/2.30.0/share/aclocal/sdl2.m4\n    ```\n    ## SDL2_image\n    ```\n    /opt/homebrew/Cellar/sdl2_image/2.8.2/include/SDL2/SDL_image.h\n    /opt/homebrew/Cellar/sdl2_image/2.8.2/lib/libSDL2_image-2.0.0.dylib\n    /opt/homebrew/Cellar/sdl2_image/2.8.2/lib/cmake/ (2 files)\n    /opt/homebrew/Cellar/sdl2_image/2.8.2/lib/pkgconfig/SDL2_image.pc\n    /opt/homebrew/Cellar/sdl2_image/2.8.2/lib/ (2 other files)\n    ```\n    ## SDL2_ttf\n    ```\n    /opt/homebrew/Cellar/sdl2_ttf/2.22.0/include/SDL2/SDL_ttf.h\n    /opt/homebrew/Cellar/sdl2_ttf/2.22.0/lib/libSDL2_ttf-2.0.0.dylib\n    /opt/homebrew/Cellar/sdl2_ttf/2.22.0/lib/cmake/ (2 files)\n    /opt/homebrew/Cellar/sdl2_ttf/2.22.0/lib/pkgconfig/SDL2_ttf.pc\n    /opt/homebrew/Cellar/sdl2_ttf/2.22.0/lib/ (2 other files)\n    ```\n\n7. Linking sdl2 files:\n   ## SDL2\n   into include: `ln -s /opt/homebrew/Cellar/sdl2/2.30.0/include/SDL2 ./include/SDL2`\\\n   into lib: `ln -s /opt/homebrew/Cellar/sdl2/2.30.0/lib ./lib/SDL2`\n   ## SDL2_image\n    into include: `ln -s /opt/homebrew/Cellar/sdl2_image/2.8.2/include/SDL2 ./include/SDL2_image`\\\n    into lib: `ln -s /opt/homebrew/Cellar/sdl2_image/2.8.2/lib ./lib/SDL2_image`\n   ## SDL2_ttf\n    into include: `ln -s /opt/homebrew/Cellar/sdl2_ttf/2.22.0/include/SDL2 ./include/SDL2_ttf`\\\n    into lib: `ln -s /opt/homebrew/Cellar/sdl2_ttf/2.22.0/lib ./lib/SDL2_ttf`\n\n8.  Create main.pp and Makefile: \n    ```\n    touch src/main.cpp\n    touch Makefile\n    ```\n9.  Code for Makefile\n    ```Makefile\n    SRC_DIR = src\n    BUILD_DIR = build/debug\n    CC = g++\n    SRC_FILES = $(wildcard $(SRC_DIR)/*.cpp)\n    OBJ_NAME = play\n    INCLUDE_PATHS = -I include/SDL2 -I include/SDL2_image -I include/SDL2_ttf\n    LIBRARY_PATHS = -L lib/SDL2 -L lib/SDL2_image -L lib/SDL2_ttf\n    COMPILER_FLAGS = -std=c++11 -Wall -O0 -g\n    LINKER_FLAGS = -lSDL2 -lSDL2_image -lSDL2_ttf\n\n    all:\n        $(CC) $(COMPILER_FLAGS) $(LINKER_FLAGS) $(INCLUDE_PATHS) $(LIBRARY_PATHS) $(SRC_FILES) -o $(BUILD_DIR)/$(OBJ_NAME)\n    ```\n\n1.  Code for main.cpp\n    ````cpp\n    #include \u003cSDL.h\u003e\n    #include \u003ciostream\u003e\n\n    int main() {\n        std::cout \u003c\u003c \"Hello, SDL!\" \u003c\u003c std::endl;\n\n        // Initialize SDL\n        if (SDL_Init(SDL_INIT_VIDEO) != 0) {\n            std::cerr \u003c\u003c \"SDL_Init Error: \" \u003c\u003c SDL_GetError() \u003c\u003c std::endl;\n            return 1;\n        }\n\n        // Create a window\n        SDL_Window* window = SDL_CreateWindow(\"SDL Window\", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);\n        if (window == nullptr) {\n            std::cerr \u003c\u003c \"SDL_CreateWindow Error: \" \u003c\u003c SDL_GetError() \u003c\u003c std::endl;\n            SDL_Quit();\n            return 1;\n        }\n\n        // Create a renderer\n        SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);\n        if (renderer == nullptr) {\n            std::cerr \u003c\u003c \"SDL_CreateRenderer Error: \" \u003c\u003c SDL_GetError() \u003c\u003c std::endl;\n            SDL_DestroyWindow(window);\n            SDL_Quit();\n            return 1;\n        }\n\n        SDL_Event e;\n        bool quit = false;\n        while (!quit){\n            while (SDL_PollEvent(\u0026e)){\n                if (e.type == SDL_QUIT){\n                    quit = true;\n                }\n                if (e.type == SDL_KEYDOWN){\n                    quit = true;\n                }\n                if (e.type == SDL_MOUSEBUTTONDOWN){\n                    quit = true;\n                }\n            }\n            // Set render color to blue\n            SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);\n\n            // Clear the window with the render color\n            SDL_RenderClear(renderer);\n\n            // Update the screen\n            SDL_RenderPresent(renderer);\n        }\n\n        // Clean up resources\n        SDL_DestroyRenderer(renderer);\n        SDL_DestroyWindow(window);\n        SDL_Quit();\n\n        return 0;\n    }\n2.  Test:\\\n    `make`\\\n    `.\\build\\debug\\play`\n\n# If you have white window on your screen everything is set.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fklihe%2Fsdl2-setup-macos","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fklihe%2Fsdl2-setup-macos","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fklihe%2Fsdl2-setup-macos/lists"}