Question

I'm working on a game in OpenGL and here's what I'd like to do:

  1. During an iteration of game logic, access texels of a texture for computations.
  2. Still during the same logic interation, possibly modify the texels of the texture.
  3. Render the game scene with the current version of the texture.
  4. Start another iteration with similar access to texel data.

I'm having trouble using glGetTexImage() in that the call crashes my program, and I'm not entirely sure this is what I want to be using anyway.

The only straightforward way I can see to do this is to have a buffer in system memory with texel information that I can mess around with, and generate a new OpenGL texture from it every iteration. That seems like a bad move.

Any help?

Was it helpful?

Solution

There are several possible ways to do this.

  1. If you don't need any non-textured data to modify your texture you could use a fragment shader. (ping-pong technique might be interesting for that)
  2. Use glTexSubImage2D if only a small part of the texture is replaced and you don't need to worry about performance or it should work on older graphic cards.
  3. Use a pixel buffer object. That should be faster then glTexSubImage2D. Some more infos about that can be found here.

OTHER TIPS

I believe glTexSubImage2d is what you are looking for.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top