Minecraft 4K C++ Port

A while ago I discovered Minecraft4k, a java demo written by Notch fitting into a 4kb object file.  He used software raycasting to rasterize a large 3d array of voxels. The original demo can be played here as an applet:


At the same time I found that Notch had made a Javascript port of the same basic engine, minus user input.


One awesome thing about these two demos is that all of the textures are synthesized proceduraly for space saving reasons.

Seeing his work, I got a strong urge to port the code to C++ and SDL.

Grab the source code here:


8 thoughts on “Minecraft 4K C++ Port

  1. Hey I’m converting this to SDL2.0 and although I have a successful build the SDL_Window gets a nullptr when it hits “plot(x, y, rgbmul(col, fxmul(br, ddist)));” in the render() method, any ideas?

    • Your right, you were close 🙂 In SDL there was just an SDL_Surface, which gives you essentially a pointer to the screen. In SDL2 you have to jump threw a few more hoops to get the same thing. Creating an SDL_Window was the right thing to do, and from that window you must create an SDL_Surface using SDL_GetWindowSurface. The new SDL_Renderer object you were trying to use is nice to have in SDL2 however it uses OpenGL and DirectX under the hood, so its impossible to get access directly to the pixels of the screen (however you can fake something similar).

      I tweaked your code to get it to running with SDL2 and tested it on my Linux laptop:

      I imagine it should still run on windows too.

  2. Yep, can confirm it runs on Win 10 – Visual Studio 2015 😀 sincerely appreciate the guidance. I’m just getting to grips with SDL at the moment and this helped a lot with getting to know how it all works.

    Thank you very much and all the best friend 😉

Leave a Reply to The 8 Bit Pimp Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s