I'm trying to load these textures into the shader which seems okay as in the shader code I can effect either sampler2D like tex1+tex2 will work but for some reason tex2 doesn't seem to be loading the texture I assigned for texture unit 1 but rather texture unit 0.
I found that for some reason tex1 is loaded into texture unit 0 and 1 although I bind a different texture for each texture unit [ useTexture function calls glBindTexture]
I'm using the immediate mode to draw the vertices and texcoords and I do use glMultiTexCoord2f 2 time one for GL_TEXTURE0 and the other for GL_TEXTURE1.
glMultiTexCoord2f( GL_TEXTURE0, ...);
glMultiTexCoord2f( GL_TEXTURE1, ...);
///vertices...
I have no clue why when I set the active texture to GL_TEXTURE1 and set the 2nd texture it seems to really set the first. I have checked the # of texture units, and made sure the texIds were different. I even went as far as making sure which texture unit was active and so I'm stumped.
On the side when I look up the texture unit with glGetIntegerv is the value supposed to return something like 33394 for GL_TEXTURE0 and 33395 for GL_TEXTURE1 (those numbers are not exact but as I see it increased by one I would think that's just opengl's internal thinking).
Basically, the 1st texture seems to be bounded in both texUnit 0 and 1 but it doesn't make sense as I binded a different tex in texUnit 1.
int main(...)
{
///GLUT INIT...
///Load Texture
BilbyTex = new texBlock;
BilbyTex->storeImageSingle("./Bilby_Diffuse_512.jpg");
BilbyTex->useTexture();
HorseTex = new texBlock;
HorseTex->storeImageSingle("./test.jpg");
HorseTex->useTexture();
glActiveTexture(GL_TEXTURE0);
BilbyTex->useTexture();
glActiveTexture(GL_TEXTURE1);
HorseTex->useTexture(); ///doesn't seem to want to use it but uses the above instead
///END
///Load Shader
pointLightShader = new Shader("./Shaders/pLight.vert", "./Shaders/pLight.frag");
int uLoc=0;
uLoc = glGetUniformLocation( pointLightShader->getProgramHandler(), "texture" );
glUniform1i(uLoc, 0);
uLoc = glGetUniformLocation( pointLightShader->getProgramHandler(), "texture_2" );
glUniform1i(uLoc, 1);
uLoc = glGetUniformLocation( pointLightShader->getProgramHandler(), "camera_position" );
glUniform3fv(uLoc, 3, camera_pos);
pointLightShader->shaderLog(); ///Shows Log in Console Window
///END
Shader(glsl):
///Vertex:
varying vec3 position;
varying vec3 normal;
varying vec2 texC;
varying vec2 texC_2;
void main()
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; ///
gl_TexCoord[1] = gl_TextureMatrix[1] * gl_MultiTexCoord1; ///
normal = gl_NormalMatrix * gl_Normal;
position = gl_Vertex.xyz;
texC = gl_TexCoord[0].st; ///
texC_2 = gl_TexCoord[1].st; ///
}
///Fragement
uniform sampler2D texture;
uniform sampler2D texture_2;
uniform vec3 camera_position;
varying vec3 position;
varying vec3 normal;
varying vec2 texC;
varying vec2 texC_2;
void main()
{
int xL=0;
///Other Stuff...
vec4 texColor = texture2D(texture, texC);
vec4 texColor2 = texture2D(texture_2, texC_2);
texColor.r += 1.0;
texColor2.g += 1.0;
vec4 cTColor = texColor * texColor2;
//Note: Can't use var from varying or uniform for indexs apparently. At
//Least it seems for any of the special gl_xxxx calls
gl_FragColor = gl_LightSource[xL].ambient+
(diffuse * vec4(cTColor.rgb, 1.0)) +
(specular);
}
[Edited by - Asem on June 8, 2009 6:35:29 PM]