texture 1+ doesnt work in shader

Started by
12 comments, last by Dragon_Strike 17 years, 6 months ago
i can only get GL_TEXTURE0 to be sent to shader and idont understand why the others doesnt work.. EDIT:: Chagned the code for easier read...


	glActiveTexture(GL_TEXTURE0);
	glEnable( GL_TEXTURE_2D );
	Textures[0].LoadData("../Data/Textures/sand.tga");
	Textures[0].CreateTexture(GL_LINEAR,GL_LINEAR_MIPMAP_LINEAR,2.0f);

	glActiveTexture(GL_TEXTURE1);
	glEnable( GL_TEXTURE_2D );
	Textures[1].LoadData("../Data/Textures/grass.tga");
	Textures[1].CreateTexture(GL_LINEAR,GL_LINEAR_MIPMAP_LINEAR,2.0f);

        ShaderProgram->SendUniform("tex1", 0);
	ShaderProgram->SendUniform("tex2", 1);

		void CreateTexture(unsigned int mag, unsigned int min, float samples)
		{

			unsigned int iTempID;
			glGenTextures(1, &iTempID);
			glBindTexture(GL_TEXTURE_2D, iTempID);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, samples);
			gluBuild2DMipmaps( GL_TEXTURE_2D, GL_COMPRESSED_RGB, m_uiWidth, m_uiHeight, GL_RGB, GL_UNSIGNED_BYTE, GetData( ) );
			SetID( iTempID );
		}

//SHADERS

#version 110

uniform sampler2D normals;


void main()
{

	gl_TexCoord[0] = gl_MultiTexCoord0;
	gl_TexCoord[1] = gl_MultiTexCoord1;
	gl_Position = ftransform();	
}

#version 110


uniform sampler2D tex1;
uniform sampler2D tex2;


void main()
{
	
	vec3 tex1color = texture2D(tex1, gl_TexCoord[0].st).rgb;
	vec3 tex2color = texture2D(tex2, gl_TexCoord[1].st).rgb;

	vec3 finalcolor = tex2color;
	gl_FragColor = vec4(finalcolor.r,finalcolor.g,finalcolor.b,1.0);	
}




in this code altought i should get texture2 (GL_TEXTURE1) i get tex1 (GL_TEXTURE0) [Edited by - Dragon_Strike on September 27, 2006 1:11:24 AM]
Advertisement
given that, according to that code, you don't bind any texture to texture unit 0 i'm impressed you are getting anything at all...
glActiveTexture(GL_TEXTURE0);
glActiveTexture(GL_TEXTURE1);
glEnable( GL_TEXTURE_2D );
Textures[0].LoadData("../Data/Textures/sand.tga");
Textures[0].CreateTexture(GL_LINEAR,GL_LINEAR_MIPMAP_LINEAR,2.0f);

Why are you doing glActiveTexture for texture0 then immediately changing to texture1?
im sorry that was just a typo from when i was pasting the coding..
seriously nobody got any idea? ive tried everything i could think of... ive set only GL_TEXTURE1 and 2 but then i get no texture at all.. ive been working with this for hours without finding the problem.. its frustrating..

if i use texture2D(tex2, gl_TexCoord[1].st) when TEXTURE0 is enable i get TEXTURE0 when i dont have TEXTURE0 mnebaled and only TEXTURE1.. i get nothing.. just black

[Edited by - Dragon_Strike on September 27, 2006 5:44:21 PM]
What are you calls to draw the geometry?
ShaderProgram->SendUniform("tex1", 1);
ShaderProgram->SendUniform("tex2", 2);

glCallList(Chunk->List);

inline RenderVertex(int x, float y, int z)
{
glMultiTexCoord2f(GL_TEXTURE0, (float)x/(float)m_iSize, (float)z/(float)m_iSize);
glMultiTexCoord2f(GL_TEXTURE1,(float)x/(float)m_iSize, (float)z/(float)m_iSize);
glVertex3f( x, y, z);
}
there is something seriously wrong here.. ive tried removing some of the code.. and this is just wierd...

with jsut these to lines i get the texture0 rendered

glGenTextures(1, &iTempID);
gluBuild2DMipmaps( GL_TEXTURE_2D, GL_COMPRESSED_RGB, m_uiWidth, m_uiHeight, GL_RGB, GL_UNSIGNED_BYTE, GetData( ) );

i dont have to active any GL_TEXTURe or enable 2d_TEXTURE i dont even need to bind the fricking texture all i have to do is Gen and build it.. and its rendered... ?!?!?!
Quote:Original post by Dragon_Strike
there is something seriously wrong here.. ive tried removing some of the code.. and this is just wierd...

with jsut these to lines i get the texture0 rendered

glGenTextures(1, &iTempID);
gluBuild2DMipmaps( GL_TEXTURE_2D, GL_COMPRESSED_RGB, m_uiWidth, m_uiHeight, GL_RGB, GL_UNSIGNED_BYTE, GetData( ) );

i dont have to active any GL_TEXTURe or enable 2d_TEXTURE i dont even need to bind the fricking texture all i have to do is Gen and build it.. and its rendered... ?!?!?!


I remember if using shaders you don't need to actually enable GL_TEXTURE_2D, that might be the reason it's working that way

Have you tried

[SOURCE]	Textures[0].LoadData("../Data/Textures/sand.tga");	Textures[0].CreateTexture(GL_LINEAR,GL_LINEAR_MIPMAP_LINEAR,2.0f);	Textures[1].LoadData("../Data/Textures/grass.tga");	Textures[1].CreateTexture(GL_LINEAR,GL_LINEAR_MIPMAP_LINEAR,2.0f);	        glActiveTexture(GL_TEXTURE0);	glEnable( GL_TEXTURE_2D );        // Bind texture 0        ShaderProgram->SendUniform("tex1", 0);	glActiveTexture(GL_TEXTURE1);	glEnable( GL_TEXTURE_2D );        // Bind texture 1	ShaderProgram->SendUniform("tex2", 1);[/SOURCE]
??
ok this is what ive got

	Texture1.LoadData("../Data/Textures/mid2.tga");	unsigned int iTempID1;	glGenTextures(1, &iTempID1);	glBindTexture(GL_TEXTURE_2D, iTempID1);	gluBuild2DMipmaps( GL_TEXTURE_2D, GL_COMPRESSED_RGB, Texture1.m_uiWidth, Texture1.m_uiHeight, GL_RGB, GL_UNSIGNED_BYTE, Texture1.GetData( ) );	Texture1.SetID( iTempID1 );	Texture2.LoadData("../Data/Textures/mid1.tga");	unsigned int iTempID2;	glGenTextures(1, &iTempID2);	glBindTexture(GL_TEXTURE_2D, iTempID2);	gluBuild2DMipmaps( GL_TEXTURE_2D, GL_COMPRESSED_RGB, Texture2.m_uiWidth, Texture2.m_uiHeight, GL_RGB, GL_UNSIGNED_BYTE, Texture2.GetData( ) );	Texture2.SetID( iTempID2 );_____________________________________ShaderProgram->SendUniform("angle", SunAngle);ShaderProgram->SendUniform("normals", 0);glActiveTexture(GL_TEXTURE0);glEnable( GL_TEXTURE_2D );			glBindTexture(GL_TEXTURE_2D, Texture1.GetID());ShaderProgram->SendUniform("tex1", 0);glActiveTexture(GL_TEXTURE1);glEnable( GL_TEXTURE_2D );			glBindTexture(GL_TEXTURE_2D, Texture2.GetID());ShaderProgram->SendUniform("tex2", 1);glCallList(Chunk->List);	_________________________________________#version 110uniform sampler2D tex1;uniform sampler2D tex2;uniform sampler2D tex3;uniform sampler2D tex4;uniform sampler2D normals;uniform float angle;void main(){	gl_FragColor = texture2D(tex2, gl_TexCoord[1].st);	}


still its "tex1" thats being rendered and not "tex2"...

This topic is closed to new replies.

Advertisement