How can I read/write pixels in an OpenGL texture?

BlitzMax Forums/OpenGL Module/How can I read/write pixels in an OpenGL texture?

SofaKng(Posted 2007) [#1]
I know that BlitzMax has a TPixmap object that can be used for reading/writing pixels, but I'm trying to use pure OpenGL for this (as a learning experience).

So, I'm wondering how I can read and write pixels from an OpenGL texture.

I'm pretty sure it involves the following functions, but I'm not sure:

glTexSubImage2d (write pixels to a texture)

glGetTexImage (get pixels from a texture)
glGetTexLevelParameterfv (used to get pixel dimensions for figuring out what size of an array needed for use with glGetTexImage)


ImaginaryHuman(Posted 2007) [#2]
To download pixels from the backbuffer into main memory you use glReadPixels(). You have to set up things like glTexParameter() before you do the transfer, and you need some memory allocated to download to - which is what pixmaps usually are for. You could use a bank.

To download from a texture to main memory I presume you'd use glGetTexImage(). I've never heard of that one.

glTexSubImage2d uploads pixels from main memory to a portion on an existing previously defined texture, kind of a drawimage-rect (which is faster than making a new texture).