GLSL changing textures, or rendering to texture?


how would I write a shader which changes a texture?

I would like to write to a texture some how.

Does anyone know of an example of doing this?

Or can someone point me to a place on how to change textures with GLSL?


A somewhat simplistic tutorial, but it will work.
Just remember that you can’t write and read from/to the same texture, in that case you either have to use blending if you can, or two textures.

Thanks for the replies.

How can I use blending to read from the texture I just wrote to?

I want to do the following:

  • copy data to texture 0.
  • render to texture 1 with GLSL fragment program accessing texture 0.
  • read data out of texture 1 into memory.

I seem to have a program working with one texture which can do this:

  • copy data to texture 0.
  • render to texture 0 with GLSL fragment program.
  • read data out of texture 0 into memory.


I seem to have to read from the texture 0, then read from the texture 1… and it kind of works:

result = glReadPixels(0, 0, 0, 0,texFormat,GL_FLOAT)

glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, texTarget,tex2,0)
result = glReadPixels(0, 0, texSize, texSize,texFormat,GL_FLOAT)

I say kind of works, because I get the expected result - however my program segfaults on exit. (might be related to python ref counts or something… maybe not related to this).

I’m surprised the readpixels calls work, they don’t even have the right amount of parameters.


As the OP said, he is using Python.

Oh, I see. I’ve been messing around a bit with PyOpenGL, only to tweak some small linux apps to suit my needs but until now I assumed the calls where always the same format. Thanks for pointing that out. That aside, Why would you call readpixels with (0,0,0,0,…)?



That first glReadPixels call seems to be required for the second one to work at all. Since I’m not interested in the data at all I pass 0,0 for height, and width. Changing it to say 16,16 or 1,1 makes no difference.
It requires opengl-ctypes latest cvs, and crashes on exit. Python opengl is very similar to C opengl… but a few calls are different.

Can anyone see anything wrong with what I’m doing?


This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.