Posts Tagged ‘glTexParameter’

OpenGL glTexParameters

Wednesday, August 22nd, 2012

Silly me, I thought that whenever you bind a texture for rendering, you need to set the texture parameters at that time. Through a bit of trial and error, and a lot of reading, unless there is a need to change the texture parameters during runtime, you can set them once and forget about them at initial texture loading to the GPU. As long as this texture is valid (not been deleted by glDeleteTextures(…)), then these parameters will remain valid and associated with this texture. Of course, loading of textures should ideally be done once, at the start of the application or game’s level.

// allocate a new texture, bind it and set the initial parameters
GLuint name = 0;
// set other texture parameters
// load our texture data


Now, when we want to render our quads (double triangle strips), we just bind our texture (assuming that textureID is value obtained from the code snippet above and saved someplace logical).


And submit our quad information

GLfloat verticies[8] = {...}; // 4 x,y pairs
GLfloat texCoords[8] = {...}; // 4 s,t pairs
GLubyte colors[32] = {...}; // 4 r,g,b,a quartets

The less OpenGL calls you need to perform, the better your game’s performance will be. Hopefully this bit of information will help.