当我移动相机时,白色线条(或空格)显示在纹理的边框上。 Java,OpenGL

时间:2015-04-04 02:35:15

标签: java opengl textures

纹理拼写错误。 正如我所见,程序用底线改变像素的顶行。它用右边的列改变左列。 如果纹理是空的,让我们说,在顶部,但底部有黑色像素 - 当你“向上或向下移动相机”时,你会看到底线变空,顶线不时变为黑色。因此,当您向左或向右移动时,它会更改列。 为了避免这种情况,我试图擦除边框上的所有像素,并将纹理彼此移近几个像素,以某种方式“粘合它们”。但效果还不错。修正了一个 - 另一个出现了。 由于某些原因,它在纹理之间绘制了白色或接近白色的线条。我也试图解决这个问题,让纹理更接近。到目前为止,他们正在铺设另一个,但这种效果仍然可见。

当然,我已经检查了StackOverflow,并且唯一可能的问题在很长一段时间内没有答案。 Opaque OpenGL textures have transparent border 它似乎是相似的,并且有相关的根源。

http://oi57.tinypic.com/k4jtkl.jpg - 定期

http://oi57.tinypic.com/mkkuo0.jpg - 带有空格

以下是造成同样错误的小程序代码:

public class WorkWrong
{
public static void main(String[] args)
{
    //creating a Display
    int wX=650,wY=650;
    try
    {
        Display.setDisplayMode(new DisplayMode(wX, wY));
        Display.setTitle("Useelees");
        Display.setResizable(false);
        Display.create();
    }
    catch(LWJGLException e)
    {
        e.printStackTrace();
        System.exit(0);
    }

    //The Mystery of OpenGL... This code is not mine, and I've never 
    //changed anything here. I just don't know what is changable. 
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    GL11.glEnable(GL11.GL_BLEND); //Enables Blending
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glViewport(0, 0, wX, wY);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GL11.glOrtho(0, wX, wY, 0, -1, 1);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glRenderMode(0);

    //reading textures
    Texture[] texture = new Texture[5];
    texture[0]=PNGUP("0.png");
    texture[1]=PNGUP("1.png");
    texture[2]=PNGUP("2.png");
    texture[3]=PNGUP("3.png");

      while(true)
      {
        //Drawing a square of 4 pictures.
        SquareRender(texture[0],0,0,64,64);
        SquareRender(texture[1],0,64,64,128);
        SquareRender(texture[2],64,0,128,64);
        SquareRender(texture[3],64,64,128,128);

        if(Display.isCloseRequested())
        {
            AL.destroy();
            Display.destroy();
            System.exit(1);
        }

        Display.update();
        Display.sync(30);
     }
     }

现在方法:

private static Texture PNGUP(String n)
{
    try
    {
        TmpTex= TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream(n));
    }
    catch(IOException e)
    {
        e.printStackTrace();
    }
    return TmpTex;
}
static Texture TmpTex;

public static void SquareRender(Texture T,float x1,float y1,float x2,float y2)
{
    T.bind();
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glTexCoord2f(0, 0);
    GL11.glVertex2f(x1,y1);
    GL11.glTexCoord2f(1, 0);
    GL11.glVertex2f(x2,y1);
    GL11.glTexCoord2f(1, 1);
    GL11.glVertex2f(x2,y2);
    GL11.glTexCoord2f(0, 1);
    GL11.glVertex2f(x1,y2);
    GL11.glEnd();
}

0 个答案:

没有答案