Internet of Tomohiro
If you found my articles interesting or useful, please donate using following links:
I made 4k intro samples using Nim programming language.
It is a program less than or equal to 4096 bytes and play cool visual and music. It is a part of demoscene culture. This is a good video to understand what is demoscene.
Don't use large data
4k intro must runs alone and may not load image files or music files. It may not download data from the internet. If you use large texture image or 3D model to create cool scene, you cannot make a small size executable. You have to make them small or generate them procedurally. For example, you can make nice scene with small code using fractal. But people watching 4k intro have seen enough of fractals. You can learn graphics that can be used in 4k intro in following web site:
You might found a GLSL code that can be used in your 4k intro:
Don't use standard C library
If you link standard C library to your executable, size of it exceeds 4096 bytes. You need to specify some compile/link options to avoid linking C standard library. And you need to implement all functions yourself or directly use windowsAPI or OpenGL. You cannot use Nim procedures that is implemented with functions in standard C library. In visual C++, WinMainCRTStartup is a default name of entry point function when standard library is not linked.
Compress executable file with Crinkler
Crinkler link object files generated by C/C++ compiler to make an executable file like a linker. It compress code and data when it makes executable file and add a code to decompress them. That executable decompress the content, writes them to memory and executes it. Data that have some pattern can be compressed to smaller, but random data are hardly compressed to smaller. So larger data that have many same bit patterns can be compressed to smaller size rather than smaller but random data. Inlining procedures usually make smaller executable files.
Dont clean up
You don't need to clean up resources like heap memory or buffer objects in OpenGL. Clean up code just make a executable file bigger. Resources you used are clean up by OS when the process is terminated. As long as you don't allocate a resource inside main loop, it doesn't cause any problems because 4k intro runs only for a few minutes. Most of 4k intros don't need to use heap memory because what they do at runtime is usually determined at compile time. On windows, in case C standard library is not used, windowsAPI called ExitProcess must be called to terminate the process.
Minimize GLSL code
In case your 4k intro uses OpenGL, GLSL code is embedded to an executable file. Shader_Minifier minify your GLSL code by removing white spaces, replacing variable and function name to smaller one and etc.