o
odinpkg.dev
packages / library / odin_sdl2_template

odin_sdl2_template

786878blibrary

No description provided.

MIT · updated 3 months ago

Odin SDL2 Template

This is a simple Odin project template with SDL2.

If you don't have Odin setup, then check Odin Setup section.

If you want to setup Odin Language Server (OLS), then check OLS Setup section.

If you want SDL3 instead, check Odin SDL3 Template

Table of Contents

Requirements

Windows

  • On Windows you need to copy SDL2 library binaries from Odin vendor directory into place where your executable is located, in this template that will be build/output

  • Alternatively you can download SDL2 library binaries from Odin repo into build/output by running:

    .\build.bat get-sdl
    
  • If you want to build SDL2 library binaries yourself, then run build script

    .\build.bat build-sdl
    

Linux

  • Install SDL2 through apt

    sudo apt update
    sudo apt install libsdl2-dev
    
  • If you want to build SDL2 library binaries yourself, then

    • Install dependencies

      sudo apt update
      sudo apt install build-essential cmake git gnome-desktop-testing libasound2-dev libaudio-dev libdbus-1-dev libdecor-0-dev libdrm-dev libegl1-mesa-dev libgbm-dev libgl1-mesa-dev libgles2-mesa-dev libibus-1.0-dev libjack-dev libpipewire-0.3-dev libpulse-dev libsndio-dev libudev-dev liburing-dev libwayland-dev libx11-dev libxcursor-dev libxext-dev libxfixes-dev libxi-dev libxkbcommon-dev libxrandr-dev libxss-dev libxtst-dev make ninja-build pkg-config
      
    • Run build script

      ./build.sh build-sdl
      

Usage

Windows

# Build executable
./build.bat build

# Build executable in debug mode
./build.bat build-debug

# Build executable and run
./build.bat run

# Build executable and run in debug mode
./build.bat run-debug

Linux

Same as Windows, but using build.sh script

Odin Setup

For more information check official installation guide

Windows

  • Download and install Visual Studio (Desktop development with C++)

  • Clone Odin repository and run build script

    git clone https://github.com/odin-lang/Odin.git odin
    cd odin
    .\build.bat release
    
    # Delete build.bat if you are adding Odin to path
    del build.bat
    
  • Add Odin directory to path in Environment Variables

Linux

  • Install clang

    sudo apt install clang
    
  • Clone Odin repository and run build script

    git clone https://github.com/odin-lang/Odin.git odin
    cd odin
    ./build_odin.sh release
    
  • Add Odin directory to path in .bashrc

    echo 'export PATH="$PATH:<PATH_TO_ODIN>"' >> ~/.bashrc
    
    # If you have Odin in home directory
    echo 'export PATH="$PATH:$HOME/odin"' >> ~/.bashrc
    

OLS Setup

OLS is Odin Language Server, for more information check OLS repository

Windows

  • Clone OLS repository and run build script

    git clone https://github.com/DanielGavin/ols.git
    cd ols
    .\build.bat
    
  • Add OLS directory to path in Environment Variables

Linux

  • Clone OLS repository and run build script

    git clone https://github.com/DanielGavin/ols.git
    cd ols
    ./build.sh
    
  • Add OLS directory to path in .bashrc

    echo 'export PATH="$PATH:<PATH_TO_OLS>"' >> ~/.bashrc
    
    # If you have OLS in home directory
    echo 'export PATH="$PATH:$HOME/ols"' >> ~/.bashrc
    

OLS in VS Code

  • Install OLS extension

  • If you have OLS added to path, then set ols.server.path to ols

  • If you don't have OLS added to path, then set ols.server.path to actual path of OLS executable

  • Set ODIN_ROOT environment variable to path of Odin directory

    # On Windows
    Add Odin directory to path in **Environment Variables**
    
    # On Linux, if you have OLS in home directory
    echo 'export ODIN_ROOT="$HOME/odin"' >> ~/.bashrc
    
  • Optionally you can create ols.json file in project folder to configure OLS, check schema for more info

    {
        "$schema": "https://raw.githubusercontent.com/DanielGavin/ols/master/misc/ols.schema.json",
        "enable_semantic_tokens": false,
        "enable_document_symbols": true,
        "enable_hover": true,
        "enable_snippets": true,
        "profile": "default",
        "profiles": [
            {
                "name": "default",
                "checker_path": ["source"]
            },
        ]
    }
    

OLS in Sublime Text

  • First you need to have Package Control installed

  • To install, open console by clicking View > Show Console in menu bar and run this command:

    from urllib.request import urlretrieve;urlretrieve(url="https://github.com/wbond/package_control/releases/latest/download/Package.Control.sublime-package", filename=sublime.installed_packages_path() + '/Package Control.sublime-package')
    
  • Open Command Palette and search for Install Package, then install these packages: Odin and LSP

  • To configure OLS, open LSP settings by clicking Preferences > Package Settings > LSP > Settings

  • Paste this into settings

    • This assumes you have OLS executable in path, otherwise set full path yourself in command array

    • This has OLS enabled for all projects, set enabled to false if you don't want that

      {
          "clients": {
              "odin": {
                  "command": [
                      "ols"
                  ],
                  "enabled": true,
                  "selector": "source.odin",
                  "initializationOptions": {
                      "enable_semantic_tokens": true,
                      "enable_document_symbols": true,
                      "enable_hover": true,
                      "enable_snippets": true,
                      "enable_format": true,
                  }
              }
          }
      }
      
  • To enable OLS for specific projects, you need to have .sublime-project file in your folder

  • Open Command Palette and search for LSP Enable in Project, then select odin

Debugging

For debugging you can use RAD Debugger

  • Build odin in debug mode and then attach executable to RAD Debugger
  • After that you can put breakpoints and run it