title: Do OpenGL GLSL samplers always return floats from 0.0 to 1.0?
body: <p>I've created a couple of floating point RGBA texture...</p>
  
  <pre><code>glBindTexture( GL_TEXTURE_2D, texid[k] );
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
  glTexImage2D(GL_TEXTURE_2D, 0, 4, width, height, 0, GL_RGBA,
               GL_FLOAT, data);
  </code></pre>
  
  <p>and then I double-buffer render/sample into them alternately in a shader program</p>
  
  <pre><code>    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, 
                         GL_TEXTURE_2D, texid[i], 0)
  </code></pre>
  
  <p>...</p>
  
  <pre><code>    state_tex_loc = glGetUniformLocation( program, "state_tex" )
      glUniform1i( state_tex_loc, 0 )
      glActiveTexture( GL_TEXTURE0 )
      glBindTexture( GL_TEXTURE_2D, texid[1-i] )
  </code></pre>
  
  <p>...</p>
  
  <pre><code>    void main( void )
      {
          gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
          vec2 sample_pos = gl_Vertex.xy / vec2( xscale, yscale );
          vec4 sample = texture2D( state_tex, sample_pos.xy );
          sample.rgb = sample.rgb + vec3( 0.5, 0.5, 0.5 );
          if ( sample.r &gt; 1.1 )
              sample.rgb = vec3( 0.0, 0.0, 0.0 );
          gl_FrontColor = sample;
      }
  </code></pre>
  
  <p>...</p>
  
  <pre><code>    void main( void )
      {
          gl_FragColor = gl_Color;
      }
  </code></pre>
  
  <p>Notice the check for <code>sample.r</code> being greater than 1.1. This never happens. It seems that either the call to <code>texture2D</code> or the output of the fragment shader clamps the value of sample.rgb to [0.0..1.0]. And yet, my understanding is that the textures themselves have complete floating-point types in them. </p>
  
  <p>Is there any way to avoid this clamping?</p>
  
  <p>UPDATE:</p>
  
  <p>As per instructions below, I've fixed my <code>glTexImage2D()</code> call to use GL_RGBA32F_ARB, but I still don't get a value greater than 1.0 out of the sampler.</p>
  
  <p>UPDATE 2:</p>
  
  <p>I just tried initializing the textures to values larger than 1.0, and it works! <code>texture2d()</code> returns the initial, > 1.0 values. So perhaps this means that the problem is in the fragment shader, writing to the texture?</p>
  
  <p>UPDATE 3:</p>
  
  <p>I've tried changing the shaders, and this works:</p>
  
  <pre><code>    varying vec4 out_color;
      void main( void )
      {
          gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
          vec2 sample_pos = gl_Vertex.xy / vec2( xscale, yscale );
          vec4 sample = texture2D( state_tex, sample_pos.xy );
          sample.rgb = sample.rgb + vec3( 0.5, 0.5, 0.5 );
          if ( sample.r &gt; 1.1 )
              sample.rgb = vec3( 0.0, 0.0, 0.0 );
          out_color = sample;
      }
  </code></pre>
  
  <p>...</p>
  
  <pre><code>    varying vec4 out_color;
      void main( void )
      {
          gl_FragColor = out_color;
      }
  </code></pre>
  
  <p>Why does using a custom varying work, but using the built-in varying gl_FrontColor/gl_Color not work?</p>