View Full Version : Store values in texture

04-28-2011, 01:59 AM
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 &amp;&amp; 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!

04-28-2011, 08:11 AM
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.

05-02-2011, 03:33 AM
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.

05-02-2011, 07:01 AM
Thanks, I found out the problem. It worked when I switched 1 to 255 and then normalized it in the shader.