Store values in texture

Hi, Im trying to reach float values from a texture in GLSL using

 texture(sampler2d, texCoord).x 

I use luminance16, clamp to edge and nearest filter before I send it to the shader. I create the texture in this way

	for (int x = 0; x < width; ++x) {
        for (int y = 0; y < height; ++y) {

			if(x == 25 && y == 25)
				texData[y*width + x] = static_cast<GLubyte>(1.0);
				texData[y*width + x] = static_cast<GLubyte>(0.0);


and then I try to reach the value 1.0 by

 texture(sampler2d, vec2(25)).x 

is it possible to do it this way or am I missing something.

Thanks in advance!

For a texture2D u need to use the normalized texture coordinates (0-1). For doing it the way u r asking, you have to use rectangle textures.

I believe you could use the glsl function texelFetch(…) to access a specific texel avoiding the need to use rectangular textures.
Watch out to use an ivec2, not a vec2.

Thanks, I found out the problem. It worked when I switched 1 to 255 and then normalized it in the shader.

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