opengl - Heightmap generation finishes halfway through -


currently, i'm trying make noise generated heightmap , display opengl. i'm following this tutorial, heightmap doesn't seem work. seems generates (or displays) half of supposed to.

this heightmap normals color: heightmap

as can see, though supposed square, appears rectangular unfinished edge.

this heightmap generation code:

public class heightmap extends gamemodel {      private static final float start_x = -0.5f;     private static final float start_z = -0.5f;      public heightmap(float miny, float maxy, float persistence, int width, int height) {         super(createmesh(miny, maxy, persistence, width, height));     }      protected static mesh createmesh(final float miny, final float maxy, final float persistence, final int width,             final int height) {         simplexnoise noise = new simplexnoise(128, persistence, 2);// utils.getrandom().nextint());          float xstep = math.abs(start_x * 2) / width;         float zstep = math.abs(start_z * 2) / height;          list<float> positions = new arraylist<>();         list<integer> indices = new arraylist<>();          (int x = 0; x < width; x++) {             (int z = 0; z < height; z++) {                 // scale [-0.5, 0.5] [miny, maxy]                 float heighty = (float) ((noise.getnoise(x, z) + 0.5f) * (maxy - miny) + miny);                  positions.add(start_x + x * xstep);                 positions.add(heighty);                 positions.add(start_z + z * zstep);                  // create indices                 if (x < width - 1 && z < height - 1) {                     int lefttop = z * width + x;                     int leftbottom = (z + 1) * width + x;                     int rightbottom = (z + 1) * width + x + 1;                     int righttop = z * width + x + 1;                      indices.add(lefttop);                     indices.add(leftbottom);                     indices.add(righttop);                      indices.add(righttop);                     indices.add(leftbottom);                     indices.add(rightbottom);                 }             }         }          float[] verticesarr = utils.listtoarray(positions);         float[] colorarr = new float[positions.size()];         (int = 0; < colorarr.length; += 3) {             colorarr[i] = (float) / colorarr.length;             colorarr[i + 1] = (float) .25f;             colorarr[i + 2] = (float) 0;         }         int[] indicesarr = indices.stream().maptoint((i) -> i).toarray();          float[] normalarr = calcnormals(verticesarr, width, height);          return new mesh(verticesarr, colorarr, normalarr, indicesarr);     }      private static float[] calcnormals(float[] posarr, int width, int height) {         vector3f v0 = new vector3f();         vector3f v1 = new vector3f();         vector3f v2 = new vector3f();         vector3f v3 = new vector3f();         vector3f v4 = new vector3f();         vector3f v12 = new vector3f();         vector3f v23 = new vector3f();         vector3f v34 = new vector3f();         vector3f v41 = new vector3f();         list<float> normals = new arraylist<>();         vector3f normal = new vector3f();         (int row = 0; row < height; row++) {             (int col = 0; col < width; col++) {                 if (row > 0 && row < height - 1 && col > 0 && col < width - 1) {                     int i0 = row * width * 3 + col * 3;                     v0.x = posarr[i0];                     v0.y = posarr[i0 + 1];                     v0.z = posarr[i0 + 2];                      int i1 = row * width * 3 + (col - 1) * 3;                     v1.x = posarr[i1];                     v1.y = posarr[i1 + 1];                     v1.z = posarr[i1 + 2];                     v1 = v1.sub(v0);                      int i2 = (row + 1) * width * 3 + col * 3;                     v2.x = posarr[i2];                     v2.y = posarr[i2 + 1];                     v2.z = posarr[i2 + 2];                     v2 = v2.sub(v0);                      int i3 = (row) * width * 3 + (col + 1) * 3;                     v3.x = posarr[i3];                     v3.y = posarr[i3 + 1];                     v3.z = posarr[i3 + 2];                     v3 = v3.sub(v0);                      int i4 = (row - 1) * width * 3 + col * 3;                     v4.x = posarr[i4];                     v4.y = posarr[i4 + 1];                     v4.z = posarr[i4 + 2];                     v4 = v4.sub(v0);                      v1.cross(v2, v12);                     v12.normalize();                      v2.cross(v3, v23);                     v23.normalize();                      v3.cross(v4, v34);                     v34.normalize();                      v4.cross(v1, v41);                     v41.normalize();                      normal = v12.add(v23).add(v34).add(v41);                     normal.normalize();                 } else {                     normal.x = 0;                     normal.y = 1;                     normal.z = 0;                 }                 normal.normalize();                 normals.add(normal.x);                 normals.add(normal.y);                 normals.add(normal.z);             }         }         return utils.listtoarray(normals);     }  } 

wild guess: you're using 16bit indices specify size of index buffer if 8bit indices (by setting size of buffer number of elements in buffer)?

judging screenshot, looks first half drawn, assume problem lies in creation of index buffer or draw call.

maybe used wrong number of indices in draw call? used number of triangles instead? or assumes number triangle fan instead of triangles?

you'll have post actual draw call , generation of buffer objects more information.

or @ least tag question according rendering library using, not plain opengl.


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -