opengl - Libgdx - Custom Created 3d Mesh causes java.nio.BufferOverflowException -


i using libgdx generate 3d mesh in code. right attempting generate flat plane many vertices in middle test things out, received exception in thread "lwjgl application" java.nio.bufferoverflowexception when called mesh.setindices(indices); variable indices short array.

i not having trouble if have less 180-150 indices. wasn't able figure out exact number trail , error, exception thrown if have more 180 indices.

here code creating mesh:

firstly how generate vertices (i don't think problem, ill put them in anyways) *note vertex attributes (vertexattribute.position(), vertexattribute.normal(), vertexattribute.colorunpacked())

private float[] generatevertices(int width, int height) {     int index = 0;     float vertices[] = new float[width*height*10];      for(int = 0; < width; ++) {         for(int j = 0; j < height; j++) {             //vertex coordinates             vertices[index] = i;             vertices[index+1] = 0;             vertices[index+2] = j;              // normal             vertices[index+3] = 0;             vertices[index+4] = 1;             vertices[index+5] = 0;              // random colors!!!             vertices[index+6] = mathutils.random(0.3f, 0.99f);             vertices[index+7] = mathutils.random(0.3f, 0.99f);             vertices[index+8] = mathutils.random(0.3f, 0.99f);             vertices[index+9] = 1;             index+=10;         }     }     return vertices; } 

secondly here how generate indices:

private short[] generateindices(int width, int height) {     int index = 0;     short indices[] = new short[(width-1)*(height-1)*3 * 2];     for(int = 0; < width-1; ++) {         (int j = 0; j < height-1; j++) {             indices[index]   = (short)((j*height) + i);             indices[index+1] = (short)((j*height) + i+1);             indices[index+2] = (short)(((j+1)*height) + i);              indices[index+3] = (short)(((j+1)*height) + i);             indices[index+4] = (short)((j*height) + i+1);             indices[index+5] = (short)(((j+1)*height) + + 1);             index+= 6;         }     }     return indices; } 

thirdly how set vertices , indices (note 6 , 7 width , height of plane):

    mesh.setvertices(generatevertices(6, 7));     mesh.setindices(generateindices(6, 7)); 

finally, here how rendered mesh through custom shader.

    shaderprogram.setuniformmatrix("u_projectionviewmatrix", camera.combined);     shaderprogram.setuniformmatrix("umvmatrix", mat4);     // rendering triangles     mesh.render(shaderprogram, gl20.gl_triangles); 

i don't know causing exception, appreciated. suggestions welcome.

thanks in advance.


Comments

Popular posts from this blog

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

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

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