我在 OpenGl 中绘制了一个立方体以将其用作天空盒。 我正在使用单个纹理图像,并使用 UV 坐标将 6 个面定位在正确的位置。 我使用以下代码发送纹理:
//------------------------------------Luminance--------------------------------------------------------------
glPixelStorei(GL_UNPACK_ROW_LENGTH, m_width);
glBindTexture(GL_TEXTURE_2D, texturePointer[0]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, m_width, m_height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, m_uYdata);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
//--------------------------------------U component------------------------------------------------------------
glPixelStorei(GL_UNPACK_ROW_LENGTH, m_uvWidth);
glBindTexture(GL_TEXTURE_2D, texturePointer[1]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, m_uvWidth, m_uvHeight, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, m_uUdata);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
//------------------------------------- V component-------------------------------------------------------------
glBindTexture(GL_TEXTURE_2D, texturePointer[2]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, m_uvWidth, m_uvHeight, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, m_uVdata);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
我无法删除立方体面之间的白色边缘,请参见下图:
GL_NEAREST
解决了问题但图像质量较低,
我怎样才能使用 GL_LINEAR
并消除这种效果?
编辑:
立方体是使用以下教程创建的: Model loading
考虑到纹理是由六个面按列拼接而成。 实际的 Blender 对象是:
# Blender v2.77 (sub 0) OBJ File: 'demo_cube.blend'
# www.blender.org
o Cube
v 1.000000 -1.000000 -1.000000
v 1.0000000 -1.000000 1.000000
v -1.000000 -1.000000 1.000000
v -1.000000 -1.000000 -1.000000
v 1.000000 1.000000 -1.000000
v 1.0000000 1.000000 1.000000
v -1.000000 1.000000 1.000000
v -1.000000 1.000000 -1.000000
vt 0.833333333 0.0000
vt 0.666666666 1.0000
vt 0.833333333 1.0000
vt 0.833333333 0.0000
vt 1.000000000 1.0000
vt 1.000000000 0.0000
vt 0.333333333 1.0000
vt 0.500000000 0.0000
vt 0.333333333 0.0000
vt 0.500000000 1.0000
vt 0.666666666 0.0000
vt 0.500000000 0.0000
vt 0.000000000 0.0000
vt 0.166666666 1.0000
vt 0.166666666 0.0000
vt 0.333333333 0.0000
vt 0.166666666 1.0000
vt 0.333333333 1.0000
vt 0.666666666 0.0000
vt 0.833333333 1.0000
vt 0.500000000 1.0000
vt 0.666666666 1.0000
vt 0.000000000 1.0000
vt 0.166666666 0.0000
s off
f 2/1 4/2 1/3
f 8/4 6/5 5/6
f 5/7 2/8 1/9
f 6/10 3/11 2/12
f 3/13 8/14 4/15
f 1/16 8/17 5/18
f 2/1 3/19 4/2
f 8/4 7/20 6/5
f 5/7 6/21 2/8
f 6/10 7/22 3/11
f 3/13 7/23 8/14
f 1/16 4/24 8/17
//44 and 47
片段着色器是:
#version 330 core
in vec2 oTexCoord;
uniform sampler2D yChannel;
uniform sampler2D uChannel;
uniform sampler2D vChannel;
out vec4 color;
const vec3 offset = vec3(0.0625, 0.5, 0.5);
const mat3 coef = mat3(
1.164, 0.0, 1.793,
1.164, -0.213, -0.533,
1.164, 2.112, 0.0
);
void main()
{
vec2 nTexCoord = vec2(oTexCoord.x, 1.0 - oTexCoord.y);
vec4 Tcolor = vec4(1.0);
if(oTexCoord.y <1 && oTexCoord.y > 0.0) {
if(oTexCoord.x < 1 && oTexCoord.x > 0.0) {
vec3 yuv = vec3(
texture(yChannel, nTexCoord).r,
texture(uChannel, nTexCoord).r,
texture(vChannel, nTexCoord).r
) - offset;
vec3 rgb = yuv * coef;
Tcolor = vec4(rgb, 1.0);
}
}
color = Tcolor;
}
最佳答案
我想你想使用 cubemaps和 GL_ARB_seamless_cube_map
:
Although it is unlikely that the generated ( s t ) coordinate lies significantly outside the determined cube map face, it is often the case that the locations of the individual elements required during a linear sampling do not lie within the determined face, and their coordinates will therefore be modified by the selected clamping and wrapping rules. This often has the effect of producing seams or other discontinuities in the sampled texture.
This extension allows implementations to take samples from adjacent cube map faces, providing the ability to create seamless cube maps.
(强调我的)。
要使用它,首先检查您是否确实拥有该扩展(这取决于您的平台以及最终帮助您访问 OpenGL 的工具包),然后只需编写
glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
(全局)启用它。
关于c++ - 立方体在 OpenGL 中的边缘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37617814/