GLSL changing textures, or rendering to texture?

Hello,

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?

cheers,

GL_EXT_framebuffer_object

http://www.flashbang.se/postbreak.php?id=18
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.

cheers,

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

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

glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, texTarget,tex2,0)
glReadBuffer(GL_COLOR_ATTACHMENT1_EXT)
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.

N.

As the OP said, he is using Python.
http://pyopengl.sourceforge.net/documentation/manual/glReadPixels.3G.html

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,…)?

N.

Hi,

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.

http://rene.f0o.com/~rene/stuff/gpudemo.py
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?

cu,

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