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
|
GLuint _texture;
LoadTestTexture(int width, int height, string fileName) {
BYTE * data = new BYTE[width * height * 3];
FILE * file;
//read texture data
fopen_s(&file, fileName.c_str(), "rb");
fread(data, width * height * 3, 1, file);
fclose(file);
glGenTextures(1, &_texture);
glBindTexture(GL_TEXTURE_2D, _texture);
// elect modulate to mix texture with color for shading
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
//when texture area is small, bilinear filter the closest mipmap
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
// when texture area is large, bilinear filter the first mipmap
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
//the texture wraps over at the edges
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_BYTE, data);
//build texture mipmaps
//gluBuild2DMipmaps(GL_TEXTURE_2D, 3, width, height, GL_RGB, GL_BYTE, data);
}
|