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:
https://mojang.com/notch/j4k/minecraft4k/
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:
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?
Hey I nearly have it working, but I need the plot.h file you used for it
Im a little confused, all of the source is in one file, there isnt a plot.h file.
I would be happy to take a look at any code you have if you want to post it…
Almost have it working I think, getting a C2227 error on line 38 http://pastebin.com/C51H4LR9
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:
http://pastebin.com/iaWRbbWh
I imagine it should still run on windows too.
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 😉
I managed to port this to MS-DOS ! It works well … but it needs lots of optimization to work at a correct speed on period correct hardware x)
Also now it’s 256 colors instead of 24 bits and runs at 320×200 res instead of 320×240.
Take a look at it here https://media.discordapp.net/attachments/344327239338426369/746699021716029510/unknown.png
Also I noticed that you forgot to add the blue blocks ^^ (which I reimplemented)
Okay that is very awesome! Thanks so much for sharing that with me. I’ve always wanted to give MSDOS programming a shot.