我正在构建一个用户从内向外看的盒子,一个天空盒子或类似的东西。我这样做是通过取 6 个四边形并用它们创建一个立方体,然后将理论相机放在立方体内并用图像对立方体进行纹理处理。用户可以使用鼠标环顾四周,立方体旋转,看起来好像一个人在移动他们的头。我遇到了在两侧的交叉点出现白线的问题,我尝试在保持实际四边形大小相同的同时拉入四边形。我已经确定清晰的颜色是黑色的,我仍然得到白线。
这是我设置的属性:
glClearColor(0.0, 0.0, 0.0, 0.0);
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT);
glClearDepth(1);
//S is the side length of the cube
float s = 5;
glShadeModel(GL_SMOOTH);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glHint(GL_POLYGON_SMOOTH, GL_NICEST);
glEnable(GL_POLYGON_SMOOTH);
glDisable(GL_COLOR_MATERIAL);
glDisable(GL_LIGHTING);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
这是创建多维数据集的代码:
float s = 5; //S is the side length of each quad
glNewList(m_cube, GL_COMPILE);
{
glPushMatrix();
{
glEnable(GL_TEXTURE_2D);
glPushMatrix();
{
glBegin(GL_QUADS);
{
//front
{
glTexCoord2f(0.5f, (1.0f / 3.0f));
// glColor3f(1, 0, 0);
glVertex3f(((s / 2.0f)), ((s / 2.0f)),
-((s / 2.0f))); //1
glTexCoord2f(0.25f, (1.0f / 3.0f));
// glColor3f(1, 1, 0);
glVertex3f(-((s / 2.0f)), ((s / 2.0f)),
-((s / 2.0f))); //2
glTexCoord2f(0.25f, (2.0f / 3.0f));
// glColor3f(1, 0, 1);
glVertex3f(-((s / 2.0f)), -((s / 2.0f)),
-((s / 2.0f))); //3
glTexCoord2f(0.5f, (2.0f / 3.0f));
// glColor3f(1, 1, 1);
glVertex3f(((s / 2.0f)), -((s / 2.0f)),
-((s / 2.0f))); //4
}
//left
{
glTexCoord2f(0.25f, (1.0f / 3.0f));
// glColor3f(1, 0, 0);
glVertex3f(-((s / 2.0f)), ((s / 2.0f)),
-((s / 2.0f))); //2
glTexCoord2f(0.0f, (1.0f / 3.0f));
// glColor3f(1, 1, 0);
glVertex3f(-((s / 2.0f)), ((s / 2.0f)),
((s / 2.0f))); //5
glTexCoord2f(0.0f, (2.0f / 3.0f));
// glColor3f(1, 0, 1);
glVertex3f(-((s / 2.0f)), -((s / 2.0f)),
((s / 2.0f))); //6
glTexCoord2f(0.25f, (2.0f / 3.0f));
// glColor3f(1, 1, 1);
glVertex3f(-((s / 2.0f)), -((s / 2.0f)),
-((s / 2.0f))); //3
}
//right
{
glTexCoord2f(0.75f, (1.0f / 3.0f));
// glColor3f(1, 0, 0);
glVertex3f(((s / 2.0f)), ((s / 2.0f)),
((s / 2.0f))); //7
glTexCoord2f(0.5f, (1.0f / 3.0f));
// glColor3f(1, 1, 0);
glVertex3f(((s / 2.0f)), ((s / 2.0f)),
-((s / 2.0f))); //1
glTexCoord2f(0.5f, (2.0f / 3.0f));
// glColor3f(1, 0, 1);
glVertex3f(((s / 2.0f)), -((s / 2.0f)),
-((s / 2.0f))); //4
glTexCoord2f(0.75f, (2.0f / 3.0f));
// glColor3f(1, 1, 1);
glVertex3f(((s / 2.0f)), -((s / 2.0f)),
((s / 2.0f))); //8
}
//back
{
glTexCoord2f(1.0f, (1.0f / 3.0f));
// glColor3f(1, 0, 0);
glVertex3f(-((s / 2.0f)), ((s / 2.0f)),
((s / 2.0f))); //5
glTexCoord2f(0.75f, (1.0f / 3.0f));
// glColor3f(1, 1, 0);
glVertex3f(((s / 2.0f)), ((s / 2.0f)),
((s / 2.0f))); //7
glTexCoord2f(0.75f, (2.0f / 3.0f));
// glColor3f(1, 0, 1);
glVertex3f(((s / 2.0f)), -((s / 2.0f)),
((s / 2.0f))); //8
glTexCoord2f(1.0f, (2.0f / 3.0f));
// glColor3f(1, 1, 1);
glVertex3f(-((s / 2.0f)), -((s / 2.0f)),
((s / 2.0f))); //6
}
//top
{
glTexCoord2f(.5f, 1.0f);
// glColor3f(1, 0, 0);
glVertex3f(((s / 2.0f)), -((s / 2.0f)),
((s / 2.0f))); //7
glTexCoord2f(0.25f, 1.0f);
// glColor3f(1, 1, 0);
glVertex3f(-((s / 2.0f)), -((s / 2.0f)),
((s / 2.0f))); //5
glTexCoord2f(0.25f, (2.0f / 3.0f));
// glColor3f(1, 0, 1);
glVertex3f(-((s / 2.0f)), -((s / 2.0f)),
-((s / 2.0f))); //2
glTexCoord2f(.5f, (2.0f / 3.0f));
// glColor3f(1, 1, 1);
glVertex3f(((s / 2.0f)), -((s / 2.0f)),
-((s / 2.0f))); //1
}
//bottom
{
glTexCoord2f(.5f, (1.0f / 3.0f));
// glColor3f(1, 0, 0);
glVertex3f(((s / 2.0f)), ((s / 2.0f)),
-((s / 2.0f))); //4
glTexCoord2f(0.25f, (1.0f / 3.0f));
// glColor3f(1, 1, 0);
glVertex3f(-((s / 2.0f)), ((s / 2.0f)),
-((s / 2.0f))); //3
glTexCoord2f(0.25f, 0.0f);
// glColor3f(1, 0, 1);
glVertex3f(-((s / 2.0f)), ((s / 2.0f)),
((s / 2.0f))); //6
glTexCoord2f(.5f, 0.0f);
// glColor3f(1, 1, 1);
glVertex3f(((s / 2.0f)), ((s / 2.0f)),
((s / 2.0f))); //8
}
}
glEnd();
}
glPopMatrix();
glDisable(GL_TEXTURE_2D);
}
glPopMatrix();
}
glEndList();
这是设置 camara 的代码:
float near_ = 1f;
float far_ = 10.0f;
float halfHeight = near_ * (Radian(m_fov)) / 2.0f;
float halfWidth = (static_cast<float>((m_width)) / static_cast<float>((m_height))) * halfHeight;
glViewport(0, 0, m_width, m_height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-halfWidth, halfWidth, -halfHeight, halfHeight, near_, far_);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
这是呈现到屏幕的代码:
void VideoStreamer::render()
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
float pitch = clamp(Degree(m_pitch), Degree(-(80.f)), Degree(80.f));
float yaw = wrap(m_yaw, Degree(0), Degree(360));
float roll = wrap(m_roll, Degree(0), Degree(360));
glPushMatrix();
{
glLineWidth(5);
glPushMatrix();
{
if (1)
{
glRotatef(pitch, 1.0, 0.0, 0.0);
glRotatef(yaw, 0.0, 1.0, 0.0);
glRotatef(roll, 0.0, 0.0, 1.0);
}
glCallList((m_cube));
}
glPopMatrix();
}
glPopMatrix();
SDL_GL_SwapBuffers();
}//end render
这是正在发生的事情的屏幕截图,请注意蓝色和黑色四边形之间的白线:
这是我正在使用的纹理,分辨率为 600x450,但线条以多种分辨率出现:
我的问题是:我如何摆脱那条白线?
编辑:白线只出现在顶部和底部与左右相交的地方
编辑:更新代码以反映建议