glCopyTexImage2D() 中的纹理值错误
我从 glCopyTexImage2D() 得到了错误的纹理值。我将深度纹理附加到 FBO,并在渲染通道中获取其值。我期望得到如下结果:(x:背景,y:正确像素)
---yyyyyyyyyyyyyyyyyyyy-----
-----------yyyyyyyyyyy------
yyyyyy----------y-----------
yyyyyyyyyy-------y----y-yyyy
yyyyyyyyyyyyyyyyyyyyyy------
但是,我的结果是这样的:
---yyyyyyyyyyyyyyyyyyyy-----
-----------yyyyyyyyyyy------
yyyyyy----------y-----------
----------------------------
----------------------------
从纹理的一半到末尾,仅呈现背景像素。当然,从左上角到一半我得到了正确的结果。
纹理创建代码如下:
glGenTexture(1, &tex);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_TEXTURE, w, h, 0, GL_DEPTH_TEXTURE, GL_FLOAT, 0);
在渲染代码中,
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_TEXTURE, 0, 0, w, h, 0);
glCopyTexImage2D 有任何错误吗? w 和 h 是固定的,我不知道为什么..
I got wrong texture values from glCopyTexImage2D(). I attached depth texture to FBO, and got its value in rendering pass. I expected a result like below : (x : background, y : correct pixel)
---yyyyyyyyyyyyyyyyyyyy-----
-----------yyyyyyyyyyy------
yyyyyy----------y-----------
yyyyyyyyyy-------y----y-yyyy
yyyyyyyyyyyyyyyyyyyyyy------
but, my result is like this :
---yyyyyyyyyyyyyyyyyyyy-----
-----------yyyyyyyyyyy------
yyyyyy----------y-----------
----------------------------
----------------------------
From the half of the texture to the end, background pixels are only presented. of course, from the top-left to the half I got a correct result.
a texture creation code is below :
glGenTexture(1, &tex);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_TEXTURE, w, h, 0, GL_DEPTH_TEXTURE, GL_FLOAT, 0);
and in rendering code,
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_TEXTURE, 0, 0, w, h, 0);
Is there any mistake in glCopyTexImage2D? w and h is fixed and I don't know why..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,我不知道您发布的内容如何编译,因为没有 GL_DEPTH_TEXTURE 之类的东西。但是有
GL_DEPTH_COMPONENT
。其次,您应该始终使用大小深度格式。因此,不要使用
GL_DEPTH_COMPONENT
,而是使用GL_DEPTH_COMPONENT24
来获取 24 位深度缓冲区。请注意,像素传输格式(倒数第三个参数)仍应为 GL_DEPTH_COMPONENT 。第三,您应该使用glCopyTexSubImage2D,这样您就不会一直重新分配纹理内存。
First, I have no idea how what you've posted compiles as there is no such thing as
GL_DEPTH_TEXTURE
. There isGL_DEPTH_COMPONENT
however.Second, you should always use sized depth formats. So instead of
GL_DEPTH_COMPONENT
, useGL_DEPTH_COMPONENT24
to get a 24-bit depth buffer. Note that the pixel transfer format (the argument third from the end) should still beGL_DEPTH_COMPONENT
.Third, you should use
glCopyTexSubImage2D
, so that you're not reallocating the texture memory all the time.