Sign in to follow this  
Dragon_Strike

texture 1+ doesnt work in shader

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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);
}

Share this post


Link to post
Share on other sites
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... ?!?!?!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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]
??

Share this post


Link to post
Share on other sites
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 110

uniform 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"...

Share this post


Link to post
Share on other sites
Just a stupid thought here, but in your code you're loading mid1.tga as GL_TEXTURE1 and mid2.tga as GL_TEXTURE0. In other words, it's a counter intuitive numbering scheme (1 is the 2nd texture, 2 is the first texture). So if mid1.tga is being rendered, then your code is working perfectly, even though you're expecting tex2.

Is that what's going on?

Share this post


Link to post
Share on other sites
Quote:
Original post by Nychold
Just a stupid thought here, but in your code you're loading mid1.tga as GL_TEXTURE1 and mid2.tga as GL_TEXTURE0. In other words, it's a counter intuitive numbering scheme (1 is the 2nd texture, 2 is the first texture). So if mid1.tga is being rendered, then your code is working perfectly, even though you're expecting tex2.

Is that what's going on?


not sure.. but i dont think thats the problem.. but ill look at ti...

Share this post


Link to post
Share on other sites
Quote:
Original post by PlayerX
Run it through glIntercept. It's been a godsend for me in finding those really obscure errors when using OpenGL.


ive tried it.. but it seems to advanced for me... its preyy funny... i still get GL_TEXTURE0 even if i disable it... i guess ill have to start over from scratch... sigh... another several hours wasted...

any ways thx for all the suggestions!

EDIT::

... something ive bene think of is that always texture0 gets rendered.. wouldnt that mean that the other textures doesnt work.. cuzz if i dont load anything to texture0 all i get is a black texture...

[Edited by - Dragon_Strike on September 30, 2006 9:53:04 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this