0

Following this tutorial, I am performing shadow mapping on a 3D scene. Now I want to manipulate the raw texel data of shadowMapTexture (see the excerpt below) before applying this using ARB extensions

//Textures
GLuint shadowMapTexture;  
...
...

**CopyTexSubImage2D** is used to copy the contents of the frame buffer into a 
texture. First we bind the shadow map texture, then copy the viewport into the 
texture. Since we have bound a **DEPTH_COMPONENT** texture, the data read will 
automatically come from the depth buffer.

//Read the depth buffer into the shadow map texture
glBindTexture(GL_TEXTURE_2D, shadowMapTexture);
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, shadowMapSize, shadowMapSize); 
  • N.B. I am using OpenGL 2.1 only.
  • 2
    And what exactly do you want to know? – derhass Dec 22 '14 at 18:20
  • How to modify the texels of *CopyTexSubImage2D* e.g. data[i] = data[i]*beta[i]. where beta[i] is an external modulating function. –  Dec 22 '14 at 18:52
  • And what kind of modification are we talking about? The tutorial you are using is _ancient_. Nowadays, we directly render into textures, and don't need such a copy at all. Modification of the data can be done by simply rendering into the texture again, or adding some shader-based post-processing pass, depending on the type of modifications which is to be applied. – derhass Dec 22 '14 at 18:55
  • I got it! First I need to **glGetTexImage()** to obtain the data. [link](http://stackoverflow.com/questions/5117653/how-to-get-texture-data-using-textureids-in-opengl). Thanks all! –  Dec 22 '14 at 19:17

1 Answers1

0

Tu can do it in 2 ways:

float* texels = ...;
glBindTexture(GL_TEXTURE_2D, shadowMapTexture);
glTexSubImage2D(GL_TEXTURE_2D, 0, x,y,w,h, GL_DEPTH_COMPONENT, GL_FLOAT, texels);

or

Attach your shadowMapTexture to (write) framebuffer and call:

float* pixels = ...;
glRasterPos2i(x,y)
glDrawPixels(w,h, GL_DEPTH_COMPONENT, GL_FLOAT, pixels);

Don't forget to disable depth_test first in above method.

Anonymous
  • 2,122
  • 19
  • 26