[Libgdx] Problem with ImmediateModeRenderer20

When I draw a polygon with ImmediateModeRenderer20 and on the next frame I draw it with an offset the polygon becomes noisy.How I can fix this?

  1. Please show some code, I don’t get what you’re doing ^^
  2. A screenshot can be really helpful for us to understand what you mean with “noisy”.

Also, ImmediateModeRenderer20 is deprecated. You shouldn’t use it. You should use one of the following:
[x] SpriteBatch for rendering Textured, moving images
[x] ShapeRenderer for rendering Shapes without textures (circles, lines, rectangles)
[x] SpriteCache for rendering Textured, static images like scenery

Well I want to render the background which is 20MB and I want to use vertices.[20MB per level]


public class LevelBackground {
	private ImmediateModeRenderer20 renderer;
	private Texture backgroundText;
	private Matrix4 projMatrix;
	private Body terrainBody;
	private ChainShape line;
	private BodyDef lineBodyDef;
	private ArrayList<Vector2> terrainVectors;
	private double dots[];
	private int speed;
	private Camera camera;

	

	public LevelBackground(String name,double dots[], World world,
			Camera camera,int speed) {
		this.camera = camera;
		this.speed = speed;
		this.dots = dots;
		projMatrix = new Matrix4();
		renderer = new ImmediateModeRenderer20( true, true, 1);
		backgroundText = new Texture(
				(Gdx.files.internal(name)),false);
		backgroundText.setFilter(TextureFilter.Linear, TextureFilter.Linear);
		line = new ChainShape();
		lineBodyDef = new BodyDef();
		terrainVectors = new ArrayList<Vector2>();
		lineBodyDef.position.set(0, 0);
		lineBodyDef.type = BodyType.StaticBody;
		// terrainBody = world.createBody(lineBodyDef);
		// for (int i = 0; i < floats.length; i++) {
		// terrainVectors.add(screenToPhysics(camera, new Vector2(
		// i * 100f - 50f, (float) ((floats[i]) / 2f) + 220f)));
		// }
		// line.createChain(terrainVectors.toArray(new Vector2[terrainVectors
		// .size()]));
		// for (int i = 0; i < terrainBody.getFixtureList().size; i++) {
		// terrainBody.getFixtureList().get(i).setFriction(1f);
		// }
		// terrainBody.createFixture(line, 1f);
	}

	public void render(float offset) {
		backgroundText.bind(GL20.GL_TEXTURE_2D);
		renderer.begin(projMatrix, GL20.GL_TRIANGLE_STRIP);
		Gdx.app.log("size", "" + dots.length);
		for (float i = 0; i < dots.length; i++) {
			renderer.texCoord((i%2),1f);
			renderer.color(1f, 1f, 1f, 1f);
			renderer.vertex(i / (float) (dots.length) * 2 - 1.5f - offset
					/ (float)speed, (float) ((dots[(int) (i)]) / 900f) - 0.8f, 1f);
			renderer.texCoord(0f, 0f);

			renderer.color(1f, 1f, 1f, 1f);
			renderer.vertex(i / (float) (dots.length) *2 - 1.5f - offset
					/ (float)speed, -1f, 1f);

		}
		renderer.end();
	}

	private Vector2 screenToPhysics(Camera camera, Vector2 screenPos) {
		Vector3 worldPos = new Vector3(screenPos.x, screenPos.y, 0);
		camera.unproject(worldPos);

		return new Vector2(worldPos.x, worldPos.y).scl(1f / 32f);
	}
}

The problem whith the noise is that the texture don`t move smooth through the screen but at fixed intervals .I use a very detailed texture and this step movement create the effect of noise.

That is not noise, well it kind of is. You are probably experiencing aliasing.

If your image is very detailed, say 5000x5000 and your screen is only 1920x1080. A lot of the 1 pixel thick details will be lost.

A way around it is texture filtering, using texture.setFilter();

If it is a very detailed image though, you can only do so much.

Well the texture is 100 by 100 and the device is 1280x756 but I think that I place the vertices too close.