The problem with Buffer Texture


glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_BUFFER, texture);
glTexBuffer(GL_TEXTURE_BUFFER, internalformat, buffer);
//glBindTexture(GL_TEXTURE_BUFFER, 0);

Hi, guys

The code to create a buffer texture works fine for now. But if I uncomment the last line, there is no data displayed. Is that a right thing?

Is that a right thing?

Yes. A texture must be bound to the context in order to be used. If you unbind it (by binding a different texture to that target and texture unit), then you have to bind it again before you can use it.

Oh, it’s my fault that mislead you. The full process is like this:


void Create()
{
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_BUFFER, texture);
glTexBuffer(GL_TEXTURE_BUFFER, internalformat, buffer);
//glBindTexture(GL_TEXTURE_BUFFER, 0);
}

void Display()
{
glActiveTexture(GL_Texture0);
glBindTexture(GL_TEXTURE_BUFFER, texture);
// Use shader to render data.
...
}

While in Create(), if I unbind the buffer texture after glTexBuffer, there is no data displayed. It’s so weird.