OVERVIEW:This section of the tutorial will get you started with the basics of using the Imagine Texture SDK. You will load the project files, modify the sections of code that create the algorithmic texture, and compile a new texture. The sample texture in the SDK is the source code for the Agate texture supplied with Imagine for Windows. We will be modifying this in the following section to produce a checkerboard texture instead. Doing this requires us to edit the contents of only two files, agate.c and agate.txt STEP ONE:Load Microsoft Visual C++. (Other compilers may work, but I haven't tested any) STEP TWO:Modify the "friendly" name of the texture.
This is the name that will appear on the Maps Property Page of an Imagine object when you open it's Attributes dialog box. char szName[18] = "Checks";
STEP THREE:Now we will modify the part of the code that does the actual work of creating a texture. Its not surprising that the name of this function is called Work( ). The Work( ) function is passed a memory pointer to the list of parameters set by the user, this is the *params argument. The Work( ) function is also passed a pointer to a data structure that contains information about the attributes of the point where the ray has hit the object, this is the *patch argument. The *vector argument is a pointer to the coordinates on the object where the ray being traced has hit. The last argument, *axes, is a pointer to a data structure that contains information about the position and orientation of the axis of this texture. We will now change the sample texture from Agate to a Checkerboard texture. Starting at line number 52 of agate.c, replace the Work( ) function with the following code:
void Work(float *params, PATCH *patch, VECTOR *vector, TFORM *axes)
{
float X, Y, Z;
X = vector->X / params[0]; // use size values for scaling
Y = vector->Y / params[1];
Z = vector->Z / params[2];
if (X < 0.0) X -= 1.0; // Offset checks when they cross
if (Y < 0.0) Y -= 1.0; // into negative quadrants.
if (Z < 0.0) Z -= 1.0;
if (((int)X + (int)Y + (int)Z) % 2) // Checks on even numbers
{
patch->ptc_col.r = params[7] / 255; // Normalize colors
patch->ptc_col.g = params[8] / 255; // into 0.0 to 1.0
patch->ptc_col.b = params[9] / 255; // range
}
}
We are using the values set by the size controls on the Size Property Page to set the size of the checks. The original code assigns the X-Size, Y-Size, and Z-Size to the params[0], params[1], and params[2] variables, respectively. The Red, Green, and Blue values of the first color button on the Color Property Page are assigned to params[7], params[8], and params[9] respectively. The controls and the variables they are assigned to can be changed. But for the purpose of this lesson we are going to use them as they are. Our replacement code in the Work( ) function will now paint a checkerboard pattern on the object using the color set on the first color button of the Colors Property Page for this texture. For more information on where the sample texture stores values from the Property Pages jump to the next section of this tutorial. For information on the contents of the patch structure you can jump ahead to the Patch Structure Reference. STEP FOUR:Next we change the help information that is displayed in the Info Property Page of this texture. The help info is stored in the agate.txt text file. Double click on the agate.txt file and replace it's contents with the following text: Checks Texture Type: Color. This texture creates a checkerboard pattern REQUESTER TABS: Color: Color 1: This sets the color of the checks. Controls: Nothing here to adjust. Size: These allow you to scale the overall size of the checks STEP FIVE:Press F7 to build the texture. Copy the cppproj.itx file from the ReleaseP subdirectory of the texture project directory to the Textures directory of Imagine. You can rename the file to MyChecks.itx or something else if you would like to keep this texture.
Continue Tutorial Back to the Texture Tutorial Table of Contents. Back to the Tutorials |
|
© 2002 Kazimer Corp.
1010 University Ave. PMB #1862
San Diego, CA 92103-3395