PDA

View Full Version : Cube from QUADS+Textures+Linear filtering=problem



James Huk
05-15-2010, 12:05 PM
Hello everyone.

I want to use interior of the cube (made from QUADS) to display textured "horizon". Well as long as I use GL_NEAREST filtering, everything looks OK:

http://img215.imageshack.us/img215/8210/goodk.png

However, if I try GL_LINEAR filtering I can see lines on edges of the cube:

http://img80.imageshack.us/img80/7668/badx.png

Of course, I want to use linear filtering because of much better quality - but I don't know how to get rid of this annoying lines. I already tried setting:


glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_R,GL _CLAMP)

But it didn't help (or maybe I didn't set it correctly...?). Please help.

Here is the code I use to draw a cube (I use QT-4.6 framework with Debian Stable):


void testGL::colorCubeQuad5(GLfloat size)
{
if(size<=0)
{
std::cerr << "Wrong size for colorcube!";
return;
}

GLfloat half=size/2.0;

//dol
glBindTexture(GL_TEXTURE_2D,textures[1]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_R,GL _CLAMP);
glBegin(GL_QUADS);
{
glColor3f(1.0f,1.0f,1.0f);//Red

glTexCoord2f(1.0f,0.0f);
glVertex3f(half,-half,half);

glTexCoord2f(1.0f,-1.0f);
glVertex3f(half,-half,-half);

glTexCoord2f(0.0f,-1.0f);
glVertex3f(-half,-half,-half);

glTexCoord2f(0.0f,0.0f);
glVertex3f(-half,-half,half);
}glEnd();

//gora
glBindTexture(GL_TEXTURE_2D, textures[4]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_R,GL _CLAMP);

glBegin(GL_QUADS);
{
glColor3f(1.0f,1.0f,1.0f);//Red

glTexCoord2f(1.0f,0.0f);
glVertex3f(-half,half,half);

glTexCoord2f(1.0f,-1.0f);
glVertex3f(-half,half,-half);

glTexCoord2f(0.0f,-1.0f);
glVertex3f(half,half,-half);

glTexCoord2f(0.0f,0.0f);
glVertex3f(half,half,half);
}glEnd();

//przod
glBindTexture(GL_TEXTURE_2D, textures[5]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_R,GL _CLAMP);
glBegin(GL_QUADS);
{
glColor3f(1.0f,1.0f,1.0f);//Red

glTexCoord2f(1.0f,0.0f);
glVertex3f(-half,-half,half);

glTexCoord2f(1.0f,-1.0f);
glVertex3f(-half,half,half);

glTexCoord2f(0.0f,-1.0f);
glVertex3f(half,half,half);

glTexCoord2f(0.0f,0.0f);
glVertex3f(half,-half,half);
}glEnd();

//tyl
glBindTexture(GL_TEXTURE_2D, textures[2]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_R,GL _CLAMP);
glBegin(GL_QUADS);
{
glColor3f(1.0f,1.0f,1.0f);//Red

glTexCoord2f(0.0f,0.0f);
glVertex3f(half,-half,-half);

glTexCoord2f(0.0f,-1.0f);
glVertex3f(half,half,-half);

glTexCoord2f(-1.0f,-1.0f);
glVertex3f(-half,half,-half);

glTexCoord2f(-1.0f,0.0f);
glVertex3f(-half,-half,-half);
}glEnd();

//lewa
glBindTexture(GL_TEXTURE_2D, textures[3]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_R,GL _CLAMP);
glBegin(GL_QUADS);
{
glColor3f(1.0f,1.0f,1.0f);//Red

glTexCoord2f(0.0f,0.0f);
glVertex3f(-half,-half,-half);

glTexCoord2f(0.0f,-1.0f);
glVertex3f(-half,half,-half);

glTexCoord2f(-1.0f,-1.0f);
glVertex3f(-half,half,half);

glTexCoord2f(-1.0f,0.0f);
glVertex3f(-half,-half,half);
}glEnd();

//prawa
glBindTexture(GL_TEXTURE_2D, textures[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_R,GL _CLAMP);
glBegin(GL_QUADS);
{
glColor3f(1.0f,1.0f,1.0f);//Red

glTexCoord2f(0.0f,0.0f);
glVertex3f(half,-half,half);

glTexCoord2f(0.0f,-1.0f);
glVertex3f(half,half,half);

glTexCoord2f(-1.0f,-1.0f);
glVertex3f(half,half,-half);

glTexCoord2f(-1.0f,0.0f);
glVertex3f(half,-half,-half);
}glEnd();
}

Thanks in advance.

GregoryM
06-24-2010, 08:48 AM
I have been stuck with the same problem not long ago.
The solution is to add the following lines:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

More information is here: http://books.google.com/books?id=H4eYq7-...lem&amp;f=false (http://books.google.com/books?id=H4eYq7-2YhYC&amp;pg=PA75&amp;lpg=PA75&amp;dq=GL_LINEAR+filtering+prob lem&amp;source=bl&amp;ots=q9-HoSV-P2&amp;sig=y18fHoyA6SpcuzOYci3-U1L3f20&amp;hl=en&amp;ei=y2wjTNDCAc-lOOqr_KEF&amp;sa=X&amp;oi=book_result&amp;ct=result&amp;resnum=7&amp;v ed=0CDUQ6AEwBg#v=onepage&amp;q=GL_LINEAR%20filtering%2 0problem&amp;f=false)