Live data from Hacker News

How OpenGL works: software renderer in 500 lines of code

github.com

21–30 of 37 posts

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

#21
post #19
post #16

Earlier quoted context omitted.

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.

If it's looked purely from educational point of view it's quite hard to find graphics code that is this clear and concise.

The author modifies this short code to implement various shading techniques with code that is as pithy and understandable as any.

You have to recall that 40 years ago even texture mapping was a scientific publication quality material.

This code makes several non-obvious things obvious - and simple! I don't think that's a light achievement.

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

#23
post #22

https://github.com/ssloy/tinyrenderer/blob/master/geometry.c... What's going on there with the template template ?

The struct vec takes a template parameter T, and it's constructor takes a different template parameter U. Therefore, you must specify both template directives when defining the constructor; one for the class type, and one for the constructor's argument.

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

#24

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…

It turns out that Trenki implemented the OpenGL ES-CL 1.0 interface on top of his software renderer (link [1] above), which should serve as an even better example of how OpenGL (may) work.

http://www.trenki.net/content/view/39/48/

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

#25
post #22

https://github.com/ssloy/tinyrenderer/blob/master/geometry.c... What's going on there with the template template ?

The struct vec takes a template parameter T, and it's constructor takes a different template parameter U. Therefore, you must specify both template directives when defining the constructor; one for the class type, and one for the constructor's argument.

Edit: re-wording this reply.

I guess what surprised me is I would almost expect it to look something like this...

template vec ::vec(template const vec &v) : x(int(v.x+.5f)),y(int(v.y+.5f)),z(int(v.z+.5f)) {}

I can tell that is silly but still.

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

#27
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.

Besides cmrx64's answer: Have you considered the possibility that 8bitpimp comes from a country where programmers are paid much worse or has a job that is paid badly but one still has good reasons to take it (say, graduate student)?

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

#28
post #4

Will this teach you how shader-based OpenGL works or the older fixed function pipeline rendering method?

It will give the educational toy-analogue to a modern programmable pipeline by using C++ code which is more or less isomorphic to shader based OpenGL (or DirectX).

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

#30
post #19
post #16

Earlier quoted context omitted.

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.

Let me cite one thing:

https://github.com/ssloy/tinyrenderer/wiki/Lesson-6:-Shaders...

"Recall that all my source code here is meant to be compared with yours. Do not use my code, write your own. I am a bad programmer."

If you want to improve the text, the wiki is open. If you want to improve the source code, fork -> code -> pull request

Post reply on HN