glsl code blocks for org-mode

Overview

GLSL code blocks for Emacs Org-mode

This org-mode extension adds the capability to run GLSL code blocks directly from inside Emacs and immediately displays the rendering results inline in your org-mode buffers.

Requirements

  • SDL2 (for creating OpenGL context)
  • SDL2_image (for saving PNG files)
  • glbinding (for OpenGL SDK)

The rendering is done with OpenGL 3.3 so should work on any graphcs card.

Building

  1. Generate project with CMake:
    cmake -G "Ninja" .
        
  2. Build the code:
    ninja
        

This will create the Emacs dynamic module ob-glsl-module.so (Linux) or ob-glsl-module.dll (Windows) or ob-glsl-module.dylib (MacOS).

Installing

  1. Put both ob-glsl.el and the dynamic module under your elisp load path.
  2. Add (glsl . t) to org-babel-load-languages. You can either customize the variable or add it manually in lisp code.

Supported parameters

  • :file The output file path (required)
  • :width The render width in pixels
  • :height The render height in pixels

You can omit either :width or :height and the omitted one will be calculated based on the other parameter. If you omit both, then the default output size is 400x300.

A simple pixel shader example

vec3 mandel(vec2 z0) {
    float k = 0.0;
    vec2 z = vec2(0.0);
    for(int i = 0; i < 420; ++i) {
        z = vec2(z.x*z.x-z.y*z.y, z.x*z.y*2.0) + z0;
        if (length(z) > 20.0) break;
        k += 1.0;
    }
    float mu = k + 1.0 - log2(log(length(z)));
    return sin(mu*0.1 + vec3(0.0,0.5,1.0));
}
void main() {
    float ar = iResolution.x / iResolution.y;
    vec2 uv = gl_FragCoord.xy / iResolution.yy - vec2(0.66 * ar, 0.5);
    // uv = uv * 2.0 + vec2(-0.3, 0.0);
    float p = 30.0;
    float t = mod(13.0, p);
    if (t > p/2.0) t = p - t;
    float scale = 0.5 + pow(2.0, t);
    vec2 offset = vec2(-1.36799, .01);
    uv += offset*scale;
    uv /= scale;
    fragColor = vec4(mandel(uv), 1.0);
}

img/mandel.png

You might also like...
HLSL Parser and Translator for HLSL, GLSL, and MSL.

HLSLParser This is a fork of Unknownworld's hlslparser adapted to our needs in The Witness. We currently use it to translate pseudo-HLSL shaders (usin

HLSL to GLSL language translator based on ATI's HLSL2GLSL. Used in Unity.

HLSL to GLSL shader language translator ⚠️ As of mid-2016, the project is unlikely to have any significant developments. At Unity we are moving to a d

HLSL Parser and Translator for HLSL, GLSL, and MSL.

HLSLParser This is a fork of Unknownworld's hlslparser adapted to our needs in The Witness. We currently use it to translate pseudo-HLSL shaders (usin

Simple printf functionality for GLSL.

Simple printf functionality for GLSL. This library is a simple proof of concept of using printf directly from a shader. The main point of being able

Shader cross compiler to translate HLSL (Shader Model 4 and 5) to GLSL
Shader cross compiler to translate HLSL (Shader Model 4 and 5) to GLSL

XShaderCompiler ("Cross Shader Compiler") Features Cross compiles HLSL shader code (Shader Model 4 and 5) into GLSL Simple to integrate into other pro

An efficient texture-free GLSL procedural noise library

Wombat An efficient texture-free GLSL procedural noise library Source: https://github.com/BrianSharpe/Wombat Derived from: https://github.com/BrianSha

Fast glsl deNoise spatial filter, with circular gaussian kernel, full configurable
Fast glsl deNoise spatial filter, with circular gaussian kernel, full configurable

glslSmartDeNoise Fast glsl spatial deNoise filter, with circular gaussian kernel and smart/flexible/adaptable - full configurable: Standard Deviation

Khronos-reference front end for GLSL/ESSL, partial front end for HLSL, and a SPIR-V generator.

News Visual Studio 2013 is no longer supported As scheduled, Microsoft Visual Studio 2013 is no longer officially supported. Please upgrade to at leas

x64 Windows kernel code execution via user-mode, arbitrary syscall, vulnerable IOCTLs demonstration
x64 Windows kernel code execution via user-mode, arbitrary syscall, vulnerable IOCTLs demonstration

anycall x64 Windows kernel code execution via user-mode, arbitrary syscall, vulnerable IOCTLs demonstration Read: https://www.godeye.club/2021/05/14/0

Comments
  • Always get a 1kb image file on M1 MacOS

    Always get a 1kb image file on M1 MacOS

    I successfully built the module and loaded it to emacs by

    (add-to-list 'load-path "~/.emacs.d/lisp")
    
    (org-babel-do-load-languages
     'org-babel-load-languages
     '((glsl . t)))
    

    However, I always get no result, the .png file is always an empty 1 Kb image only.

    image

    When compiling the module, I get this warning:

    [3/4] Building CXX object CMakeFiles/ob-glsl-module.dir/Main.cpp.o
    Main.cpp:86:40: warning: implicit conversion of nullptr constant to 'bool' [-Wnull-conversion]
            glbinding::Binding::initialize(nullptr);
            ~~~~~~~~~                      ^~~~~~~
                                           false
    1 warning generated.
    [4/4] Linking CXX shared library ob-glsl-module.dylib
    

    Maybe this is the reason?

    I have very limited knowledge both Emacs modules in C or openGL, and I am not sure about how to debug in this situation. Sorry for that.

    Also, the glbinding from my package manager is still 2.1.4.

    opened by shenlebantongying 5
  • ""SDL2::SDL2-static" was not found" on Archlinux

    CMake Error at CMakeLists.txt:11 (add_library):
      Target "ob-glsl-module" links to target "SDL2::SDL2-static" but the target
      was not found.  Perhaps a find_package() call is missing for an IMPORTED
      target, or an ALIAS target is missing?
    

    For unknown and mythical reason, on Archlinux, the static lib is named as libSDL2main.a rather than libSDL2.a. https://github.com/archlinux/svntogit-packages/blob/07aecf0c44807cd19307b693b9768e3557dc0d53/trunk/PKGBUILD#L51

    To build on Archlinux, one have to change this line

    target_link_libraries(${PROJECT_NAME} SDL2::SDL2-static ${GLBINDING_LIB} ${SDL2_IMAGE_LIB})
    

    to

    target_link_libraries(${PROJECT_NAME} SDL2::SDL2main ${GLBINDING_LIB} ${SDL2_IMAGE_LIB})
    

    And the ob-glsl works :D :+1:

    opened by shenlebantongying 4
  • build failure

    build failure "Main.cpp:92:14: error: expected type-specifier"

    rob@oven:~/src/ob-glsl$ ninja
    [1/2] Building CXX object CMakeFiles/ob-glsl-module.dir/Main.cpp.o
    FAILED: CMakeFiles/ob-glsl-module.dir/Main.cpp.o 
    /usr/bin/c++  -Dob_glsl_module_EXPORTS -I/usr/local/include -fPIC   -std=gnu++17 -MD -MT CMakeFiles/ob-glsl-module.dir/Main.cpp.o -MF CMakeFiles/ob-glsl-module.dir/Main.cpp.o.d -o CMakeFiles/ob-glsl-module.dir/Main.cpp.o -c Main.cpp
    Main.cpp:92:14: error: expected type-specifier
         operator glbinding::GetProcAddress() const {return nullptr;}
                  ^~~~~~~~~
    ninja: build stopped: subcommand failed.
    rob@oven:~/src/ob-glsl$ 
    
    
    opened by biffhero 2
  • Autocompile / melpa compatibility

    Autocompile / melpa compatibility

    The following allows for loading this package via quelpa directly from .emacs as follows:

    (use-package glsl-mode)
    (use-package ob-glsl
      :after glsl-mode
      :quelpa (ob-glsl
    		   :fetcher github
    		   :repo "finalpatch/ob-glsl"
    		   :files ("*.el" "*.cpp" "*.hpp" "CMakeLists.txt" "*.h" "*.so"))
      :custom
      (org-babel-do-load-languages
       'org-babel-load-languages
       '((glsl . t))))
    

    Obviously, replace "finalpatch/ob-glsl" with "shizcow/ob-glsl" for a working example.

    Being able to load this package with quelpa makes it one step closer to being melpa-compatible and able to be loaded with a simple (use-package ob-glsl).

    Note on cleanliness

    I'm not particularly versed in writing emacs packages, so I probable made some big mistakes here. The provided changes aren't really intended as a final product, but as a push towards the eventual goal of making this package more accessible.

    opened by Shizcow 1
Owner
null
LLVM IR and optimizer for shaders, including front-end adapters for GLSL and SPIR-V and back-end adapter for GLSL

Licensing LunarGLASS is available via a three clause BSD-style open source license. Goals The primary goals of the LunarGLASS project are: Reduce the

LunarG, Inc. 153 Dec 8, 2022
⚔️ A tool for cross compiling shaders. Convert between GLSL, HLSL, Metal Shader Language, or older versions of GLSL.

A cross compiler for shader languages. Convert between SPIR-V, GLSL / GLSL ES, HLSL, Metal Shader Language, or older versions of a given language. Cross Shader wraps glslang and SPIRV-Cross, exposing a simpler interface to transpile shaders.

Alain Galvan 207 Dec 30, 2022
GLSL optimizer based on Mesa's GLSL compiler. Used to be used in Unity for mobile shader optimization.

GLSL optimizer ⚠️ As of mid-2016, the project is unlikely to have any significant developments. At Unity we are moving to a different shader compilati

Aras Pranckevičius 1.6k Jan 3, 2023
If the button pressed esp will reset and App mode will on. App mode will on then led will on, network is connected led will off.

DHT22-to-Google-sheet-Reset-Using-ESP8266-LED-Switch If button pressed esp will reset and App mode will on. App mode will on then led will on, network

Md. Harun-Or-Rashid 3 Aug 17, 2022
Building blocks for modern GNOME applications

Adwaita Building blocks for modern GNOME applications. License Libadwaita is licensed under the LGPL-2.1+. Building We use the Meson (and thereby Ninj

Muqtadir 3 Jan 19, 2022
Minify and obfuscate GLSL or HLSL code

Shader Minifier Shader Minifier is a tool that minifies and obfuscates shader code (GLSL and HLSL). Its original use-case is for the demoscene, for op

Laurent Le Brun 251 Jan 2, 2023
Qnicorn: a cutting edge version of unicorn-engine.org

Qnicorn Engine Qnicorn is a cutting edge and community-driven version of unicorn-engine. Qnicorn offers the features below: All features that Unicorn2

qiling.io 4 Sep 10, 2022
Boost.org program_options module

Program Options, part of the collection of Boost C++ Libraries, allows for definition and acquisition of (name, value) pairs from the user via convent

Boost.org 77 Jan 1, 2023
this is my simple voxel engine, appart from librairies like glad it is entierly written in C++ and GLSL

simple-voxel-raycaster this is my simple voxel engine, appart from librairies like glad it is entierly written in C++ and GLSL here is a gif: https://

null 2 Sep 26, 2022
VSIX Project that provides GLSL language integration.

GLSL language integration (for VS2017, 2019 and 2022) Download this extension from Visual Studio Marketplace version VS2017 & 2019 or VS 2022 preview

Daniel Scherzer 208 Dec 24, 2022