OPENGL Texture2D 直接或间接操作



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

//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。
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。

相关内容

  • 没有找到相关文章

最新更新