White lines(or spaces) shows up on the borders of the Textures as I move camera. Java, OpenGL

被刻印的时光 ゝ 提交于 2020-01-11 07:39:07

问题


Textures are drawn incorrectly. As I see, Program changes the top line of pixels with the bottom line. And it changes the left column with the right one. If Texture is empty, let's say, on the top, but there are black pixels on the bottom -- when you "move camera" Up or Down you'll see that bottom line becomes empty, and top line becomes black from time to time. So it changes columns as you're moving Left or Right as well. To escape this, I've tried to erase all of the pixels on the borders and move textures closer one to another for few pixels, to "glue them up" somehow. But the effect was half good. Fixed one -- another showd up. For some reasons It draws a white, or close to white, lines between the textures. I've tried to fix this too and move textures even closer. So far, they are laying one on the other, but this effect is still visible.

Sure, I've checked the StackOverflow and the only one possible question stays without the answer for a long long time. Opaque OpenGL textures have transparent border It seems to be similar and have related roots.

http://oi57.tinypic.com/k4jtkl.jpg -- regular

http://oi57.tinypic.com/mkkuo0.jpg -- with white spaces

Here's the code of small program that makes the same mistake:

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);
     }
     }

Now Methods:

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

and

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();
}

来源:https://stackoverflow.com/questions/29442115/white-linesor-spaces-shows-up-on-the-borders-of-the-textures-as-i-move-camera

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!