[SOLVED] LibGDX - Window contents overstrech upon resizing

Hi everybody!
I’m new to libgdx and to this great forum so please don’t hurt me if I do something stupid…

Anyway, I’m making a logic circuit simulator for desktop and mostly Android, and I ran into a problem which didn’t see anywhere on the Internet:

Here’s the program with it’s default size:

http://kepfeltoltes.hu/130915/Logick-01_www.kepfeltoltes.hu_.png

This is how it should look at all times.

And this is how it looks if I make the window smaller:

http://kepfeltoltes.hu/130915/Logick-02_www.kepfeltoltes.hu_.png

The UI should adjust to the new size, but it shrinks too much. The controls work OK (a click in the blackness in the bottom right corner toggles the options panel).

If the program starts with a different default value, it looks well only on that size.

I searched the Internet about this, but nothing came up ( or I’m just too blind :stuck_out_tongue: ).

I know it’s a stupid problem that I should be able to solve, but as I stated, I’m new to libGDX.

Oh, and the problem probably has to do something with the fact that I don’t use cameras.

Any help would be awesome and thanks in advance!
Btw: This forum ROCKS!!

Do you have something in your method resize code? post it?

Maybe you need to readjust your camera or something else, whenever the screen resizes?

Are you defining based upon a fixed value, or Gdx.getGraphics.getWidth()/.getHeight() ?

[quote]I’m new to libgdx and to this great forum so please don’t hurt me if I do something stupid…
[/quote]
Muhahahaha

Wow, that was quick!

My resize method is currently empty, and there are no cameras to readjust(or is there a default camera?). The sprites’ positions are defined using getWidth() and getHeight().

If you can click in black space to have the button respond, it probably has more to do with how you’re rendering the diagram…post a snippet maybe?

Yes sir. May we see some of the init code ?
Im no opengl expert, but its clearly a viewport issue.

I don’t know about libGdx but here’s how to change the viewport in LWJGL. You can find a similar mechanism in libGdx.


public void resized()
{
    glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
}

This sets the viewport to the window space completely stretching the bounds you specify in the Orthographic Camera.


	public void init() {
		font = new BitmapFont(Gdx.files.internal("gfx/font.fnt"), false);
		font.setColor(0.9254902F, 0.9254902F, 0.9254902F, 1);
		
		inactive = new Texture(Gdx.files.internal("gfx/CABLE-OFF.png"));
		scrollUp = new Texture(Gdx.files.internal("gfx/UP.png"));
		scrollDown = new Texture(Gdx.files.internal("gfx/DOWN.png"));

		bgtex = new Texture(Gdx.files.internal("gfx/UIBG.png"));
		bgsel = new Texture(Gdx.files.internal("gfx/UISEL.png"));
		
		left[0] = new Texture(Gdx.files.internal("gfx/NOT.png"));
		left[1] = new Texture(Gdx.files.internal("gfx/AND.png"));
		left[2] = new Texture(Gdx.files.internal("gfx/OR.png"));
		left[3] = new Texture(Gdx.files.internal("gfx/XOR.png"));
		left[4] = new Texture(Gdx.files.internal("gfx/SWITCH-OFF.png"));
		left[5] = new Texture(Gdx.files.internal("gfx/LIGHT-OFF.png"));
		
		right[0] = new Texture(Gdx.files.internal("gfx/UIOPT.png"));
		right[1] = new Texture(Gdx.files.internal("gfx/SWITCH-ON.png"));
		
		options[0] = new Texture(Gdx.files.internal("gfx/UNDO.png"));
		options[1] = new Texture(Gdx.files.internal("gfx/SAVE.png"));
		options[2] = new Texture(Gdx.files.internal("gfx/LOAD.png"));

		sb = new SpriteBatch();
	}

I found

 Gdx.gl20.glViewport(0, 0, width, height); 

, but it didn’t do a thing.
Thanks anyways!


public void render() {
	sb.begin();
	sb.draw(bgtex, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
	//Draw rest of the UI
	sb.end();
}

Try making an orthographic camera. There is a wiki page here. https://code.google.com/p/libgdx/wiki/OrthographicCamera

Ok, i’ll give that a try. Thanks for the link!

EDIT:


cam.setToOrtho(false, width, height);

WORKED LIKE A CHARM!! THANK YOU EVERYBODY!! ;D

Instead of initialzing that many textures, use a TextureAtlas or (if left is supposed to be an animation) Animation.