【问题标题】:OPENGL Texture2D manipulation directly/indirectlyOPENGL Texture2D 直接/间接操作
【发布时间】:2015-02-20 21:05:30
【问题描述】:

this tutorial 之后,我正在对 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。

【问题讨论】:

  • 你到底想知道什么?
  • 如何修改 CopyTexSubImage2D 的纹素例如数据[i] = 数据[i]*beta[i]。其中 beta[i] 是一个外部调制函数。
  • 我们在谈论什么样的修改?您正在使用的教程是ancient。现在,我们直接渲染成纹理,根本不需要这样的副本。可以通过简单地再次渲染到纹理中来修改数据,或者添加一些基于着色器的后处理通道,具体取决于要应用的修改类型。
  • 我明白了!首先我需要 glGetTexImage() 来获取数据。 link。谢谢大家!

标签: c++ opengl texture2d shadow-mapping


【解决方案1】:

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

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。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-01
    相关资源
    最近更新 更多