Forums
OpenGLES2.0 Unknown error while drawing billboard with an element buffer - Printable Version

+- Forums (http://www.scratchpadgames.net/forums)
+-- Forum: Main Forums (http://www.scratchpadgames.net/forums/forumdisplay.php?fid=1)
+--- Forum: Help my code won't work?? (http://www.scratchpadgames.net/forums/forumdisplay.php?fid=22)
+--- Thread: OpenGLES2.0 Unknown error while drawing billboard with an element buffer (/showthread.php?tid=362)



OpenGLES2.0 Unknown error while drawing billboard with an element buffer - Joachim - 03-06-2019

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!


RE: OpenGLES2.0 Unknown error while drawing billboard with an element buffer - Brian Beuken - 03-06-2019

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?


RE: OpenGLES2.0 Unknown error while drawing billboard with an element buffer - Brian Beuken - 03-07-2019

did you fix it Joachim?


RE: OpenGLES2.0 Unknown error while drawing billboard with an element buffer - Joachim - 03-11-2019

(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