Project 3 and 4 Score:00000 1. Project 1 included 2. Navigation Mouse and arrows 3. Menu to control speed: Normal and Fast 4. Light Emissive and Ambient. Static and Mobile 5. Materials 6. Textures 7. OBJs 8. Transformations: movements 9. GAME x
Create or Load Textures (from File) // Load a DIB/BMP file from disk. GLubyte* load_bmp_file(const char *filename, BITMAPINFO **info) { FILE *fp; // open file pointer GLubyte * bits; // bitmap pixel bits int bitsize; // Size of bitmap int infosize; // Size of header information BITMAPFILEHEADER header; // File header // open the file; use "rb" mode to read this *binary* file. // read the file header and any following bitmap information. // allocate memory for the bitmap and read *it* in. // OK, everything went fine - return the allocated bitmap. return (bits); }
Generate and Bind glGenTextures (size, name) § Create an texture identifier (similar to display lists) § Create texture names one by one (size=1). glBindTexture (GL_TEXTURE_2D, texture_name1) § When object is first bound, the texture object is created with default values. § Subsequent texture commands (e.g. glTexImage, glTexParameter, etc.) affect the actively bound texture // generate GLuint texture_array[3]; // size 1 à create an array with 1 texture names glGenTextures(1, &texture_array[0]); // bind glBindTexture(GL_TEXTURE_2D, texture_array[0]); // configure binding // set to 1 // read Red Book chapter 8 Pixel Packing and Unpacking. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
7. Bind a Texture Object glBindTexture (GL_TEXTURE_2D, texture_name1); § When object is first bound, the texture object is created with default values. § Subsequent texture commands (e.g. glTexImage, glTexParameter, etc.) affect the actively bound texture
Mipmaps gluBuild2DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const void * data); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, width, height, GL_BGR_EXT, GL_UNSIGNED_BYTE, an_array); § Create mipmaps automatically § Mipmaps are pre-calculated, optimized sequences of images, each of which is a progressively lower resolution representation of the same image.
Create or Load Textures (from Algorithm) // Create texture from algorithm void texture_from_algorithm(GLuint *textureArray) { const int TexHeight = 128; const int TexWidth = 128; // create texture in memory GLubyte textureImage[TexHeight][TexWidth][3]; for (int i = 0; i < TexHeight; i++) for (int j = 0; j < TexWidth; j++) { textureImage[i][j][0] = 127 + i; // red value from 0 to 255 textureImage[i][j][1] = 0; // green value from 0 to 255 textureImage[i][j][2] = 127 + j; // blue value from 0 to 255 } // setup texture glGenTextures(1, textureArray); glBindTexture(GL_TEXTURE_2D, *textureArray); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // must set to 1 for compact data gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TexWidth, TexHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, textureImage); }
Reading § To get a general picture of texture mapping: oRed Book (pdf): ch9 p247 ex9-1 § Pixel storage format oRed Book ch8 Pixel Packing and Unpacking section § Required reading for texture mapping: oRed Book (pdf): ch9 p250-p274 oHearn Baker: ch10 p628-p633, p648-p658 oReading tip: mainly focus on the instructions discussed in the slides. You are also encouraged to read all other instructions.