views:

301

answers:

1

I'm trying send some 32 bit float data to a shader, but the results are erratic. If I test with full white (1,1,1,1) the values are all zero. This is my code for creating the texture:

gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA32F_ARB, 512, 512, 0, GL.GL_RGBA, GL.GL_FLOAT, data);

and reading from it in GLSL:

uniform sampler2D u_tex1;

varying vec2 v_uv;

void main()
{
    gl_FragColor = texture2D(u_tex1, v_uv);
}

If i set the texture to random values something shows up, but it's not correct. Is this the correct way to read from an RGBA32F texture or am I missing something?

+1  A: 

You're not giving much info on the things you did< The code you show is correct though.

Some things I can think of that may be wrong:

  • your data does not have the right data in (are there floats in there?)
  • your texture is not filtered properly (since you only provide 1 mip level, you need to disable mipmapping)
  • your texture is not bound to the texture unit for the sampler u_tex1 (so you may not be fetching from it).
  • your texture coordinates are not what you think they are (and, depending on your clamping/wrapping mode, this can lead to a texel that is not white. Use GL_CLAMP_TO_EDGE or GL_REPEAT to not interact with the texture border)

There are lots of ways to not have texturing working, I hope I hit the correct one in this list!

Bahbar
Thanks Bahbar. I was storing the data in a ByteBuffer which had the wrong order. That should have been the first thing i checked! I needed to insert this line after allocating the buffer data.order(ByteOrder.nativeOrder());
notlion