Howdy,
I’m trying a simple test to create a VBO in JUCE with the code below, most of which was taken from the JuceDemo. My triangle does get displayed but only on the first call to renderOpenGL(), after that it does not appear.
Could someone please tell me what I’m doing wrong?
Thanks,
Bird
[code]
enum { PositionSlot, ColorSlot };
void OpenglCanvas::newOpenGLContextCreated ()
{
GLenum err = glewInit();
if (GLEW_OK != err)
{
// Glew didn’t initialize
jassert(0);
Logger::writeToLog(“ERROR::Glew failed to initialize”);
}
float verts[] = {
-0.5f, -0.5f, 1,1,0, // Yellow
+0.0f, +0.5f, 1,0,1, // Magenta
+0.5f, -0.5f, 0,1,1, // Cyan
};
GLuint vboHandle;
GLsizeiptr vboSize = sizeof(verts);
GLsizei stride = 5 * sizeof(float);
GLenum usage = GL_STATIC_DRAW;
GLvoid* colorOffset = (GLvoid*) (sizeof(float) * 2);
glGenBuffers(1, &vboHandle);
glBindBuffer(GL_ARRAY_BUFFER, vboHandle);
glBufferData(GL_ARRAY_BUFFER, vboSize, verts, usage);
glVertexAttribPointer(PositionSlot, 2, GL_FLOAT, GL_FALSE, stride, 0);
glVertexAttribPointer(ColorSlot, 3, GL_FLOAT, GL_FALSE, stride, colorOffset);
glEnableVertexAttribArray(PositionSlot);
glEnableVertexAttribArray(ColorSlot);
}
void OpenglCanvas::renderOpenGL ()
{
OpenGLHelpers::clear (Colours::black.withAlpha (1.0f));
{
MessageManagerLock mm (Thread::getCurrentThread());
if (! mm.lockWasGained())
return;
}
glDrawArrays(GL_TRIANGLES, 0, 3);
}[/code]