0

I'm creating a glBufferData using an array explicitly defined of vertex coordinates and everything works fine. When using a non explicitly defined array the result is totally different althought I'm using the same coordinates values. The drawcall renders things in a different vertexs order.

The vertexs are a grid of triangles.

Code 1 that works fine:

this->graphics->createBuffers(1, vboIndexsID);
this->graphics->bindBuffer(GL_ELEMENT_ARRAY_BUFFER, *vboIndexsID);
this->graphics->bufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLushort)*numIndexs, ind, GL_STATIC_DRAW);

this->graphics->createBuffers(1, vboVertexsID);
this->graphics->bindBuffer(GL_ARRAY_BUFFER, *vboVertexsID);

this->graphics->bufferData(GL_ARRAY_BUFFER, 300, quad_verts2, GL_STATIC_DRAW);

where quad_verts2 is:

GLfloat quad_verts2[75] =
{
    0.0f,   0.0f, 0.0f, 
    0.0f,   0.0f, 100.0f, 
    0.0f,   0.0f, 200.0f, 
    0.0f,   0.0f, 300.0f, 
    0.0f,   0.0f, 400.0f, 
    100.0f, 0.0f, 0.0f, 
    100.0f, 0.0f, 100.0f, 
    100.0f, 0.0f, 200.0f, 
    100.0f, 0.0f, 300.0f, 
    100.0f, 0.0f, 400.0f, 
    200.0f, 0.0f, 0.0f, 
    200.0f, 0.0f, 100.0f, 
    200.0f, 0.0f, 200.0f, 
    200.0f, 0.0f, 300.0f, 
    200.0f, 0.0f, 400.0f, 
    300.0f, 0.0f, 0.0f, 
    300.0f, 0.0f, 100.0f, 
    300.0f, 0.0f, 200.0f, 
    300.0f, 0.0f, 300.0f, 
    300.0f, 0.0f, 400.0f, 
    400.0f, 0.0f, 0.0f, 
    400.0f, 0.0f, 100.0f, 
    400.0f, 0.0f, 200.0f, 
    400.0f, 0.0f, 300.0f, 
    400.0f, 0.0f, 400.0f
};

Code 2 that doesn't work:

this->graphics->createBuffers(1, vboIndexsID);
this->graphics->bindBuffer(GL_ELEMENT_ARRAY_BUFFER, *vboIndexsID);
this->graphics->bufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLushort)*numIndexs, ind, GL_STATIC_DRAW);

this->graphics->createBuffers(1, vboVertexsID);
this->graphics->bindBuffer(GL_ARRAY_BUFFER, *vboVertexsID);

this->graphics->bufferData(GL_ARRAY_BUFFER, 300, list, GL_STATIC_DRAW);

exactly the same as before, but the list data instead of quad_vert2.

where list is:

GLfloat list[75];
int j = 0;
for(int i=0;i<numVertexs;++i) {
    list[j] = v->coord.x;j++;
    list[j] = v->coord.y;j++;
    list[j] = v->coord.z;j++;
    ++v;
}

the data in v, is exactly the same values than in quad_vert2.

glGetError, after glBufferData is always 0. If I get the data in the buffer using glGetBufferSubData the values are the same.

Ideas?

thanks in advance.

11
  • Did you forget to assign numVertexs? Commented Aug 26, 2013 at 21:22
  • Nope. The data in list and in quad_vert2 has the same values with the inspector. Commented Aug 26, 2013 at 21:24
  • First of all: GLfloat* list = new GLfloat[numVertices*3]; Commented Aug 26, 2013 at 21:25
  • @Frizi: Yuck! No need for memory leaks here. Commented Aug 26, 2013 at 21:26
  • With quad_verts2 I can see 25 points in the screen, with list only 9. Commented Aug 26, 2013 at 21:27

2 Answers 2

1

I would be suspect of the value of numVertexs, since your buffer data upload call does not actually use it. You should be uploading sizeof (GLfloat) * 3 * numVertexs bytes of data and not using the magic number 300. If you replace 300 with that expression in both situations chances are good that it will expose your real problem.

Sign up to request clarification or add additional context in comments.

Comments

0

Thank you all,

the problem here was: I was rendering two objects, with different number of vertexs. When rendering, I forgot to assign the indexs buffer correctly, and openGL was trying to draw the second object with the indexs of the first one.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.