Difficulty setting up simple VBO and Shader [SOLVED]

I’m having difficulty setting up a simple VBO and shader. I’m trying to do something akin to this Hello Triangle code sample, but using ofShader and ofVbo.

I’ve debugged step-by-step into OpenFrameworks and all the proper OpenGL calls seem to be made, yet no triangle appears on screen.

My ofApp.cpp looks like this:

#include "ofApp.h"

const float ofApp::vertices[6] = {
    -0.5f, -0.5f,    // Left (X,Y)
    0.5f, -0.5f, // Right (X,Y)
    0.0f, 0.5f  // Top (X,Y)
};

//--------------------------------------------------------------
void ofApp::setup(){
    shader.load("shaderGL3/shader");
    vbo.setVertexData(vertices, 2, 3, GL_STATIC_DRAW, 2*(sizeof(float)));
    glDisable(GL_DEPTH_TEST);
}

//--------------------------------------------------------------
void ofApp::draw(){
    glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);

    ofPtr<ofGLProgrammableRenderer> renderer = ofGetGLProgrammableRenderer();
    renderer->beginCustomShader(shader);
    vbo.draw(GL_TRIANGLES, 0, 3);
    renderer->endCustomShader();

    ofColor(255, 255, 255);
    ofDrawBitmapString("D:", 100, 100);
}

data/bin/shaderGL3/shader.vert:

#version 330 core

layout (location = 0) in vec2 position;

void main()
{
    gl_Position = vec4(position.x, position.y, 0.0f, 1.0f);
}

data/bin/shaderGL3/shader.frag:

#version 330 core

out vec4 color;

void main()
{
    color = vec4(1.0f, 0.5f, 0.2f, 1.0f);
} 

What am I doing wrong?

Thanks for your help :smile:

EDIT : main.cpp has following first line:

ofSetCurrentRenderer(ofGLProgrammableRenderer::TYPE);

Actually, I got it working :expressionless:

I shouldn’t have tried to access the renderer directly. I must have done this while there was something else wrong with the code, and then I let it like that.

This is now my draw method:

//--------------------------------------------------------------
void ofApp::draw(){
    glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);

    shader.begin();
    vbo.draw(GL_TRIANGLES, 0, 3);
    shader.end();

    ofColor(255, 255, 255);
    ofDrawBitmapString(":D", 100, 100);
}

Consider it solved!