Live data from Hacker News

Simple software rasterizer in a single C++11 header file

github.com

1–10 of 23 posts

Re: Simple software rasterizer in a single C++11 header file

#3
post #2

What exactly is the difference between this and for example a simple ray tracer? Seems like it takes a lot of the same steps.

This loops over the triangles and converts them to screen pixels. A ray tracer loops over screen pixels and checks if there are any triangles that overlap it.

Re: Simple software rasterizer in a single C++11 header file

#4
I'm not a C++11 developer, I've done a little C++ in the past. What is the pride in putting all the code in the header file? Shouldn't the declarations be there, and the definitions be pulled out into a .cpp file? Is it somehow smaller, faster, more convenient to have it all in a header file?

Re: Simple software rasterizer in a single C++11 header file

#5
post #4

I'm not a C++11 developer, I've done a little C++ in the past. What is the pride in putting all the code in the header file? Shouldn't the declarations be there, and the definitions be pulled out into a .cpp file? Is it somehow smaller, faster, more convenient to have it all in a header file?

Header libraries are easier to add to your project because there are no build scripts to figure out or cross-compiling to do or whatever. A lot of Boost is header-only, for example. GLM (OpenGL Mathematics), too, is header-only. OTOH if you end up modifying a header that's included in a whole bunch of places, woe unto you.

Re: Simple software rasterizer in a single C++11 header file

#6
post #4

I'm not a C++11 developer, I've done a little C++ in the past. What is the pride in putting all the code in the header file? Shouldn't the declarations be there, and the definitions be pulled out into a .cpp file? Is it somehow smaller, faster, more convenient to have it all in a header file?

[deleted]

Re: Simple software rasterizer in a single C++11 header file

#8
post #5
post #4

I'm not a C++11 developer, I've done a little C++ in the past. What is the pride in putting all the code in the header file? Shouldn't the declarations be there, and the definitions be pulled out into a .cpp file? Is it somehow smaller, faster, more convenient to have it all in a header file?

Header libraries are easier to add to your project because there are no build scripts to figure out or cross-compiling to do or whatever. A lot of Boost is header-only, for example. GLM (OpenGL Mathematics), too, is header-only. OTOH if you end up modifying a header that's included in a whole bunch of places, woe unto you.

The reason Boost is headers only is you have to be a header to be generic. Implementations outside of headers have to friend / otherwise be not truly generic.

Re: Simple software rasterizer in a single C++11 header file

#9
post #3
post #2

What exactly is the difference between this and for example a simple ray tracer? Seems like it takes a lot of the same steps.

This loops over the triangles and converts them to screen pixels. A ray tracer loops over screen pixels and checks if there are any triangles that overlap it.

More or less this. To expand a bit - rasterization converts lines or polygons to pixels via hidden line removal techniques (http://en.wikipedia.org/wiki/Hidden_line_removal) and/or hidden surface techniques (http://en.wikipedia.org/wiki/Hidden_surface_determination) while ray tracing can mean a lot of different things, where most common and basic form is Whitted's ray tracing where final image is a grid of pixels with from each one there is a 'ray' shot towards the scene and checking if there is a collision with the object (polygon) and then turned towards each light source. In normal world, model is that light travels from light source, bounces from objects and comes to the camera - Whitted's algorithm is opposite where rays are shot from camera towards objects (modified by surface properties there) and towards light sources (less computation that way). Modern ray tracers involve Kajiya's equations and other fancy stuff.
Post reply on HN