Problem of maximum vertices with glDrawelements

Hi, I am working on water surface simulation and I am using glDrawELements() for laying my triangular mesh.

The problem is, maximum vertices the code works is 62500(i.e when I lay a 250x250 grid). If I increase the grid size above this for eg 260x260 or 300x300 the grid gets stripped for right side and only 62500 vertices are drawn. Also the grid appears not laid properly.

link for 250x250 grid simulation image:

link for 350x350 grid simulation image:

I am using GL_TRIANGLES for putting the triangles. I have used the query command
glGetIntegerv(GL_MAX_ELEMENTS_VERTICES, &maxVertices);

which gives the output 1048576, and the max i can use is 62500 so I can still increase lot of vertices.

I had googled about this problem but all I found was to use GL_MAX_ELEMENTS_VERTICES and act accordingly. following is part of my code:


glNormalPointer(GL_FLOAT, 0, normals);

glGetIntegerv(GL_MAX_ELEMENTS_VERTICES, &maxVertices);
glGetIntegerv(GL_MAX_ELEMENTS_INDICES, &maxIndices);



where ‘n’ is the height or width of square grid.

Thanks in advance.

With GL_UNSIGNED_SHORT you are limited to 16 bit indices, so your indices are probably wrapping around after 65535. I suggest you try GL_UNSIGNED_INT and prepare your indices accordingly.

glGetIntegerv(GL_MAX_ELEMENTS_VERTICES, &maxVertices);
glGetIntegerv(GL_MAX_ELEMENTS_INDICES, &maxIndices);

These are constants. They don’t change. Also, they mean absolutely nothing for what you’re doing. They are for glDrawRangeElements, which is not a function you are using.


Your indices are shorts. Shorts take up only 16-bits. They can only represent numbers from 0 to 65535. If you have more than 256x256 vertices, then you will need more than 65536 indices. You must store integers in your index array, not shorts.

That solves the problem, thanks a lot.