Hey, I’m having a bit of trouble trying to pull out some texture data in my vs. I have read several tutorials and i seem to be doing everything as is suggested. here are some code snippets. Any help would be appreciated.
The same uniform sampler seems to work okay in my fragment shader so I don’t think there is anything wrong with the texture that I can see.
This code is setting my v.y to just under 1.2 across the entire surface.
vs:
...
uniform sampler2D displacementMap;
...
void main(void)
{
...
vertexPosition.x = gl_Vertex.x/10.0;
vertexPosition.y = -gl_Vertex.z/10.0;
vec4 v = vec4(gl_Vertex);
vec4 texel = texture2DLod(displacementMap, vertexPosition, 0.0); //vertexPosition is filled with the values 0.0-199.0
v.y = (texel.r+texel.g+texel.b); //the texture size is 200x200
gl_Position = gl_ModelViewProjectionMatrix * v;
...
}
The texture loading code:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, width, height, GL_BGR, GL_UNSIGNED_BYTE, data);
I am using OpenGL 3.1 on an NVIDIA Quadro NVS 135M currently.
Any thoughts?