HP Workstation zx2000 HP OpenGL Implementation Guide for HP-UX 11.X (IPF versi - Page 14

D texture program fragments, This program draws four layers in the base MIPmap level

Page 14 highlights

overview of OpenGL 3D texture program fragments This program draws four layers in the base MIPmap level, and a diagonal slice through the base MIPmap level. /* Allocate texture levels separately, then concat to get 3D texture */ GLubyte texture1[TEXTURE_WIDTH][TEXTURE_HEIGHT][4]; GLubyte texture2[TEXTURE_WIDTH][TEXTURE_HEIGHT][4]; GLubyte texture3[TEXTURE_WIDTH][TEXTURE_HEIGHT][4]; GLubyte texture4[TEXTURE_WIDTH][TEXTURE_HEIGHT][4]; GLubyte textureConcat[TEXTURE_DEPTH][TEXTURE_WIDTH][TEXTURE_HEIGHT][4]; /* The checkerPattern procedure fills a texture of width and height with a period of Checker_period alternating between firstColor and secondColor, Texture should be declared prior to calling checkerPattern. */ static void checkerPattern(int width, int height, GLubyte *firstColor, GLubyte *secondColor, GLubyte *texture, int Checker_period) { int int GLubyte texelX, texelY; index, fromIndex; *p = texture; index = 0; for (texelY = 0; texelY < height; texelY++) { for (texelX = 0; texelX < width; texelX++) { if (((texelX/Checker_period)% 2) ^ ((texelY/Checker_period)% 2)) { *p++ = firstColor[0]; /* red */ *p++ = firstColor[1]; /* green */ *p++ = firstColor[2]; /* blue */ *p++ = firstColor[3]; /* alpha */ } else { *p++ = secondColor[0]; /* red */ *p++ = secondColor[1]; /* green */ *p++ = secondColor[2]; /* blue */ *p++ = secondColor[3]; /* alpha */ } } } GLubyte blackRGBA[] = {0.0, 0.0, 0.0, 255.0}; GLubyte whiteRGBA[] = {255.0, 255.0, 255.0, 255.0}; GLubyte redRGBA[] = {255.0, 0.0, 0.0, 255.0}; GLubyte greenRGBA[] = {0.0, 255.0, 0.0, 255.0}; GLubyte blueRGBA[] = {0.0, 0.0, 255.0, 255.0}; GLubyte yellowRGBA[]= {255.0, 255.0, 0.0, 255.0}; 1-10 OpenGL implementation guide

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42

1–10
OpenGL implementation guide
overview of OpenGL
3D texture program fragments
This program draws four layers in the base MIPmap level, and a diagonal slice through the base
MIPmap level.
/* Allocate texture levels separately, then concat to get 3D
texture */
GLubyte texture1[TEXTURE_WIDTH][TEXTURE_HEIGHT][4];
GLubyte texture2[TEXTURE_WIDTH][TEXTURE_HEIGHT][4];
GLubyte texture3[TEXTURE_WIDTH][TEXTURE_HEIGHT][4];
GLubyte texture4[TEXTURE_WIDTH][TEXTURE_HEIGHT][4];
GLubyte
textureConcat[TEXTURE_DEPTH][TEXTURE_WIDTH][TEXTURE_HEIGHT][4];
/* The checkerPattern procedure fills a texture of width and
height with a period of Checker_period alternating between
firstColor and secondColor, Texture should be declared prior to
calling checkerPattern. */
static void checkerPattern(int width, int height,
GLubyte *firstColor,
GLubyte *secondColor,
GLubyte *texture,
int Checker_period)
{
int
texelX, texelY;
int
index, fromIndex;
GLubyte
*p = texture;
index = 0;
for (texelY = 0; texelY < height; texelY++) {
for (texelX = 0; texelX < width; texelX++) {
if (((texelX/Checker_period)% 2) ^
((texelY/Checker_period)% 2)) {
*p++ = firstColor[0]; /* red */
*p++ = firstColor[1]; /* green */
*p++ = firstColor[2]; /* blue */
*p++ = firstColor[3]; /* alpha */
} else {
*p++ = secondColor[0]; /* red */
*p++ = secondColor[1]; /* green */
*p++ = secondColor[2]; /* blue */
*p++ = secondColor[3]; /* alpha */
}
}
}
GLubyte blackRGBA[] = {0.0, 0.0, 0.0, 255.0};
GLubyte whiteRGBA[] = {255.0, 255.0, 255.0, 255.0};
GLubyte redRGBA[] = {255.0, 0.0, 0.0, 255.0};
GLubyte greenRGBA[] = {0.0, 255.0, 0.0, 255.0};
GLubyte blueRGBA[] = {0.0, 0.0, 255.0, 255.0};
GLubyte yellowRGBA[]= {255.0, 255.0, 0.0, 255.0};