How to update texture per pixel every frame?
New to OpenGL.
I want to write pixel to texture oen by one.
In directx 11.I do something below
hr = mDeviceContext->Map(pNewTexture, subresource, D3D11_MAP_READ_WRITE, 0, &resource);
float* source = static_cast< float* >(resource.pData);
then i can direct operate source
for (int i = 0; i < 512; ++i)
{
source = height;
}
then unmap it
mDeviceContext->Unmap(pNewTexture, 0);
and copy to the texture i want to
mDeviceContext->CopyResource(audioTex, pNewTexture);
all done
what is the equivalent code in OpenGL?
i try to write like
glBindBuffer(GL_TEXTURE_BUFFER, tex2);
void *ptr = glMapBuffer(GL_TEXTURE_BUFFER, GL_WRITE_ONLY);
unsigned char data[] = {0,100,100,100};
memcpy(ptr, data, sizeof(data));
glUnmapBuffer(GL_TEXTURE_BUFFER);
glBindBuffer(GL_TEXTURE_BUFFER, 0);
but this does not seem to change the texture.
instead it accidently change my vertex position.
strange
what is the right way to do this?
GL_TEXTURE_BUFFER is very specific case, working with 1D textures, whose memory is hosted by texture buffer.
But probably your texture is generic 2D map?
In that case you should resort to glGetTexImage/glTexSubImage, preferably using PBO (http://www.songho.ca/opengl/gl_pbo.html) for asynchronous updates of large blocks.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement