Skip to main content
deleted 508 characters in body
Source Link
wondra
  • 4.9k
  • 1
  • 22
  • 36

The call glDrawElements(..., indices.size(), GL_UNSIGNED_SHORT, 0); tells your GPU roughly following:

for(unsigned short i = 0 /*last parameter*/; i < indices.size(); i += 3 /*3 vertices/triangle*/ )
{
   drawTriangle(VBO[indices[i]], VBO[indices[i + 1]], VBO[indices[i + 2]] );
}

Do you see what is wrong now? If the value of indices[i] is higher than your size of VBO, it is a problem.
Moreover, for VBO it is recommended to have around 1-4MB of vertices in it - only 4 vertices/VBO will very likely kill your performance. You might be interested in instancing instead.

big edit reason: cant read right(solved in comments)

The call glDrawElements(..., indices.size(), GL_UNSIGNED_SHORT, 0); tells your GPU roughly following:

for(unsigned short i = 0 /*last parameter*/; i < indices.size(); i += 3 /*3 vertices/triangle*/ )
{
   drawTriangle(VBO[indices[i]], VBO[indices[i + 1]], VBO[indices[i + 2]] );
}

Do you see what is wrong now? If the value of indices[i] is higher than your size of VBO, it is a problem.
Moreover, for VBO it is recommended to have around 1-4MB of vertices in it - only 4 vertices/VBO will very likely kill your performance.

big edit reason: cant read right(solved in comments)

The call glDrawElements(..., indices.size(), GL_UNSIGNED_SHORT, 0); tells your GPU roughly following:

for(unsigned short i = 0 /*last parameter*/; i < indices.size(); i += 3 /*3 vertices/triangle*/ )
{
   drawTriangle(VBO[indices[i]], VBO[indices[i + 1]], VBO[indices[i + 2]] );
}

Do you see what is wrong now? If the value of indices[i] is higher than your size of VBO, it is a problem.
Moreover, for VBO it is recommended to have around 1-4MB of vertices in it - only 4 vertices/VBO will very likely kill your performance. You might be interested in instancing instead.

big edit reason: cant read right(solved in comments)

deleted 508 characters in body
Source Link
wondra
  • 4.9k
  • 1
  • 22
  • 36

The call glDrawElements(..., indices.size(), GL_UNSIGNED_SHORT, 0); tells your GPU roughly following:

for(unsigned short i = 0 /*last parameter*/; i < indices.size(); i += 3 /*3 vertices/triangle*/ )
{
   drawTriangle(VBO[indices[i]], VBO[indices[i + 1]], VBO[indices[i + 2]] );
}

Do you see what is wrong now? You need index for each vertex drawn. In you draw method you told GPU to renderIf the value of indices.size()indices[i](which happends to be 6) vertices. Additionally, there might be one more error in specifying is higher than your size/leght in some other glCall(I would expect last 2 triangles drawn) of VBO, it is a problem.
A somebody gave me a good advice: when everything fails, start drawing. I dont say this is copy/paste solutionMoreover, but hopefullyfor VBO it gives you an idea how to solve similar problems, taking pencil and paper and getting right indices manually gives: ![enter image description here][1]

...it should not be difficult to derive right formulais (you probably already have the right one, just you needrecommended to apply if for every "index" = for every quad and handle looping from backhave around 1-4MB of quad "strip") [1]:vertices in it https://i.sstatic.net/n9QZY.png- only 4 vertices/VBO will very likely kill your performance.

big edit reason: cant read right(solved in comments)

The call glDrawElements(..., indices.size(), GL_UNSIGNED_SHORT, 0); tells your GPU roughly following:

for(unsigned short i = 0 /*last parameter*/; i < indices.size(); i += 3 /*3 vertices/triangle*/ )
{
   drawTriangle(VBO[indices[i]], VBO[indices[i + 1]], VBO[indices[i + 2]] );
}

Do you see what is wrong now? You need index for each vertex drawn. In you draw method you told GPU to render indices.size()(which happends to be 6) vertices. Additionally, there might be one more error in specifying size/leght in some other glCall(I would expect last 2 triangles drawn).
A somebody gave me a good advice: when everything fails, start drawing. I dont say this is copy/paste solution, but hopefully it gives you an idea how to solve similar problems, taking pencil and paper and getting right indices manually gives: ![enter image description here][1]

...it should not be difficult to derive right formula (you probably already have the right one, just you need to apply if for every "index" = for every quad and handle looping from back of quad "strip") [1]: https://i.sstatic.net/n9QZY.png

The call glDrawElements(..., indices.size(), GL_UNSIGNED_SHORT, 0); tells your GPU roughly following:

for(unsigned short i = 0 /*last parameter*/; i < indices.size(); i += 3 /*3 vertices/triangle*/ )
{
   drawTriangle(VBO[indices[i]], VBO[indices[i + 1]], VBO[indices[i + 2]] );
}

Do you see what is wrong now? If the value of indices[i] is higher than your size of VBO, it is a problem.
Moreover, for VBO it is recommended to have around 1-4MB of vertices in it - only 4 vertices/VBO will very likely kill your performance.

big edit reason: cant read right(solved in comments)

Post Undeleted by wondra
Post Deleted by wondra
deleted 15 characters in body
Source Link
wondra
  • 4.9k
  • 1
  • 22
  • 36

The call glDrawElements(..., indices.size(), GL_UNSIGNED_SHORT, 0); tells your GPU roughly following:

for(unsigned short i = 0 /*last parameter*/; i < indices.size(); i += 3 /*3 vertices/triangle*/ )
{
   drawTriangle(VBO[indices[i]], VBO[indices[i + 1]], VBO[indices[i + 2]] );
}

Do you see what is wrong now? You need index for each vertex drawn. In you draw method you told GPU to render indices.size()(which happends to be 6) vertices. Additionally, there might be one more error in specifying size/leght in some other glCall(I would expect last 2 triangles drawn).
A somebody gave me a good advice: when everything fails, start drawing. I dont say this is copy/paste solution, but hopefully it gives you an idea how to solve similar problems, taking pencil and paper and getting right indices manually gives: ![enter image description here][1]

...it should not be difficult to derive right formula (you probably already have the right one, just you need to doapply if for every "index" inside loop creating= for every quad verticesand handle looping from back of quad "strip") [1]: https://i.sstatic.net/n9QZY.png

The call glDrawElements(..., indices.size(), GL_UNSIGNED_SHORT, 0); tells your GPU roughly following:

for(unsigned short i = 0 /*last parameter*/; i < indices.size(); i += 3 /*3 vertices/triangle*/ )
{
   drawTriangle(VBO[indices[i]], VBO[indices[i + 1]], VBO[indices[i + 2]] );
}

Do you see what is wrong now? You need index for each vertex drawn. In you draw method you told GPU to render indices.size()(which happends to be 6) vertices. Additionally, there might be one more error in specifying size/leght in some other glCall(I would expect last 2 triangles drawn).
A somebody gave me a good advice: when everything fails, start drawing. I dont say this is copy/paste solution, but hopefully it gives you an idea how to solve similar problems, taking pencil and paper and getting right indices manually gives: ![enter image description here][1]

...it should not be difficult to derive right formula (you probably already have the right one, just you need to do if for every "index" inside loop creating quad vertices) [1]: https://i.sstatic.net/n9QZY.png

The call glDrawElements(..., indices.size(), GL_UNSIGNED_SHORT, 0); tells your GPU roughly following:

for(unsigned short i = 0 /*last parameter*/; i < indices.size(); i += 3 /*3 vertices/triangle*/ )
{
   drawTriangle(VBO[indices[i]], VBO[indices[i + 1]], VBO[indices[i + 2]] );
}

Do you see what is wrong now? You need index for each vertex drawn. In you draw method you told GPU to render indices.size()(which happends to be 6) vertices. Additionally, there might be one more error in specifying size/leght in some other glCall(I would expect last 2 triangles drawn).
A somebody gave me a good advice: when everything fails, start drawing. I dont say this is copy/paste solution, but hopefully it gives you an idea how to solve similar problems, taking pencil and paper and getting right indices manually gives: ![enter image description here][1]

...it should not be difficult to derive right formula (you probably already have the right one, just you need to apply if for every "index" = for every quad and handle looping from back of quad "strip") [1]: https://i.sstatic.net/n9QZY.png

added 39 characters in body
Source Link
wondra
  • 4.9k
  • 1
  • 22
  • 36
Loading
deleted 4 characters in body
Source Link
wondra
  • 4.9k
  • 1
  • 22
  • 36
Loading
Source Link
wondra
  • 4.9k
  • 1
  • 22
  • 36
Loading