Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
OpenGLES2.0 Unknown error while drawing billboard with an element buffer
#1
Hi, I am working on a billboard model that simply consists of a few hard coded vertices. I want to use this model a lot throughout the project I'm working on so I figured it would be a good idea to make these as optimized as possible and thus use element indices to define which vertices must be drawn and which ones ignored.

My primary source for this has been the LearnOpenGL website. 
The snippet for drawing my quad is as follows:
Code:
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementBuffer);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
if (glGetError() != GL_NO_ERROR)
{
    printf("Oh bugger Billboard Draw error\n");
    return false;
}
The printf seen above is triggered so something is going wrong, however I can't figure out what the error actually is.
The code which I use for initializing the model is quite straightforward, but I feel like I'm missing something very silly.
Code:
this->Vertices = billboardVertices;

    glGenBuffers(1, &vbo);
    glBindBuffer(GL_ARRAY_BUFFER, vbo);
    glBufferData(GL_ARRAY_BUFFER, sizeof(billboardVertices), billboardVertices, GL_STATIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);

    glGenBuffers(1, &elementBuffer);    
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementBuffer);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

As this code is mostly expanded upon from the SpaceCadet project, the rest of the draw function is basically the same, so I suspect there shouldn't be anything causing my problem there. Thanks a bunch in advance to anyone helping me figure this out!
Reply
#2
Hi Joachim

there's some code we can't seehere but I can see one thing wrong...if your drawing a billboard, from an element list, you mybe don't have 6 vertices, you have 4? though my examples don't remove the repeats.

Also you need to make sure you bind the array and the element buffers. you seem to be unbinding them after you set them up.

let me know if this gets you further?
Brian Beuken
Lecturer in Game Programming at Breda University of Applied Sciences.
Author of The Fundamentals of C/C++ Game Programming: Using Target-based Development on SBC's 



Reply
#3
did you fix it Joachim?
Brian Beuken
Lecturer in Game Programming at Breda University of Applied Sciences.
Author of The Fundamentals of C/C++ Game Programming: Using Target-based Development on SBC's 



Reply
#4
(03-07-2019, 04:53 PM)Brian Beuken Wrote: did you fix it Joachim?

Yes! Apologies for the late reply and keeping you in suspence! It took some time but I am now able to draw my billboard with 4 vertices and everything looks good.[Image: quad.JPG]
The heads up you gave me about binding both the EBO and the VBO gave me a good direction to look in. Also your suspicions are correct when it comes to the amount of vertices I have defined. The picture above is rendered using 4 vertices instead of six, which was a problem at the time as well. 
Thanks a bunch for thinking along
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)