Texture Mapping
An Introduction |
Prof. David Bernstein |
Computer Science Department |
bernstdh@jmu.edu |
/** * Fill the given matrix with a striped texture. * * @param stripeWidth The width of each stripe * @param colorA The color of one stripe * @param colorB The color of the other stripe * @param smooth 0 for sharp stripes; otherwise for smooth * @param data The matrix to fill */ void createStripedTexture(int stripeWidth, int* colorA, int* colorB, int smooth, GLbyte data[256][256][3]) { int u, v; float s, t; for (u = 0; u < 256; u++) { for (v = 0; v < 256; v++) { s = sin(PI * u / stripeWidth); if (smooth) { t = (1.0 + s) / 2.0; } else { if (s > 0) t = 1.0; else t = 0.0; } data[u][v][0] = (GLbyte) ((1.0 - t) * colorA[0] + t * colorB[0]); data[u][v][1] = (GLbyte) ((1.0 - t) * colorA[1] + t * colorB[1]); data[u][v][2] = (GLbyte) ((1.0 - t) * colorA[2] + t * colorB[2]); } } } // Create the striped "image" int stripeWidth = 32; GLbyte image[256][256][3]; createStripedTexture(stripeWidth, purple, gold, 1, image);