…but it’s not working. The texture won’t display properly and I get an error when I try to delete it later, or even with a glIsEnabled(GL_TEXTURE_2D) check. I’ve tried numerous permutations of the basic commands but I haven’t gotten anything to work. If I make, draw, and delete within the same function, everything is fine; but when I do it separately it doesn’t work. So if anybody could help me that would be great. Anyway, first I create the texture, where sq is the (power of 2) array of GLubytes:
void MakeTexture()
{
int tex_name;
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size, size,
0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, sq);
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &tex_name);
glBindTexture(GL_TEXTURE_2D,tex_name);
glDisable(GL_TEXTURE_2D);
}
After this function call other things might be drawn, including other textures. However I get failure even when this is the only thing I try to draw.
void ShowTexture()
{
glColor4f(1.0, 1.0, 1.0, 1.0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,GetTexName());
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
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);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glPushMatrix();
glBegin(GL_POLYGON);
for (i=0; i<num_sides; ++i)
{
glTexCoord2f(...);
glVertex2f(...);
//... The texture mapping is not itself the problem, it works in other circumstances.
}
glEnd();
glPopMatrix();
glDisable(GL_TEXTURE_2D);
}
The geometry is completely determined by the glColor() call, e.g. is white in this case. But if I omit that it’s still white. And the environment variable is GL_REPLACE anyway.
void CleanTexture()
{
//Every one of the following statements individually makes the program crash:
glIsEnabled(GL_TEXTURE_2D); //As used in an if statement
glEnable(GL_TEXTURE_2D);
glIsTexture(tex_name); //As used in an if statement
glDeleteTextures(1, &tex_name);
}
So by the time the program gets to CleanTexture(), the state machine is apparently broken. What is going on? What’s the right way to create a texture, store it, and retrieve it later? Thank you…
Matt