0
votes

I've been trying to resolve this issue I have been having with displaying a texture correctly on my libgdx desktop program.

I have an Orthographic camera with which when I set as:

camera.setOrtho(false);

I get this image: enter image description here

And when I set it as:

camera.setOrtho(true);

I get this image: enter image description here

The red image is drawn with a SpriteBatch:

batch.draw(texture, x, y, width, height);

While the white image is drawn from individual points plotted based on if their alpha value was 1.

TextureData td = texture.getTextureData();
td.prepare;
Pixmap map = td.consumePixmap();
for (int i = 0; i < map.getWidth(); i++)
            for (int j = 0; j < map.getHeight(); j++)
                if (new Color(map.getPixel(i, j)).a == 1)
                    points.add(new Point(i, j));

Above is the code used to get all the non-transparent pixels. They are displayed as the white image, and seem to be the inverse of the original texture.

However, the points plotted and the image itself is always an inverse of one another.

Is there any way of resolving this issue?

Thank you.

PS: I've tried multiple ways of trying to fix this:

  • Using Sprites and flipping them
  • Using TextureRegions and flipping them

Absolutely nothing seems to work.

1
What does the setOrtho method do?BDL
make sure to read this github.com/libgdx/libgdx/wiki/Coordinate-systems especially the part about pixmaps.Xoppa
Nothing I do seems to make this work. All I want it to do is to know what the color of the point on the screen at which I click is and it seems literally unfeasible.Orange Receptacle

1 Answers

0
votes

Yes this is very anoying, Libgdx is not consistent with it's coordinate system. Like font.draw() draws from top downward. Alter the way you iterate over you draw/plot inside your loop, basically you have to flip it manually. So when j == 0 then y would become the highest value and if j == map.getHeight y would become the lowest value. Then interpolate linearly within these values. If you shown whats inside your loop I could help out a bit more.