PDA

View Full Version : a question about texture mapping



qiongyu_wu
11-23-2004, 09:32 PM
I want to render two neighor planes be joined on one border.Both planes are textured using texture mapping with the same parameter. when the code is excuted,there is a black line on the joined border between the textured planes.

my question is :how to eliminate the black line.

my code is :

glGenTextures(2,texture_objects);

glBindTexture(GL_TEXTURE_2D, texture_objects[0]);

glTexImage2D(GL_TEXTURE_2D,0,3,widthleft,heightlef t,0,GL_BGR_EXT,GL_UNSIGNED_BYTE,BitmapBitsLeft);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL _CLAMP);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL _CLAMP);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR );
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR );
//glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE GL_DECAL);

glBindTexture(GL_TEXTURE_2D, texture_objects[1] );
glTexImage2D(GL_TEXTURE_2D,0,3,widthback,heightbac k,0,GL_BGR_EXT,GL_UNSIGNED_BYTE,BitmapBitsBack);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL _CLAMP);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL _CLAMP);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR );
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR );

glBindTexture(GL_TEXTURE_2D, texture_objects[0]);
glBegin(GL_POLYGON);
glTexCoord2f(0,0);
glVertex3f(m_vertices[5].x,m_vertices[5].y,m_vertices[5].z);
glTexCoord2f(0,1);
glVertex3f(m_vertices[11].x,m_vertices[11].y,m_vertices[11].z);
glTexCoord2f(1,1);
glVertex3f(m_vertices[7].x,m_vertices[7].y,m_vertices[7].z);
glTexCoord2f(1,0);
glVertex3i(m_vertices[1].x,m_vertices[1].y,m_vertices[1].z);
glEnd( );


glBindTexture(GL_TEXTURE_2D, texture_objects[1] );
glBegin(GL_POLYGON);
glTexCoord2f(0,0);
glVertex3f(m_vertices[2].x,m_vertices[2].y,m_vertices[2].z);
glTexCoord2f(1,0);
glVertex3f(m_vertices[1].x,m_vertices[1].y,m_vertices[1].z);
glTexCoord2f(1,1);
glVertex3f(m_vertices[7].x,m_vertices[7].y,m_vertices[7].z);
glTexCoord2f(0,1);
glVertex3f(m_vertices[8].x,m_vertices[8].y,m_vertices[8].z);
glEnd( );


glDeleteTextures(2,texture_objects);

Relic
11-24-2004, 12:47 AM
linear filtering with GL_CLAMP will filter the texture border color in your case. The texture border color is black per default.
If you don't want the texture border color to be sampled change all GL_CLAMP to GL_CLAMP_TO_EDGE.
If you want perfect blending you need to add real texture borders of the adjacent texture edges around your textures and leave the wrap modes on GL_CLAMP.
Some older hardware doesn't support texture borders.

qiongyu_wu
11-25-2004, 03:28 AM
when I change 'GL_CLAMP' to "GL_CLAMP_TO_EDGE', a error occurs:

error C2065: 'GL_CLAMP_TO_EDGE' : undeclared identifier.

What can i do to make my computer to support textured borders?

WyZ
11-25-2004, 04:31 AM
Hi,

You could use Intel's GLsdk (http://oss.sgi.com/projects/ogl-sample/GLsdk.zip) to include all OpenGL function entry points not present in the header provided by Microsoft, along with the new defines.

I hope it helps.

Relic
11-25-2004, 05:33 AM
Originally posted by qiongyu_wu:
when I change 'GL_CLAMP' to "GL_CLAMP_TO_EDGE', a error occurs:

error C2065: 'GL_CLAMP_TO_EDGE' : undeclared identifier.

What can i do to make my computer to support textured borders?The error means you don't have the GLenum in one of your included GL headers, either gl.h or glext.h. You can find the correct enum in those files at the link http://oss.sgi.com/projects/ogl-sample/registry/

Anyway it's
#define GL_CLAMP_TO_EDGE 0x812F

That doesn't mean your OpenGL implementation will accept it. Check the glGetError before and after the glTexParameter call using it. If it's not GL_NO_ERROR your stuck in that. Your could revert to GL_NEAREST filtering which doesn't leave the texture.

Texture borders are given with the border parameter in the glTexImage call.
You had 0 there, make it a 1 and send textures which are width + 2, height + 2. That is a 64*64 texture becomes a 66*66 image. Beware of the glPixelStore unpack alignment in case your texture is RGB!
You need to prepare the texture to contain the adjacent data yourself either in a paint program or at runtime in your app. It's just some memory copying.

To know if your hardware supports texture borders you should first look at what implementation you are using.
Check the strings returned by glGetString(GL_VENDOR) and glGetString(GL_RENDERER).
If it say Microsoft, you're not running in hardware anyway.
If not, give it a try and if it's fast it's running in hardware, or ignored it. ;)
Print what you got here and you might get an answer.

def
11-27-2004, 02:31 AM
If you change GL_CLAMP to GL_REPEAT you'll at least get rid of the black color, the color from the opposite side of the texture will be filtered in.
Without GL_CLAMP_TO_EDGE available you could use just one mesh with either multitexturing or one combined texture instead of two planes, that would give you the cleanest edge.

if "glGetString(GL_VERSION)" returns 1.2 or higher you should have access to GL_CLAMP_TO_EDGE. (up to date hardware should support 1.5)

jwatte
11-27-2004, 02:04 PM
The right thing to do is to use GL_CLAMP and put the edge texels of the neighboring texel into the texture border of the current texture.

qiongyu_wu
11-30-2004, 10:12 PM
Thanks all of you.

I download GLsdk and use opengl1.3.1.,add a border to the textures,then the black lines disappears!!!!