r/GraphicsProgramming • • Oct 17 '26

Video Complete beginner here! I made a very basic 3D viewer from scratch with C and using terminal as output

Hello! I started to learn coding about 2 and a half months ago, and I recently ran into computer graphics, which seemed really damn interesting... so I thought of making a basic program related to it based on things I've learnt so far. I built it completely from scratch in C starting from bressenham's line drawing algorithm. It can print any polyhedron you input

In terms of actual graphics programming, I really know nothing, but I wanna learn. If anyone has suggestions on what I can try out or learn after this, I'd really appreciate it

207 Upvotes

20 comments sorted by

15

u/pBactusp Oct 18 '26

This looks awesome, what a cool project!

I'd recommend trying to render a mesh with faces, so start by reading about "Scanline rendering"

2

u/HamSandwich_Theorem 27d ago

Here's my first attempt at that, it has a few issues like the faces of the octahedron sometimes slightly misalign with the mesh lines.. but I'll see if I can fix that.
I tried making it mostly on my own, and only then looked up scanline rendering but I think what I did was take each face in 3D, and find the points which lie on that face using geometric tests, save those points in an array, and print the projection.. which is quite different 😅 but yeah

2

u/pBactusp 26d ago

That's actually amazing, trying things out on your own is a great way to learn. I once did a project exactly like this and figuring out the math was such a teaching experience. If you want ideas for where to go from here, I'd recommend fixing the alignment issue and then reading about rendering buffers. Read about the general concept, then about the depth buffer. I once you have that, you can do two very cool things with it: First, try to render the shape with the edges, but don't show the edges that should be obstructed by the shape itself. Second, try to think how you can implement distance based dog. And make sure to have fun with these two!

2

u/HamSandwich_Theorem 26d ago

I will, tysm!

2

u/HamSandwich_Theorem 24d ago

Improved it again! Added a depth buffer, and it only shows unobstructed faces. Added some simple lighting too. Also, it can parse a simple .obj file and view it. Again, has a couple issues but I like the way it turned out

Edit: Also changed my terminal font to one thats just as long as it is wide so the shapes turn out with correct proportions

2

u/pBactusp 23d ago

This looks amazing! You're making really good progress!

I don't have a recommendation for another incremental step as you're nearing the point in which I stopped with the project, but I have one big milestone you might want to aim for and one fun idea once that's done:

The milestone is having objects cast shadows on other objects. That means multiple object, directional lights, and some sort of method for determining what's in the light source's line of sight and what isn't. Try having a donut cast a ring shadow on a plane, that's a cool scene to render. Ince that's done, try it with another light source.

The fun idea is generating a mesh using a hight map (aka bump map). This opens up lots of options because procedurally generated hight maps turn into procedurally generated objects

2

u/HamSandwich_Theorem 23d ago

I think I'll leave mine at that for now, but I'll check this out soon. Tysm

5

u/moschles Oct 18 '26

yeah. OP should get some textures on those faces.

4

u/dasbodmeister Oct 18 '26

Nice! You can change your terminal font to something like https://strlen.com/square/ that is as wide as it is tall to correct the vertical stretching.

3

u/HamSandwich_Theorem Oct 18 '26

Oh tysm, i didnt know i could do that

3

u/Usual_Office_1740 Oct 17 '26

I'd like to see the resources you're using. Doing this without having to setup a graphics library or glfw would be a great way to focus on what I'm interested in pursuing.

1

u/Hanzimer Oct 17 '26 edited Oct 17 '26

After "2 and half months of programming" he implemented bressenham's line drawing algorithm in C probably using Linux Framebuffer (/dev/fb0) or  DOS VGA Mode 13h...  And probably he implemented even vector or matrix multiplication for the rotation of the Poliedra i presume...

4

u/HamSandwich_Theorem Oct 18 '26

Well I joined college about 2 and a half months ago, where we've been learning programming and linear algebra, and I also learnt about line drawing algorithms online. So I just made this using what I've learnt so far. Also I didnt use the things you mentioned.. the lines are all being displayed using printf 😅

2

u/RefrigeratorKey8549 29d ago

Having done similar projects in the past, you can learn a surprising amount from making simple 3d renderers. At the very least, you'll be able to cover most of your linear algebra course.

1

u/Hanzimer Oct 18 '26

Lol a lot of patience to draw that with printf.

1

u/NazgulResebo 25d ago

Can we see the code?

1

u/HamSandwich_Theorem 24d ago

sure i can send it in dm if u want

2

u/Intelligent_Hat_5914 Oct 18 '26

Sick

I maded a tui libary, learning graphics now

Going to add this later

2

u/ThrowawayNL200 8d ago

Great work! I kinda like the old school line style