Slide 7
Slide 7 text
Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 6
jgs
Load Textures
// Create texture from a DIB or BMP file
void texture_from_file(GLuint *textureArray, const char * file) {
BITMAPINFO *bitmapInfo; // Bitmap information
GLubyte *bitmapBits; // Bitmap data
if (!file) { cout << "texture file not found!" << endl; return;}
// load image
bitmapBits = load_bmp_file(file, &bitmapInfo);
// 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,
bitmapInfo->bmiHeader.biWidth, bitmapInfo->bmiHeader.biHeight,
GL_BGR_EXT, GL_UNSIGNED_BYTE, bitmapBits
);
}