Problem with VBO and passing textures to GLSL

Hi all,

I’m working on a bump mapping project for school, and I’m having a problem passing the normal map to my fragment shader.

I’ve got a texture and normal map. The texture gets passed in fine, and I can render with it, but the normal map seems to contain the same data as the texture.

What I mean is, when I try to render the image using the data in the normal map, it displays as if I’m using the texture.

Here is the OpenGL code in my program:

prog->enable_shader_prog();

glBindBuffer(GL_ARRAY_BUFFER, VBO_ID);

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableVertexAttribArray(tan_loc);
glEnableVertexAttribArray(bitan_loc);
	
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex_ID);
prog->set_uniform1f("diffuseColor", 0);

glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, bump_map_ID);
prog->set_uniform1f("bumpMap", 1);

glVertexPointer(3, GL_FLOAT, 14 * sizeof(float), 0);
glTexCoordPointer(2, GL_FLOAT, 14 * sizeof(float), reinterpret_cast<void*>(3 * sizeof(float)));
glNormalPointer(GL_FLOAT, 14 * sizeof(float), reinterpret_cast<void*>(5 * sizeof(float)));
glVertexAttribPointer(tan_loc, 3, GL_FLOAT, false, 14 * sizeof(float), reinterpret_cast<void*>(8 * sizeof(float)));
glVertexAttribPointer(bitan_loc, 3, GL_FLOAT, false, 14 * sizeof(float), reinterpret_cast<void*>(11 * sizeof(float)));

glDrawArrays(GL_TRIANGLES, 0, nverticies);

glDisableVertexAttribArray(bitan_loc);
glDisableVertexAttribArray(tan_loc);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);

glBindBuffer(GL_ARRAY_BUFFER, 0);

glBindTexture(GL_TEXTURE_2D, 0);

prog->disable_shader_prog();

Here is my vertex shader:

attribute vec3 tangent;
attribute vec3 bitangent;

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

And my fragment shader:

uniform sampler2D diffuseColor;
uniform sampler2D bumpMap;

void main()
{
	// This works.
	gl_FragColor = texture2D(diffuseColor, gl_TexCoord[0].st);
	
	//This doesn't... it displays like the statement above.
	//gl_FragColor = texture2D(bumpMap, gl_TexCoord[0].st);
}

Don’t you need to use uniform1i for samplers instead of uniform1f?

Wow, I’ve been staring at this code for HOURS!

Haha, I can’t believe I missed that.

Thanks a lot!

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.