0

按照本教程,我将在 3D 场景上执行阴影映射。现在我想在使用 ARB 扩展应用它之前操作shadowMapTexture的原始纹素数据(见下面的摘录)

//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); 
  • 注意我只使用 OpenGL 2.1。
4

1 回答 1

0

Tu可以通过两种方式做到这一点:

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

或者

将您的 shadowMapTexture 附加到(写入)帧缓冲区并调用:

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

不要忘记在上述方法中首先禁用 depth_test。

于 2014-12-22T18:34:20.553 回答