1D texture lookup

I am trying to pass a 1D float texture to my shader for use as a lookup. I am using GLSL.

I create my texture as follows:



	glGenTextures(1, &m_TextureID);
	glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 
				  m_TextureID);

	glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP);
	glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP);	

	m_TextureWidth  = 1024;
	m_TextureHeight = 1;

	int textureSize	= m_TextureWidth * m_TextureHeight * 4;
	float *textureData 		= new float[textureSize];

	for(int nRow = 0; nRow < m_TextureHeight; nRow++) {
		for(int nCol = 0; nCol < m_TextureWidth; nCol++) {

			int index = nCol + nRow * m_TextureWidth;
			int texelIndex = 4 * index;

			textureData[texelIndex + 0] = float(0.2 * index);	// r
			textureData[texelIndex + 1] = float(0.4 * index);	// g
			textureData[texelIndex + 2] = float(0.8 * index);	// g
			textureData[texelIndex + 3] = float(1.0 * index);	// a

		}
	}

	glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 
					0,
					GL_FLOAT_RGBA32_NV, 
					m_TextureWidth, 
					m_TextureHeight, 
					0, 
					GL_RGBA, 
					GL_FLOAT, 
					textureData);	

I initialize the location of my texture uniform as follows:


m_TextureLocation = glGetUniformLocation(m_ShaderProgram, "MyTexture");		
if (m_TextureLocation == -1) {
	fprintf(stderr, "No such uniform named MyTexture
");
	errorCode = -5;
}	else {
}

I set the uniform value as follows:


glEnable(GL_TEXTURE_RECTANGLE_ARB);
glActiveTextureARB(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, m_TextureID);			
if (m_TextureLocation == -1) {
} else {
	glUniform1i(m_TextureLocation, 0);
}

My frag shader is as follows:


--------------------------------------------------------------------------
uniform samplerRect MyTexture;

void main( void )
{		
    gl_FragColor = vec4(0.8, 0.6, 0.4, 1.0);    

	float textureCoordinate = float(100.0);
	float texel  			= textureRect(MyTexture, textureCoordinate);

    float red   = texel.r;
    float green = texel.g;
    float blue  = texel.b;
    float alpha = texel.a;

    gl_FragColor = vec4(red, blue, green, alpha);    

}

is textureRect the correct call to retrieve the texel at ‘textureCoordiante’? I am not seeing the data I think I should be. Do I have something wrong elsewhere… outside the shader?

CD

forget to bind your program for uniform update? I’ve made that mistake a million times or so…

No, it’s bound… I other parts of my shader are working ok… I am just having this problem with the texture lookup.

CD