Using the Chapter s Source Code

[ LiB ]

Using the Chapter's Source Code

In the file path / Book Code/Chapter 02/ on the CD are two sample programs. I wrote them to help you simulate color mixing. Each program copies color information into a data buffer and save the information to a file. In / Book Code/Chapter 02/Common are the classes we've just created. The two programs will share this common folder as it utilizes these classes. Here is the list of the files:

 Color3.cpp Color3.h MathTools.h PPM.cpp PPM.h 

Color 3

The Color3 program is located in / Book Code/Chapter 02/Color3 . Color3 just prints each basic color from your class to a file. The entry point for the program is inside main() . This is how you dictate to the application the logic used to output the colors to a PPM formatted file. The main logic of the program is in a file called / Book Code/Chapter 02/Color3/main.cpp . The program includes the Color3 class, the PPM file importer method, and a few math functions. The program copies each basic color of the Color3 class to a memory buffer that's outputted to a PPM file. The color buffer is created. The colors blue, red, green, cyan, yellow, and white are all copied to the memory buffer. The application then cycles through the pixels in the memory buffer and assigns a basic color from the Color3 class. The color buffer is then out-putted to a PPM formatted file. After the PPM files are exported, the memory buffer is released. Take a look at the general logic of the program defined in main.cpp (note that cyan, yellow, and white aren't shown for brevity's sake, but they use the same general logic):

 #include <stdio.h> // INCLUDE CLASS FILES #include "..\Common\MathTools.h" #include "..\Common\Color3.h" #include "..\Common\PPM.h"  int main(int argc, char* argv[]) {    printf("Color Program!\n");    // create a 320x240 blue image    int height, width;    color3 * pBuffer = NULL;    pBuffer = new color3[320 * 240];    // LET'S DO BLUE    printf("Doing Blue!\n");    for(height=0; height< 240; height++)       for(width=0; width<320; width++)          pBuffer[320 * height + width] = color3::Blue;    // write ppm    WritePPM("blue.ppm", pBuffer, 320, 240 );    // LETS DO RED    printf("Doing Red!\n");    for(height=0; height< 240; height++)       for(width=0; width<320; width++)          pBuffer[320 * height + width] = color3::Red;    // write ppm    WritePPM("red.ppm", pBuffer, 320, 240 );    // LET'S DO GREEN    printf("Doing Green!\n");    for(height=0; height< 240; height++)        for(width=0; width<320; width++)           pBuffer[320 * height + width] = color3::Green;    // write ppm    WritePPM("green.ppm", pBuffer, 320, 240 ); } 

To compile this program, follow these steps:

  1. Open the project workspace ( Color3.dsw or Color3.dsp ).

  2. From the File menu, choose Build, Rebuild All.

  3. From the File menu, choose Build, !Execute Color3.exe .

You can also run the program directly by executing the following file: /Book Code/Chapter 02/Color3/Color3.exe

The program will begin exporting each basic color from the Color3 class to the current directory. However, I've already created the exported files for you and placed them in the following folder:

 /Book Code/Chapter 02/Color3/Output/ 

The files in this folder are as follows :

 12/21/2002  07:27p        614,898 blue.ppm 12/21/2002  07:27p        768,498 cyan.ppm 12/21/2002  07:27p        614,898 green.ppm 12/21/2002  07:27p        614,898 red.ppm 12/21/2002  07:27p        922,098 white.ppm 12/21/2002  07:27p        768,498 yellow.ppm 

Color3Mix

The Color3Mix program is located in / Book Code/Chapter 02/Color3Mix. Color3Mix mixes two colors to create a gradient and saves the effects to a file. This program follows the same format as the previous one, but varies in the logic located in Main.cpp . To compile the program, open the project workspace called Color3Mix.dsw in Microsoft Visual C++ 6.0. Then press Build Execute Color3Mix.exe . Then follow the same instructions as previously. Again, you can go to the /Output folder and open up each generated file.

Here are the names of the generated files:

 green_gradient.ppm red_gradient.ppm 

Be sure to review both sample applications before you go to the next chapter.

[ LiB ]


Focus On Photon Mapping
Focus On Photon Mapping (Premier Press Game Development)
ISBN: 1592000088
EAN: 2147483647
Year: 2005
Pages: 128
Authors: Marlon John

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net