/* global definitions for constants and global image arrays */ #define ImageWidth 64 #define ImageHeight 64 GLubyte Image[ImageHeight][ImageWidth][4]; #define stripeImageWidth 32 GLubyte stripeImage[4*stripeImageWidth]; /************************************************************* void image_set_up(void): generate checkerboard and stripe images. * Inside init(), call this function and set up texture objects for texture mapping. (init() is called from main() before calling glutMainLoop().) ***************************************************************/ void image_set_up(void) { int i, j, c; /* --- Generate checkerboard image to the image array ---*/ for (i = 0; i < ImageHeight; i++) for (j = 0; j < ImageWidth; j++) { c = (((i & 0x8) == 0) ^ ((j & 0x8) == 0)); if (c == 1) /* white */ { c = 255; Image[i][j][0] = (GLubyte) c; Image[i][j][1] = (GLubyte) c; Image[i][j][2] = (GLubyte) c; } else /* green */ { Image[i][j][0] = (GLubyte) 0; Image[i][j][1] = (GLubyte) 150; Image[i][j][2] = (GLubyte) 0; } Image[i][j][3] = (GLubyte) 255; } glPixelStorei(GL_UNPACK_ALIGNMENT, 1); /*--- Generate 1D stripe image to array stripeImage[] ---*/ for (j = 0; j < stripeImageWidth; j++) { /* When j <= 4, the color is (255, 0, 0), i.e., red stripe/line. When j > 4, the color is (255, 255, 0), i.e., yellow remaining texture */ stripeImage[4*j] = (GLubyte) 255; stripeImage[4*j+1] = (GLubyte) ((j>4) ? 255 : 0); stripeImage[4*j+2] = (GLubyte) 0; stripeImage[4*j+3] = (GLubyte) 255; } glPixelStorei(GL_UNPACK_ALIGNMENT, 1); /*----------- End 1D stripe image ----------------*/ /*--- texture mapping set-up is to be done in init() (set up texture objects), display() (activate the texture object to be used, etc.) and in shaders. ---*/ } /* end function */