Reputation: 72
I was going through some basic opengl tutorials, and want to know if this code could be made better.
My question is in c++, but I believe this would carry over to any other opengl implementation in different languages.
Here is the code:
glGenTextures(1, &texture1);
glBindTexture(GL_TEXTURE_2D, texture1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
//load the data for the texture, apply it, the free the data
glGenTextures(1, &texture2);
glBindTexture(GL_TEXTURE_2D, texture2);
//Now the question.
After binding texture2
, is it then neccessary to repeat the glTexParameteri
lines, if I want the same effect on both images?
Upvotes: 0
Views: 34
Reputation: 474086
Texture parameters are part of the state of a texture object. When you set texture parameters, you're setting state in that object. So your question is roughly equivalent to "if I do x.v = 5;
, does that mean y.v
is also 5 if x
and y
are the same type?"
When you bind an object to the context and then call a state setting function on that bind point, you are setting state in the object, just as surely as x.v = 5
sets state into the object x
. OpenGL simply has an unusual spelling for this notion (and sometimes, it's difficult to know without looking it up if a function sets state into an object or the context), but it's the same thing either way.
So no, setting state on one object will not transfer that state to another that just so happens to be bound to that binding point.
Upvotes: 2