PDA

View Full Version : Work with textures



Hamid Reza
08-30-2010, 11:42 PM
Hi,I'm new in glsl.
I want to use from 'texture2d' function twice for 2 separate texture and mix their colors.
But i don't know how i can do this work.
I wrote this code for do it, but not work.
Vertex program:

void main()
{
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
}
Fragment Program:

uniform sampler2D tex0;
uniform sampler2D tex1;
void main (void)
{
vec4 Color0=texture2D(tex0, gl_TexCoord[0].st);
vec4 Color1=texture2D(tex1, gl_TexCoord[0].st);
gl_FragColor = (Color0+Color1)/2.0;
}
Initial C++ Code:

.
.
.
glBindTexture(GL_TEXTURE_2D,0);
Load Tex0

glBindTexture(GL_TEXTURE_2D,1);
Load Tex1

int Tex0 = glGetUniformLocationARB(my_program,"tex0");
glUniform1iARB(Tex0,0);

int Tex1 = glGetUniformLocationARB(my_program,"tex1");
glUniform1iARB(Tex1,1);
.
.
.
Please help me.
Thank you for your attention. :)

mhagain
08-31-2010, 02:20 AM
What happens when you call glUniform1iARB(Tex0,0); and glUniform1iARB(Tex1,1); before binding the textures?

frank li
08-31-2010, 07:24 PM
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D,0);
Load Tex0

glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D,1);
Load Tex1

int Tex0 = glGetUniformLocationARB(my_program,"tex0");
glUniform1iARB(Tex0,0);

int Tex1 = glGetUniformLocationARB(my_program,"tex1");
glUniform1iARB(Tex1,1);

Hamid Reza
09-01-2010, 12:36 AM
Thank you for your answering.
But it doesn't work well yet...
And color0 and color1 values are same! :(