Today I fixed the cube texture warping: The perspective correction uses interpolated Z values to do a sort of perspective divide in the texture space. I don’t entirely understand how it works yet, so I’ll add a note here if this is all wrong.Here’s what I have so far: The problem is that the texture…
Category: Programming
Learning C, Day 16 (Texture Mapping 2)
Barycentric coordinates: they’re great for squishing squares into triangles. Here’s a wobbly textured cube: An overview of how it works The goal is to draw a triangle on the screen with pixels from a texture. I have three vertices and a texture in memory. The vertices describe two triangles: a triangle in the screen with…
Learning C, Day 15 (Texture Mapping 1)
Today I worked on adding texture mapping to the renderer so that it can display textured objects, which took about two and a half hours. It isn’t done yet, though, so here’s the classic missing texture color using the new code: Right now the code loops through each pixel of each screen space triangle and…
Learning C, Day 14 (Perspective Matrix)
Today I spent about two and a half hours implementing the perspective matrix and better flat shading. Now the renderer supports different aspect ratios and fields of view: At one point I messed up the color shading code and this happened (warning, flashing colors): Also, the site now has an icon and dark mode! I…
Learning C, Day 13 (More Matrix Math)
More matrix math today. I spent about an hour and a half implementing matrix rotation and scaling: Perspective matrix is up next, I’ll see you tomorrow!
Learning C, Day 12 (Matrix Math)
Matrix math. I added types and functions for matrix scaling and translation, which took about two hours. I’m thinking I might not use matrices in the PICO-8 port because they seem to add a bunch of overhead. I guess I’ll see. An update on Vim: sometimes I find myself pressing “j” to go down in…
Learning C, Day 11 (Triangle Fill)
Today I got triangle fill and basic z-depth order working! It took about four hours (o.O), but it looks really cool: I also fixed a bug with key inputs being delayed. I needed to get all the SDL events each frame instead of just the first one. It’s really nice to not have to wait…
Learning C, Day 10 (Back-Face Culling)
I spent about two and a half hours today on the course (more vector math) and I got back-face culling working! The next part of the course is filling the triangles, which is something I’ve been wondering how to do for a while. I can’t wait to see what I can make with the engine…
Learning C, Day 9 (Porting to PICO-8)
Today I worked on vector math to eventually implement back-face culling. I spent about an hour on that and then I ported the renderer so far to PICO-8: And it only took about 30 minutes! Working in C really makes me appreciate how much PICO-8 does behind the scenes. PICO-8 can’t load files directly, so…
Learning C, Day 8 (Loading OBJ Files)
Today I spent about two and a half hours on the course and I got my renderer loading OBJ files! So I had to render the Blender Suzanne monkey: I’m pretty sure my method of parsing OBJ files is awful, so I’ll probably rewrite it at some point. Here’s the code snippet: I’ll see you…
Learning C, Day 7 (Wireframe Cube)
I spent about four hours on the course today and I made a new cube: Things I worked on: Fixing the game loop to run at a constant speed Adding types for working with triangles DDA line drawing Maybe it doesn’t look as cool as the last one, but this one uses a system of…
Learning C, Day 6 (Point Cube)
Finally some 3D today! But first, Vim. I spent about half an hour just messing around in Vim and after that I used it for the rest of the day. Vim is so cool. It has shortcuts and commands for everything. A few times I found myself guessing commands correctly. For example, “$” means “move…
Learning C, Day 5 (Drawing Grids)
About an hour and a half learning C and 3D graphics today. I’m really enjoying the course so far. Not a whole lot to report on, I just refactored the code and wrote functions for drawing rectangles, grids, and single pixels. Note: I’ve got to learn vim. The course instructor is zooming in vim. Makes…
Learning C, Day 4 (3D Graphics Beginning)
Recently I’ve been playing some 3D PICO-8 games and I’m intrigued as to how the game creators squished 3D graphics into PICO-8’s limitations. I have experience with Blender, so I’m familiar with the high level concepts of 3D graphics, but I don’t understand how they work at a low level. So… I got a course…
Learning C, Day 3
I spent about 3 hours today learning C. I found an excellent blog with C tutorials: flaviocopes.com I also cobbled together a text colorizing program for Windows. Windows Batch can’t print colored text without changing the already printed text, but this program can do that. I’m at the point of being able to copy and…
Learning C, Day 2
So I spent about 2 hours today learning C and I finally got to pointers. C is so quirky and I love it. I finished the first tutorial and now I’m reading Modern C by Jens Gustedt. I’m working on a text adventure game and I’m googling how to do almost everything. Most of the…
Learning C
Earlier today I was reading an older book about microcomputers and how the only languages available at the time were FORTRAN, Basic, and Assembly. The book was published in 1977, so I wondered if C was available at the time. Turns out it was, but while I was on the Wikipedia page about C, I…
Optimizing The Bubbles Screensaver (PICO-8)
I was tinkering with the PICO-8 bubble screensaver today and I found a simple optimization that allows the game to support 50 bubbles instead of 40. (Edit: I’ve since optimized it again) Background The game needs to know which bubbles are colliding so that it can push them apart. The easiest method of finding which…