Odin Language Examples

repository·master·Indexed 18 days ago

https://github.com/odin-lang/examples

A collection of idiomatic Odin language examples demonstrating best practices for using the language, core libraries, and vendor libraries. Includes practical implementations for code generation, networking (TCP/UDP echo servers), graphics (Vulkan, Raylib, Metal), audio (miniaudio), WebAssembly (js_wasm32), and Windows-specific resource embedding.

Tokens
2.8K
Snippets
20
Records
24
Agent score
66%

What's inside odin-lang-examples

  1. Run Odin examples

    master

    To run an example from this repository, clone the repository and navigate into the specific example's directory. Most examples can be executed using the odin run . command. Note that some examples may contain a local README file with specific instructions or additional requirements.

    # Navigate to an example directory
    cd path/to/example
    
    # Run the example
    odin run .
  2. Run Raylib port examples

    master

    The Raylib examples in this repository mirror the structure of the official Raylib examples. To ensure correct resource loading and execution, you must follow two requirements:

    1. Run from the example's directory: You must cd into the specific subdirectory containing the example before running the command.
    2. Use the -file flag: You must pass the -file flag to the odin run command.

    Example for running shaders/shaders_mesh_instancing.odin:

    cd shaders
    odin run shaders_mesh_instancing.odin -file
  3. Run the Absolute Beginners example

    master

    To execute the basic Odin features demonstrated in this example, navigate to the absolute_beginners directory in your terminal and use the odin run command. Note that the output is designed to be read alongside the source code in 1_main.odin to understand the fundamental programming concepts being demonstrated.

    odin run .
  4. Recompile shaders for the Vulkan example

    master

    The example uses pre-compiled SPIR-V shaders (vert.spv and frag.spv). If you modify the source shader files (shader.vert or shader.frag), you must recompile them using glslc (part of the Vulkan SDK) before running the Odin code.

    glslc shader.vert -o vert.spv
    glslc shader.frag -o frag.spv
  5. Run the js_wasm32 web example using a local server

    master

    Because the example involves a website calling Odin procedures via WASM, you must serve the web directory using a local web server.

    1. Navigate to the web directory:
    cd web
    1. Start a web server using one of the following methods:

    Using Python:

    python -m http.server

    Using Node.js (npx):

    npx http-server -p 8000 .
    1. Open your browser and visit http://localhost:8000 (or the port specified by your server).
    cd web
    npx http-server -p 8000 .
  6. Build an Odin program for the js_wasm32 target

    master

    To build an Odin program targeting js_wasm32, use the provided build scripts. These scripts compile the WASM module and automatically copy the required odin.js file from the core Odin library into your project directory.

    • Windows: Run build.bat
    • macOS / Linux: Run build.sh
    ./build.sh
  7. Embed a Windows manifest using Odin

    master

    Windows manifests (metadata for UAC, DPI awareness, or visual styles) can be embedded into an executable using a .rc (resource script) file. To embed a manifest as a regular resource, use the RT_MANIFEST type (numeric value 24) and assign the main application manifest the resource ID 1.

    # Compile the project including the resource script
    odin build . -resource:resource.rc
  8. Run the UDP Echo Server example

    master

    To start the UDP Echo Server, navigate to the example directory and use the Odin compiler to run the server package. The server will listen for incoming UDP packets and echo the received data back to the client.

    Requirements:

    • Odin Compiler (latest stable version)
    • A terminal or command prompt
    odin run server