Sign in to follow this  

Texture Objects - can't reuse

This topic is 1512 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a routine to apply contours to the surface of quads. Iam using a 1d texture.
 
I create the texture using:

glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glDeleteTextures(1,&contourTextureName);
glGenTextures(1, &contourTextureName);


glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, CONTOUR_TEXTURE_LENGTH, 0,
GL_RGBA, GL_UNSIGNED_BYTE, contourTexture);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBindTexture(GL_TEXTURE_1D,contourTextureName);

then when rendering the quads i do the following:

glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);


glBindTexture(GL_TEXTURE_1D,contourTextureName);


glEnable(GL_TEXTURE_1D);


glBegin(GL_POLYGON);


glTexCoord1f(value[0]); glVertex3f(NX(n1),NY(n1),NZ(n1));
glTexCoord1f(value[1]); glVertex3f(NX(n2),NY(n2),NZ(n2));
glTexCoord1f(value[2]); glVertex3f(NX(n3),NY(n3),NZ(n3));
if(n4 > 0)
glTexCoord1f(value[3]); glVertex3f(NX(n4),NY(n4),NZ(n4));


glEnd();

The texture ends up not being used. However, if i do the following (add the texture creation code each time i need to use it)

	glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP);
	glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER,GL_LINEAR);
	glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, CONTOUR_TEXTURE_LENGTH, 0,
		GL_RGBA, GL_UNSIGNED_BYTE, contourTexture);
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

	glBindTexture(GL_TEXTURE_1D,contourTextureName);

	glEnable(GL_TEXTURE_1D);

	glBegin(GL_POLYGON);

	glTexCoord1f(value[0]); glVertex3f(NX(n1),NY(n1),NZ(n1));
	glTexCoord1f(value[1]); glVertex3f(NX(n2),NY(n2),NZ(n2));
	glTexCoord1f(value[2]); glVertex3f(NX(n3),NY(n3),NZ(n3));
	if(n4 > 0)
		glTexCoord1f(value[3]); glVertex3f(NX(n4),NY(n4),NZ(n4));

	glEnd();

It works fine. This is eating up all sorts of cpu, and i thought i should be able to re-use the texture, what am i doing wrong???

 

 

Share this post


Link to post
Share on other sites

Make sure that the texture is create after the rendering context is created. Also make sure that the contourTextureName variable is the same in both functions. If not, you probably have two (or more) definitions of contourTextureName and the one that receives the texture name is not the same as the one using the texture name.

Share this post


Link to post
Share on other sites

Also, GL_TEXTURE_1D is not a valid parameter for glEnable().

 

 

L. Spiro

Sure it is valid, texture dimensions are enabled separately so 1D texture is a valid enable state.

Share this post


Link to post
Share on other sites
Is that extreme legacy or what?
I checked http://www.opengl.org/sdk/docs/man/xhtml/glEnable.xml prior to posting and it is also something I have never used before.
I see people talking about it online but they are talking about 1.5 spec etc.

I’m assuming this has been completely fully deprecated for shader-based OpenGL, as I’m having no problems using 2D textures and cube textures without enabling them.


L. Spiro

Share this post


Link to post
Share on other sites

Yeah, it's legacy and you need to glEnable it in order to tell OpenGL to sample from the currently bound 1D texture.  It's still legal with the fixed pipeline though, and will remain legal as long as drivers support the fixed pipeline.

Share this post


Link to post
Share on other sites
Sign in to follow this