andersch.dev

[ cpp ]
<2024-05-31>

Embedding a Binary File into a C/C++ Program

How to bake any file as a buffer into your executable

How to embed a binary into your program

READ MORE

<2024-05-29>

Hot-Reloadable, Embedded Shader Code in C/C++

How to include a GLSL shader as a string inside your code (and still make it hot-reloadable)

Most OpenGL tutorials that start you out on shaders will tell you to include your first shaders as string literals by writing out the GLSL code out like this:

const char* vertex_shader_source = "#version 330 core\n"
    "layout(location = 0) in vec3 aPos;\n"
    "void main() {\n"
    "    gl_Position = vec4(aPos, 1.0);\n"
    "}\0";

This is done because it has the benefit of being able to pass over file IO & parsing code and instead focus on teaching actual OpenGL/GLSL specific concepts. It would also be useful for fast prototyping with more complex shaders, if it wasn't for the fact that…

  • Writing out "...\n" for every line is tedious and easy to forget
  • You don't get any syntax highlighting for the GLSL code
  • It makes shader hot-reloading impossible (or does it?)

I was exploring better ways on how to include the shader without having to write some bespoke shader management code that loads in files, allocates memory for the string, appends null terminators, watches for file changes and so on. To my surprise, I stumbled upon my now preferred way of hot-reloading shaders.

READ MORE

[ lisp ]
<2020-11-20>

The Lisp Programming Language and its Influence

A paper on the history, influence and concepts of the Lisp family of programming languages

As part of a university seminar on programming languages I wrote a small paper on Lisp. It ended up being about the history of Lisp and its dialects, their influences on other languages, as well as a short tutorial on how Lisp works.

READ MORE