Cubified / termgl

A terminal-based renderer for OpenGL shaders. Like Shadertoy, but in the terminal.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

termgl

A terminal-based renderer for OpenGL shaders. Like Shadertoy, but in the terminal.

This project uses GLFW to render an invisible OpenGL context, then converts its pixel data to ANSI escape sequences understood by a terminal emulator.

Currently, it supports rendering custom fragment shaders to a single quad that fills the entire terminal window. Support for custom vertex shaders (or geometries) is planned.

It also supports spinning up a secondary thread via pthreads to handle mouse input, allowing shaders that use the iMouse uniform to function properly.

Demos

demo-1.gif

demo-2.gif

demo-3.gif

demo-4.gif

demo-5.gif

Compiling and Running

Prior to compiling, ensure that GLFW and OpenGL have been installed. Then, run:

$ ./configure --with-pthreads
$ make
$ ./termgl demos/1-basic.frag

Assuming a successful compilation, termgl should display the following:

basic.png

To close the application, send a SIGTERM with Ctrl+C.

If on a system without pthreads support, run ./configure without the --with-pthreads argument. This will disable mouse support, but still allow shaders to be rendered.

Running A Custom Shader

To run a custom fragment shader, simply pass its filename as the first argument to termgl. A minimal shader is as follows:

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
  fragColor = vec4(fragCoord, 0.5, 1.0);
}

Running Shaders Directly from Shadertoy

termgl exposes a minimal wrapper that emulates Shadertoy's uniforms and attributes. For most (but not all) shaders, pasting the contents into a file and opening them with termgl should work properly. In particular, termgl exposes:

uniform vec2 iResolution;
uniform vec3 iMouse;
uniform float iTime;

None of these need to be included in the shader code, termgl's wrapper adds these lines automatically (just as Shadertoy does).

Others (such as iDate) are not yet supported.

Notes

  • termgl should work on any platform supported by GLFW including Linux, MacOS, and Windows. However, Windows is untested at this time.
  • Running termgl within a terminal multiplexer such as tmux is not recommended for performance reasons. For best performance, run termgl natively inside a GPU-accelerated terminal such as kitty or alacritty.
  • The GLSL version is system-dependent, but all shaders in demo/ are confirmed to be working with GLSL 1.10 (i.e. #version 110).

To-Do

  • Add the ability to select a different geometry on which to render the shader (e.g. cube, sphere, etc.)
  • Investigate occasional crashes on window resize
  • Add more uniforms and other quality of life improvements
  • Add support for channels (i.e. custom images/textures)

A Few of My Other Terminal Projects

  • tuibox: A single-header terminal UI library
  • vex: A terminal-based hex editor with vi-like keybinds
  • colorslide: A terminal-based color picker with mouse support

About

A terminal-based renderer for OpenGL shaders. Like Shadertoy, but in the terminal.


Languages

Language:C 100.0%