Search code examples
c++glsl

read float texture in shader, value is always zero


I'm trying send float buf(row 1020. col 4) data to a shader

The follow is my c++ code

float angle_maps[1020 * 4];

GLuint angle_maps_distort_texture;

glGenTextures(1, &angle_maps_distort_texture);
glBindTexture(GL_TEXTURE_2D, angle_maps_distort_texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 4);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB, 1020, 1, 0, GL_RGBA, GL_FLOAT, angle_maps);

glActiveTexture(GL_TEXTURE4);
glBindTexture(GL_TEXTURE_BUFFER, angle_maps_distort_texture);
m_shaderProgram->set_uniform_value("angle_maps_distort_text", 4);

The follow is frag shader

uniform sampler2D angle_maps_distort_text;

float theta_degree = degrees(theta);
//The range of values returned by theta_degree is [0.0, 102.0]
vec4 factor = texture(angle_maps_distort_text, vec2(theta_degree/102.0, 0.0));

I am true the factor value is always zero. May be some step to send texture is wrong, But I don't know where is the issue, does anyone have similar problem, please help me, Thanks


Solution

  • I found out the issue. glBindTexture(GL_TEXTURE_BUFFER, angle_maps_distort_texture); change GL_TEXTURE_BUFFER to GL_TEXTURE_2D