0

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();
}
5
  • Can you please add a bit of your rendering code to help us better understand what you are doing?
    – Seamus
    Apr 5, 2015 at 3:05
  • Yes! Sure I can. Let me take second, I will make a little code.
    – Tony Shor
    Apr 5, 2015 at 8:41
  • What texture filters are you using, and what wrap modes? You probably want GL_CLAMP_TO_EDGE to prevent the wrapover at the border.
    – derhass
    Apr 5, 2015 at 17:08
  • Sorry, I don't understand all of this as I am a little bit NOOB with OpenGL. I don't know where to use this "GL_CLAMP_TO_EDGE" and I know nothing about wrappers. Luckly, I've found a way, In few hours I'm gonna post it here. But, that way is stupid. If you could show me where to use that thing that you propose... it would be nice.
    – Tony Shor
    Apr 6, 2015 at 10:57
  • As I was blocked on this site for a real bad answers, SO, Before I leave. If someone has similar trouble -- my "real bad answer" for a related question may help you. Try it Out: stackoverflow.com/questions/14781617/…
    – Tony Shor
    Apr 6, 2015 at 14:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.