I am working on building a box that the user looks from the inside out, a sky box or some thing of the sort. I am doing this by taking 6 quads and creating a cube with them and then putting the theoretical camera inside the cube and texturing the cube with an image. The user can look around by using the mouse and the cube rotates making as seem that one is moving their head. i have run in to a problem with a white line appearing at the intersections of the two sides, I have tried pulling in the quads while keeping the size of the actual quads the same. i have made sure that the clear color was black and I am still getting the white line.
Here are the attributes I set:
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);
Here is the code that creates the cube:
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();
Here is the code that sets up the 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();
Here is the code that renders to the screen:
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
And here is a screen shot of what is happening, notice the white line between the blue and black quads:

Here is the texture I am using, resolution 600x450, but line happens at multiple resolutions:

My question is: How do I get rid of that white line?
EDIT: The white lines are only appearing where the top and bottom meet the left and right
EDIT: Updated Code to reflect suggestions
What you're seeing is simply that you indeed have white in your texture. So the fragments that are on the border of the face end up fetching from the white part (you'll see that more clearly if you turn a linear filter type on your texture).
What you can do to fix it:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With