开发者

Wrong texture values in glCopyTexImage2D()

开发者 https://www.devze.com 2023-03-30 00:08 出处:网络
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)

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 text开发者_StackOverflow社区ure 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..


First, I have no idea how what you've posted compiles as there is no such thing as GL_DEPTH_TEXTURE. There is GL_DEPTH_COMPONENT however.

Second, you should always use sized depth formats. So instead of GL_DEPTH_COMPONENT, use GL_DEPTH_COMPONENT24 to get a 24-bit depth buffer. Note that the pixel transfer format (the argument third from the end) should still be GL_DEPTH_COMPONENT.

Third, you should use glCopyTexSubImage2D, so that you're not reallocating the texture memory all the time.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号