-2

I'm studying clipmap algorithm, and I want to get elevations by VTF. But I've got a problem when using vertex textures. 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++)
data[i]=float(rand()%100)/100.0;
glGenTextures(1, &vertexTexture);   
//glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, vertexTexture);

//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_NEAREST_MIPMAP_NEAREST);
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 tried texture2D(vertexTexture, vTexCoords) 
    // and texture(vertexTexture, vTexCoords),but they don't work.
    vec4 position=vec4(vVertex.x,height,vVertex.y,1.0);
    gl_Position = mvpMatrix * position;
}

I store some random floats in array data then store them with a texture,and as the vertex shader showing,I want to get some values to the y coordinate by VTF.but the result is that the height is always 0.I think something must be wrong. I don't know what's wrong and how to do it the right way.

genpfault
  • 51,148
  • 11
  • 85
  • 139
Qingsong
  • 51
  • 1
  • 7
  • 1
    What is the actual problem? Please describe what you expect. – Gorgsenegger Mar 22 '14 at 16:16
  • I store some random floats in array data then store them with a texture,and as the vertex shader showing,I want to get some values to the y coordinate by VTF.but the result is that the height is always 0.I think something must be wrong. I don't know what's wrong and how to do it the right way. – Qingsong Mar 23 '14 at 02:44
  • `GL_LUMINANCE_FLOAT32_ATI`? On an implementation that supports `#version 410`? Why not `GL_R32F`? – genpfault Mar 24 '14 at 06:08
  • I'm a new learner. i found that some ATIcards don't support VTF or only support 2 format of data when i want to use VTF,so i adapt one of them just in case. i think it doesn't a big deal. it still doesn't work when i use GL_R32F. – Qingsong Mar 24 '14 at 09:21
  • by the way,where can i learn the knowledge like which data-type is better when using a shader with a specific version? – Qingsong Mar 24 '14 at 09:29
  • Are you setting the `vertexTexture` uniform somewhere? – GuyRT Mar 24 '14 at 12:08
  • i set its value as 0 in client-end – Qingsong Mar 25 '14 at 02:48

1 Answers1

1

it's solved now.the answer is here.thank you all!

Try setting the texture's minification filter to GL_NEAREST or GL_LINEAR after glTexImage2D():

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

The OpenGL default is to use mipmaps and you didn't send any which makes the texture incomplete and will disable that texture image unit.

Then you can use texture(vertexTexture, vTexCoords) inside the shader instead of the deprecated texture2DLOD() version with the explicit LOD access.

Qingsong
  • 51
  • 1
  • 7