   textured quad has extra stripe at edge (solution)
  I'm implimenting the old textured-quad tile game thingy. I have a texture with all of my tiles on it and I'm using texture coordinates to select the tile from the texture and render the tile to a quad. The problem is, depending on where I draw the tile or how I scale it, an extra stripe of an adjacent piece of the texture is included occasionally. The stripe is exactly 1 pixel wide regardless of how big I scale the tile. Is there any way to get a more precise clip of the texture?Here is the code I use to establish the texture: (note this is a C# binding)// bind to GL textureint[] texturename=new int[1];Gl.glGenTextures(1,texturename);Gl.glBindTexture(Gl.GL_TEXTURE_2D, texturename[0]);Gl.glTexParameteri(Gl.GL_TEXTURE_2D,Gl.GL_TEXTURE_MAG_FILTER,Gl.GL_NEAREST);Gl.glTexParameteri(Gl.GL_TEXTURE_2D,Gl.GL_TEXTURE_MIN_FILTER,Gl.GL_NEAREST);Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, 4, image_width, image_height, 0, Gl.GL_RGBA, Gl.GL_UNSIGNED_BYTE, pix_map);the rendering code:public void draw_sub_image(caves_image image, int sub_image_x,int sub_image_y,int sub_image_width,int sub_image_height,int world_x,int world_y,int world_width,int world_height){   float corner_x=(float)sub_image_x/(float)image.get_width();float corner_y=(float)sub_image_y/(float)image.get_width();float piece_w=(float)sub_image_width/(float)image.get_width();float piece_h=(float)sub_image_height/(float)image.get_width();Gl.glMatrixMode(Gl.GL_MODELVIEW);Gl.glPushMatrix();Gl.glLoadIdentity();Gl.glBindTexture(Gl.GL_TEXTURE_2D,image.get_gl_tex_num());Gl.glOrtho(0,screen_width,0,screen_height,-1,1);Gl.glTranslated(world_x,world_y,0);Gl.glBegin(Gl.GL_QUADS); Gl.glTexCoord2f(corner_x,corner_y+piece_h);// Texture coord (bottom left)(0,1)Gl.glVertex2i(0,0);// Vertex coord (Bottom left) (0,0)Gl.glTexCoord2f(corner_x+piece_w,corner_y+piece_h);// Texture coord (Bottom right)(1,1)Gl.glVertex2i(world_width,0);// Vertex coord (Bottom right)(1,0)Gl.glTexCoord2f(corner_x+piece_w,corner_y);// Texture coord (Top right)(1,0)Gl.glVertex2i(world_width,world_height);// Vertex coord (Top right) (1,1)Gl.glTexCoord2f(corner_x,corner_y);// Texture coord (Top left) (0,0)Gl.glVertex2i(0,world_height);// Vertex coord (Top left) (0,1)Gl.glEnd();Gl.glPopMatrix();}[Edited by - Kelly G on January 18, 2006 6:57:06 PM]
  You may either:Set texture wrapping mode to GL_CLAMP by calling glTexParameter () with both GL_TEXTURE_WRAP_S and GL_TEXTURE_WRAP_T set to GL_CLAMP.Set texture border to 1 instead of 0 in glTexImage2D () function.For more info you may take a look at MSDN - glTexParameter* () and glTexImage* () functions.;  You could try putting a border around the textures so that when it picks up the next texel it isn't quite as obvious.   ;  Skeleton_V@T: Thanks for the reply, friend, but these modifications don't seem to have any effect (except border of 1 is a huge performance hit for some reason). hmm.   ;  My solution: in case anyone is having the same problem some day and starts searching the forum, I'll put my solution here. I found this on google Using OpenGL with SDL (useful info)Quote:When using one texture to store multiple sprites, OpenGL smooth out my frames which tends to blend sprites together with a faint line at the edges    To turn off this image blending, so that it keeps it more pixel accurate, either include a gutter around the tiles (a technique that is used when using mip mapping), or do not use the transitioning/blending.    If you want a more pixel accurate render technique using OpenGL, try :  1. change the glTexParameter() from GL_LINEAR to GL_NEAREST  2. if you do not zoom in/out, do not use mipmaps  3. try to draw all quads with exactly the same dimensions as the corresponding tile  4. remember that integer coordinates are located in the center of pixels under orthonormal projection in OpenGL    One may begin by making sure one could draw a 2x2 single colored quad a certain pixel location (try at (0,0) and (638,478) if you are in 640x480 mode), then you would know if you got your "pixel correctness". Then it would be easy to extend to a whole tile/quad.In compliance with number 4, I shrunk my texture coordinate grabby box by one half pixel width on each side and that seems to work, for now. Thanks to those who replied.   ;  Thanks for posting the solution, I was having the same problem too. Funnily enough I was doing the same thing in my old DirectX engine for the sakes of getting rid of filtering artifacts.   ;  Try setting the WRAP modes to CLAMP_TO_EDGE instead of CLAMP - the former will sample the border color, whereas the latter will only sample the edge texels.  Note that some older cards treat CLAMP as CLAMP_TO_EDGE because they didnt support border color; apps written to depend on this behavior broke when newer cards supported the proper CLAMP behavior.Insetting the texture coords by 1/2 a texel will achieve the same result on the edges but may induce minification artifacts in the middle because you have shrunk the image.