View Full Version : HELP! I got a problem when using vertex texture

Qingsong Yan
03-22-2014, 07:40 AM
At last,I'm studying clipmap algorithm,and I want to get elevations by VTF.
But I got a problem when using vertex texture. I don't know what's wrong.:(
the related code is like this:

int width=127;

float *data=new float[width*width];
for(int i=0;i<width*width;i++)
glGenTextures(1, &vertexTexture);
glBindTexture(GL_TEXTURE_2D, vertexTexture);

glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_FLOAT32_ATI, width,width, 0,GL_LUMINANCE, GL_FLOAT, data);

the GLSL code in vertex shader is like this:

#version 410
uniform mat4 mvpMatrix;
uniform sampler2D vertexTexture;
in vec2 vVertex;

void main(void)
vec2 vTexCoords=vVertex/127.0;
float height = texture2DLod(vertexTexture, vTexCoords,0.0).x*100.0;
//I also try texture2D(vertexTexture, vTexCoords) and texture(vertexTexture, vTexCoords)
vec4 position=vec4(vVertex.x,height,vVertex.y,1.0);
gl_Position = mvpMatrix * position;

please tell me what's wrong and how can I fix it.