Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hi, Does there have any example to render VAO data with pangolin? #799

Open
lfwin opened this issue Oct 13, 2022 · 1 comment
Open

Hi, Does there have any example to render VAO data with pangolin? #799

lfwin opened this issue Oct 13, 2022 · 1 comment

Comments

@lfwin
Copy link

lfwin commented Oct 13, 2022

I try to modify code '3_gl_intro_classic_triangle_vbo_shader.cpp' in example folder as following,

void sample()
{
    pangolin::CreateWindowAndBind("Classic GL Triangle With VBO and Shader", 500, 500);

    // Build and compile our shader program
    // ------------------------------------

    Shader shader("9.1.geometry_shader.vert", "9.1.geometry_shader.frag", "9.1.geometry_shader.geom");


    float points[] = {
        -0.5f,  0.5f, 1.0f, 0.0f, 0.0f, // top-left
         0.5f,  0.5f, 0.0f, 1.0f, 0.0f, // top-right
         0.5f, -0.5f, 0.0f, 0.0f, 1.0f, // bottom-right
        -0.5f, -0.5f, 1.0f, 1.0f, 0.0f  // bottom-left
    };
    unsigned int VBO, VAO;
    glGenBuffers(1, &VBO);
    glGenVertexArrays(1, &VAO);
    glBindVertexArray(VAO);
    glBindBuffer(GL_ARRAY_BUFFER, VBO);
    glBufferData(GL_ARRAY_BUFFER, sizeof(points), &points, GL_STATIC_DRAW);
    glEnableVertexAttribArray(0);
    glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), 0);
    glEnableVertexAttribArray(1);
    glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(2 * sizeof(float)));
    glBindVertexArray(0);


    // Setup a variable to progress a simple animation as a function of time
    float time = 0.01f;

    while( !pangolin::ShouldQuit() )
    {
        glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        shader.use();
        // Set our buffer as the current one for OpenGL
        glBindVertexArray(VAO);

        // This buffer contains floating point vertices with 3 dimensions.
        // They starts from the 0th element and are packed without padding.
        //glVertexPointer(3, GL_FLOAT, 0, 0);

        // Use Them!
        glEnableClientState(GL_VERTEX_ARRAY);

        //GLint u_time = glGetUniformLocation(shaderProgram, "u_time");
        //glUniform1f( u_time, time);
        shader.setFloat("u_time", time);

        glDrawArrays(GL_POINTS, 0, 4);
        //pangolin::RenderVbo(VAO, GL_POINTS);

        // Disable the stuff we enabled...
        glDisableClientState(GL_VERTEX_ARRAY);
        glBindVertexArray(0);

        time += 0.01;

        pangolin::FinishFrame();
    }

    // Deallocate the OpenGL buffer we made
    glDeleteVertexArrays(1, &VAO);
    glDeleteBuffers(1, &VBO);

    // Deallocate the GlSl Shader program
    // glDeleteProgram(shaderProgram);
}

int main( int /*argc*/, char** /*argv*/ )
{
    sample();
    return 0;
}

This just draw four points, but what i want to draw is 4 circles.

@stevenlovegrove
Copy link
Owner

You seem to be using a different shader library, and you don't include the shader code, so I don't know that you'll be able to get much help here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants