Texture Buffer Object Problem

I’m having trouble setting up a GL_TEXTURE_BUFFER

I have written a simple program to draw a cube at the origin and then have it’s position offset by data stored in a 1D texture.

I initially tried this:

	float position[4]={1.0f, 1.0f, 0, 0};
	//Create a TBO For position
	glGenBuffers(1, &m_tbo);
	glBindBuffer(GL_TEXTURE_BUFFER, m_tbo);
	glBufferData(GL_TEXTURE_BUFFER, sizeof(float)*4, position, GL_STATIC_DRAW);	

	glGenTextures(1, &m_texID);
	glBindTexture(GL_TEXTURE_BUFFER, m_texID);
	glTexBuffer(GL_TEXTURE_BUFFER, GL_RGBA32F, m_tbo);	

in my initialization code, and it doesn’t work,
but if replace it with this:

	float position[4]={1.0f, 1.0f, 0, 0};

	//create TextureID
	glGenTextures(1, &m_texID);
	glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA32F, 1, 0, GL_RGBA, GL_FLOAT, position);				

the exact same code works fine.

I am using a simple vertex shader with texelFetch to get the position data from the sampler. This is all running on OpenGL 3.3 and a gtx460 (258.96 drivers). I am not using any other textures in the program.

If someone could please point out where i am going wrong it’d be a big help :slight_smile:

You texture buffer object code looks fine, but to be paranoid:

  1. do you call glUniform1i on the uniform for the texture buffer object, setting the value to 0?

  2. since you did not post the shader: the type for a texture buffer object is different in GLSL. 1D textures are sampler1D where as texture buffer objects are samplerBuffer.

Also a great help is glValidateProgram, it checks that the current GL state is ok with the active GLSL program, I advise calling that, getting the value of GL_VALIDATE_STATUS (via glGetProgramiv) and making sure it is GL_TRUE, if not, then use glGetProgramInfoLog to see why the GL implementation is not co-operating.

Thank you so much for the quick response kRougue:

I was setting the sampler uniform to 0 at initialization, however I was not using samplerBuffer because it gave me a compiler error with texelFetch when i first tried it. I forgot that the texture buffer only has one level and was using the 1d texture version which requires you specify the mip-map level.

Thanks again!