demotomohiro / nim-4k-intro-sample

4k intro sample code written with Nim programming language.
MIT License
14 stars 1 forks source link

nim-4k-intro-sample

4k intro sample code written with Nim programming language. This sample is written for MS Windows.

Build tools

Nim use C compiler in Visual Studio as backend. Crinkler works as linker and compress your code and data. Output executable file from crinkler decompress code at runtime.

Required libraries

How to build Nim sampels

Make sure parent directories of nim and crinker are in PATH environment variable and you can run them from command prompt.

  1. Set LIB environment variable to the directory containing *.lib files to use Windows API.
    • For example:
      set lib=c:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x86
    • Do not use double quote in LIB environment variable. Otherwise crinkler doesn't recognize it.
  2. Build

    git clone https://github.com/demotomohiro/nim-4k-intro-sample.git
    cd nim-4k-intro-sample\src
    • Release build:

      nim c -d:danger minimum.nim
    • Debug build:

      nim c minimum.nim

How to build C samples

Make sure parent directories of nim and crinker are in PATH environment variable and you can run them from command prompt.

  1. Run VS2015 x86 Native Tools command prompt
  2. Set INCLUDE environment variable to the directory containing OpenGL Extension Header Files(GL/glext.h, GL/wglext.h and KHR/khrplatform.h).
    • For example:
      set INCLUDE=c:\path\to\include;%INCLUDE%
  3. Build
    git clone https://github.com/demotomohiro/nim-4k-intro-sample.git
    cd nim-4k-intro-sample\csrc
    minimum_build.bat
    • Each *_build.bat files builds each samples.

Directory structure

openGL4kGen

It downloads and reads the OpenGL Registry XML file and generates a OpenGL wrapper optimized for 4k-intro. It imports OpenGL 1.0 and 1.1 functions with header pragma. Like Official OpenGL interface, it uses undocumented 'dynlib' feature and Nim generate a procedure that load only OpenGL extension functions used in user code. So loadExtensions() must be called after the creation of an OpenGL context and before any OpenGL extension procs are used. It only generates procedures and enums in OpenGL core profile.

How to use openGL4kGen

Following code build openGL4kGen and generate OpenGL wrapper.

cd nim-4k-intro-sample\tools\openGL4kGen
nim c -d:ssl openGL4kGen.nim
openGL4kGen.exe > ..\..\src\openGL4k2.nim

If you want to use OpenGL with Nim not for 4k-intro, use one of them: