Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (496)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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  
  Terrain texture glitching?  (Read 525 times)
0 Members and 1 Guest are viewing this topic.
Offline professorx

Junior Newbie





« Posted 2012-06-08 19:10:29 »

I am using Ardor3D for a game. I made a simple array terrain data provider (creates terrain out of a float array). Then, I used an awtexturesource (provides texture for the terrain) and added a white rectangle that fills the whole terrain. At certain angles, though, it looks like :


What are the random black areas??? What am I doing wrong?

Code: (ExampleBase is a simple base for games that calls initExample() then repeatedly calls updateExample() in a loop)


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  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
public class Level extends ExampleBase {

   Node _level=new Node("Level Root");
   private final float farPlane = 8000.0f;
   private Terrain terrain;
   
   final int SIZE = 2048;
   PointLight pl=new PointLight();
   
   
   private double counter = 0;
    private int frames = 0;

   public void updateExample(ReadOnlyTimer t){
      counter += t.getTimePerFrame();
        frames++;
        if (counter > 1) {
            final double fps = frames / counter;
            counter = 0;
            frames = 0;
            System.out.printf("%7.1f FPS\n", fps);
        }
      pl.setLocation(_canvas.getCanvasRenderer().getCamera().getLocation());
   }
   
   
   @Override
   protected void initExample() {
      _canvas.setTitle("Terrain Example");
        _canvas.getCanvasRenderer().getCamera().setLocation(new Vector3(0, 10, 0));
        _canvas.getCanvasRenderer().getCamera().lookAt(new Vector3(1, -300, 1), Vector3.UNIT_Y);
        _canvas.getCanvasRenderer().getCamera().setFrustumPerspective(
                70.0,
                (float) _canvas.getCanvasRenderer().getCamera().getWidth()
                        / _canvas.getCanvasRenderer().getCamera().getHeight(), 1.0f, farPlane);
        _canvas.getCanvasRenderer().getRenderer().setBackgroundColor(ColorRGBA.CYAN);
        _controlHandle.setMoveSpeed(300);
      setupDefaultStates();
     
      AwtTextureSource awt = new AwtTextureSource(8, TextureStoreFormat.RGBA8);
     
      try {
           
         final int SIZE = 2048;

            float[] heightMap=new float[SIZE*SIZE];
            for(int i=0;i<heightMap.length;i++)heightMap[i]=0f;
           
     

            final TerrainDataProvider terrainDataProvider = new ArrayTerrainDataProvider(heightMap, SIZE, new Vector3(1, 300, 1));

            TerrainBuilder b=new TerrainBuilder(terrainDataProvider, _canvas.getCanvasRenderer().getCamera());
            b.addTextureConnection(awt);
           
            terrain = b.setShowDebugPanels(true).build();

           
            terrain.getTextureClipmap().setShowDebug(false);
            terrain.reloadShader();
           
            _level.attachChild(terrain);
        } catch (final Exception ex1) {
            System.out.println("Problem setting up terrain...");
            ex1.printStackTrace();
        }
     

        AwtShapeElement rectangle = new AwtShapeElement(new Rectangle(2048, 2048));
        Transform t = new Transform();
        rectangle.setTransform(t);
        awt.getProvider().addElement(rectangle);
     
      _root.attachChild(_level);
     
   }
   //copied from ArrayTerrainExample
  private void setupDefaultStates() {
        _lightState.detachAll();
        final DirectionalLight dLight = new DirectionalLight();
        dLight.setEnabled(true);
        dLight.setAmbient(new ColorRGBA(0.4f, 0.4f, 0.5f, 1));
        dLight.setDiffuse(new ColorRGBA(0.6f, 0.6f, 0.5f, 1));
        dLight.setSpecular(new ColorRGBA(0.3f, 0.3f, 0.2f, 1));
        dLight.setDirection(new Vector3(-1, -1, -1).normalizeLocal());
       
        pl.setAmbient(new ColorRGBA(0.4f, 0.4f, 0.5f, 1));
        pl.setDiffuse(new ColorRGBA(0.6f, 0.6f, 0.5f, 1));
        pl.setSpecular(new ColorRGBA(0.3f, 0.3f, 0.2f, 1));
        pl.setAttenuate(false);
        _lightState.attach(pl);
        _lightState.attach(dLight);

        _lightState.setEnabled(true);

        final CullState cs = new CullState();
        cs.setEnabled(true);
        cs.setCullFace(CullState.Face.Back);
        _root.setRenderState(cs);

        final FogState fs = new FogState();
        fs.setStart(farPlane / 2.0f);
        fs.setEnd(farPlane);
        fs.setColor(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
        fs.setDensityFunction(DensityFunction.Linear);
        _root.setRenderState(fs);
    }

   /**
    * @param args
    */

   public static void main(String[] args) {
      start(Level.class);

   }

}
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

BurntPizza (14 views)
2014-09-19 03:14:18

Dwinin (32 views)
2014-09-12 09:08:26

Norakomi (58 views)
2014-09-10 13:57:51

TehJavaDev (80 views)
2014-09-10 06:39:09

Tekkerue (40 views)
2014-09-09 02:24:56

mitcheeb (62 views)
2014-09-08 06:06:29

BurntPizza (46 views)
2014-09-07 01:13:42

Longarmx (33 views)
2014-09-07 01:12:14

Longarmx (37 views)
2014-09-07 01:11:22

Longarmx (36 views)
2014-09-07 01:10:19
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!