LibGDX error : Camera setup

I’m trying to write a simple app which demonstrates how my packed fonts can be rendered in LibGDX. I asked it to render at (0, 0) and it starts rendering at bottom-down corner. I’ve wanted it at up-left corner so from the wiki, I used the following in the [icode]create()[/icode] method.


cam = new OrthographicCamera();
cam.setToOrtho(true, 800, 600);

But it still renders in the bottom-left corner. What should I do?

I’m rendering the texture like this. Does it matter?


batch.begin();
{
    batch.draw(tex, x, y);
}
batch.end();

I never use setToOrtho method, just pass those value to constructor.

Btw I don’t really clear the problem. So you want to move the origin back to Java2D (up-left)?

@Rebirth

Yes. I just want to go to Java2D origin.

I never do this. I just recalculate the Y with height subtraction since it’s safer to do that.

My idea:

  1. translate camera x,y
  2. use negative value for height (???)

Could you give me some clarity? An example? I don’t understand.

I just want to draw a texture on top of the screen. And leave others at the default position.

Have you added:


batch.setProjectionMatrix(cam.combined);
batch.begin();
...

?

@drabla

Adding that made the characters upside down.

I am not on Eclipse right now,


cam = new OrthographicCamera(800, -600, true);

Dunno what will happen though ::slight_smile:

@Rebirth,

The same. No change at all. I’ve also tried calling the update and apply methods. But no use.

After changing your camera, like this:

You need to change your batch’s projection matrix:
[icode]batch.setProjectionMatrix(camera.combined);
… render sprites …[/icode]

and yes the characters will be upside down.
if you use ydown you have to flip your textures as well

@Cero

Can you say how to flip them?

sprite.flip(false, true);

or do it in your graphical program.

I can’t create a new sprite for each texture. Can we directly flip the texture?

Don’t flip texture; that would involve re-arranging byte data. Instead, flip the texture region that encapsulates your texture. You should learn about textures and texture regions here:

Generally speaking you shouldn’t be using Texture except for low-level purposes, or to hold a single texture atlas. Instead it is better to use Sprite (which caches vertex data) or TextureRegion.

If you are loading your Sprites through a TextureAtlas: // (this is good practice right? :wink: )

TextureAtlas atlas = new TextureAtlas(Gdx.files.internal(“data/pack.pack”), true);

The last boolean will flip the y in your whole textureatlas. C.f.: http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g2d/TextureAtlas.html#TextureAtlas(com.badlogic.gdx.files.FileHandle, boolean)