Live data from Hacker News

How OpenGL works: software renderer in 500 lines of code

github.com

11–20 of 37 posts

Re: How OpenGL works: software renderer in 500 lines of code

#11
post #5

I wrote a software implementation of OpenGL with the only goal of being able to play Quake3 using it. I can vouch that it is an amazing learning experience. The tutorial here doesnt seem to aproach the issues of performance however, which really are another learning experience entirely.

Holy crap. If you could reimplement OpenGL you should be able to buy a video card. I think I had a tnt2 Ultra back then.

Re: How OpenGL works: software renderer in 500 lines of code

#13
The title is a bit misleading, this is boilerplate code for a graphics programming course and it hasn't got much to do with OpenGL.

The articles describing the operation are much more interesting than the code itself.

It's just an inefficient triangle rasterizer. All it does is loop over the pixels in a rectangle covering a triangle, and for each pixel inside it calls a "shader" function. All the beef is in these 40 lines [0].

I don't know how they've done the texturing in all those pretty pictures (it's in the "shaders", not included here), but they don't calculate the partial derivatives required for correct, mipmapped texturing. Simple non-mipmapped perspective correct texture mapping can be computed in the shaders, with the usual caveats.

OpenGL is much more than a rasterizer, there's texturing, depth-stencil operations, blending, compute shaders and efficient memory management.

[0] https://github.com/ssloy/tinyrenderer/blob/master/our_gl.cpp...

edit: Someone in reddit pointed out that this is a translation of a Russian language course. The original Russian version looks to be a bit longer than the English translation (but I don't read Russian, so I can't tell if it is better): https://habrahabr.ru/post/249467/

Re: How OpenGL works: software renderer in 500 lines of code

#14
This is great and so concise, but I'm surprised that the author didn't implement OpenGL's interface (obviously not all of it), if the goal is to show how OpenGL works.

Another good example of this is Trenki's software renderer for the GPX2[1], which implements a shader architecture if memory serves. I haven't looked at it for many years, but I remember it being a useful resource when learning this stuff.

Other useful resources are, of course, Michael Abrash's Graphics Programming Black Book[2] (despite it's age, is still a great read filled with useful information), and for a really deep dive into the graphic's pipeline, ryg's (of Farbrausch fame) A Trip Through the Graphics Pipeline[3].

[1] http://www.trenki.net/content/view/18/38/

[2] https://github.com/jagregory/abrash-black-book

[3] https://fgiesen.wordpress.com/2011/07/09/a-trip-through-the-...

Re: How OpenGL works: software renderer in 500 lines of code

#16
post #13

The title is a bit misleading, this is boilerplate code for a graphics programming course and it hasn't got much to do with OpenGL. The articles describing the operation are much more interesting than the code itself. It's just an inefficient triangle rasterizer. All it does is loop over the pixels in a rectangle covering a triangle, and for each pixel inside it calls a "shader" function. All the beef is in these 40…

You need to look through the short course notes in the wiki of the page to understand the full quality of this repository.

Re: How OpenGL works: software renderer in 500 lines of code

#17
post #5

I wrote a software implementation of OpenGL with the only goal of being able to play Quake3 using it. I can vouch that it is an amazing learning experience. The tutorial here doesnt seem to aproach the issues of performance however, which really are another learning experience entirely.

Holy crap. If you could reimplement OpenGL you should be able to buy a video card. I think I had a tnt2 Ultra back then.

"being able to play quak 2" as a goal for validation of effort and to have something concrete to strive for is completely different than "none of my software or hardware on my system can play quake 2", and I suspect grandparent meant the former and not the latter.

Re: How OpenGL works: software renderer in 500 lines of code

#19
post #16
post #13

The title is a bit misleading, this is boilerplate code for a graphics programming course and it hasn't got much to do with OpenGL. The articles describing the operation are much more interesting than the code itself. It's just an inefficient triangle rasterizer. All it does is loop over the pixels in a rectangle covering a triangle, and for each pixel inside it calls a "shader" function. All the beef is in these 40…

You need to look through the short course notes in the wiki of the page to understand the full quality of this repository.

Yes, I did and that's much more interesting than the code itself. But the title is still misleading and emphasizes the code, which isn't terribly spectacular.
Post reply on HN