Maximum colour value, ASCII decimal representation.Height of the image, ASCII decimal representation.
Width of the image, ASCII decimal representation.A "magic number" identifying the file type, in our case this will be "P6".The PPM format has the following components (also called the header) needed for the file to be identified and displayed correctly by the image viewer: The ppm format is a simple uncompressed format from the Netpbm family of image formats. For this tutorial however, we will use something very simple: the ppm (portable pixmap) format. Most of these are quite complex to generate unless you use existing libraries. There are many image formats such as jpeg, png, gif, etc. The first thing we need to do is agree on the format we're going to use. Suppose we want to programatically create the Finnish flag: With 24 bit colour, we have enough to represent over 16.7 million colours. In this way, we can let the red, green and blue component vary in value between 0 and 255 because. When we say that an image is '24-bit colour', we mean that each pixel is built up out of 3 values, each 8 bit long. Each pixel can represent any colour made up from the three primary colours red, green and blue. Let's take this one step further and create an actuall graphic which you can open in an image viewer.Ĭomputer images are built up out of pixels (picture elements).
Not super exciting, I know, but it verifies the correctness of our ray/sphere intersect function. If you compiled and ran the example attached to the last article, you should have noticed a console output which looks like this: Last time we build up the basics of the raytracer: some essential math and the corresponding function implementations and structures in the C programming language. We will expand the ray tracer this time to generate actual graphics and to generate these images with multiple spheres, light sources, and reflections. Tags: C, Graphics, Mathematics, Programming, Ray Tracing