Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (535)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [Libgdx] Problem with ImmediateModeRenderer20  (Read 455 times)
0 Members and 1 Guest are viewing this topic.
Offline hhfjkehfe

Senior Newbie





« Posted 2014-04-15 08:38:50 »

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?
Offline matheus23

JGO Kernel


Medals: 106
Projects: 3


You think about my Avatar right now!


« Reply #1 - Posted 2014-04-15 11:13:35 »

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:
  • SpriteBatch for rendering Textured, moving images
  • ShapeRenderer for rendering Shapes without textures (circles, lines, rectangles)
  • SpriteCache for rendering Textured, static images like scenery

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline hhfjkehfe

Senior Newbie





« Reply #2 - Posted 2014-04-15 11:43:37 »

Well I want to render the background which is 20MB and I want to use vertices.[20MB per level]
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline hhfjkehfe

Senior Newbie





« Reply #3 - Posted 2014-04-15 18:01:43 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
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.
Offline Gibbo3771
« Reply #4 - Posted 2014-04-15 18:04:41 »

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.

"This code works flawlessly first time and exactly how I wanted it"
Said no programmer ever
Offline hhfjkehfe

Senior Newbie





« Reply #5 - Posted 2014-04-15 18:51:49 »

Well the texture is 100 by 100 and the device is 1280x756 but I think that I place the vertices too close.
Pages: [1]
  ignore  |  Print  
 
 

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Riven (7 views)
2014-07-29 12:53:52

Dwinin (7 views)
2014-07-29 10:59:34

E.R. Fleming (23 views)
2014-07-29 03:07:13

E.R. Fleming (9 views)
2014-07-29 03:06:25

pw (39 views)
2014-07-24 01:59:36

Riven (39 views)
2014-07-23 21:16:32

Riven (26 views)
2014-07-23 21:07:15

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21

Zero Volt (51 views)
2014-07-17 23:47:54
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!