Jump to content
  • Advertisement
Sign in to follow this  
tracegame

OpenGL How to update texture per pixel every frame?

This topic is 1031 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!