1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_TEXTURE_COORD_ARRAY); //only if you are using VBOs before OpenGL 3.0
GLuint tex;
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
//texture parameters; check the reference pages for alternate settings
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
//optional extension for anisotropic filtering (requires the extension to be available)
float maximumAnisotropy;
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maximumAnisotropy);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, maximumAnisotropy);
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB8, textureSizeX, textureSizeY, GL_BGR, GL_UNSIGNED_BYTE, texturePixelsPointer);
|