Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Texture Objects - can't reuse


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 BigEfromTheVillages   Members   -  Reputation: 108

Like
0Likes
Like

Posted 22 November 2013 - 10:03 AM

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???

 

 



Sponsor:

#2 Brother Bob   Moderators   -  Reputation: 9000

Like
0Likes
Like

Posted 22 November 2013 - 11:21 AM

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.



#3 swiftcoder   Senior Moderators   -  Reputation: 11828

Like
1Likes
Like

Posted 23 November 2013 - 12:10 AM

In your texture creation code, you are calling glBindTexture() after glTexImage1D().

 

You must call it before, if you wish the image to be uploaded to that texture...


Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]


#4 BigEfromTheVillages   Members   -  Reputation: 108

Like
0Likes
Like

Posted 23 November 2013 - 04:25 AM

Two things were wrong, i called glBindTexture() after glTexImage1D, and i was creating the texture before the rendering context was created. Thanks for your help.



#5 L. Spiro   Crossbones+   -  Reputation: 16572

Like
-1Likes
Like

Posted 26 November 2013 - 07:18 PM

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

 

 

L. Spiro



#6 Brother Bob   Moderators   -  Reputation: 9000

Like
2Likes
Like

Posted 27 November 2013 - 04:01 AM

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.



#7 L. Spiro   Crossbones+   -  Reputation: 16572

Like
0Likes
Like

Posted 27 November 2013 - 12:55 PM

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

#8 mhagain   Crossbones+   -  Reputation: 8760

Like
0Likes
Like

Posted 27 November 2013 - 01:07 PM

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.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#9 swiftcoder   Senior Moderators   -  Reputation: 11828

Like
0Likes
Like

Posted 27 November 2013 - 01:55 PM


Is that extreme legacy or what?

It is required by the fixed function pipeline. So if fixed function is "extreme legacy", then yes.


Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS