globjects icon indicating copy to clipboard operation
globjects copied to clipboard

Potentially add even more basic examples?

Open andrew-kennedy opened this issue 8 years ago • 3 comments

I've been trying to use this library for a day or two now, and while I'm new to openGL, I'm struggling to use this library to even draw a simple triangle, starting with my vertex data and color data in 2 separate std::vector<glm::vec3>'s. I can accomplish this with the normal openGL calls, but despite going through example after example, I can't seem to figure out how to translate the simple task of drawing one triangle to globjects code. Having even just one slightly more fleshed out case of regular openGL vs globjects would be super helpful. It's really hard to find documentation on this library elsewhere on the web.

andrew-kennedy avatar Feb 10 '17 00:02 andrew-kennedy

You're right, the current entry level of knowledge includes actual OpenGL knowledge of all object types and their relations. We should focus on easing usage, e.g., by providing more examples that show more aspects from OpenGL and how they are used with globjects.

As a long-term goal we want to provide a large amount of cool OpenGL demos and examples based on globjects but our programming capacity is currently low and we must focus on other projects right now. I think a quick view into some of our projects based on globjects may help:

  • https://github.com/hpicgs/glexamples
  • https://github.com/cgcostume/multiframesampling
  • https://github.com/cginternals/glhimmel

In addition, you can provide a link or open another issue where you provide some code so I can have a look at it.

scheibel avatar Feb 10 '17 10:02 scheibel

Well one example where a question arises is here where you bind a VAO using globjects but then draw the triangles using a standard openGL call, glDrawArrays. Why not use the vao->drawArrays() method here? Is it possible to accomplish this same pipeline using only globjects calls?

andrew-kennedy avatar Feb 12 '17 22:02 andrew-kennedy

also, here's some code I have questions about:

    auto g_vao = make_ref<VertexArray>();
    auto g_vertexBuffer = make_ref<Buffer>();
    g_vertexBuffer->setData(g_vertices, GL_STATIC_DRAW);
    auto g_colorBuffer = make_ref<Buffer>();
    g_colorBuffer->setData(g_colors, GL_STATIC_DRAW);

    auto binding = g_vao->binding(0);
    binding->setAttribute(0);
    binding->setBuffer(g_vertexBuffer, 0, sizeof(glm::vec3));
    binding->setFormat(3, GL_FLOAT);
    
    binding->setAttribute(1);
    binding->setBuffer(g_colorBuffer, 0, sizeof(glm::vec3));
    binding->setFormat(3, GL_FLOAT);
    
    g_vao->enable(0);

and the relevant vertex shader is:

#version 330 core
layout(location = 0) in vec3 vertPos;
layout(location = 1) in vec3 color;
uniform mat4 P;
uniform mat4 MV;

out vec3 Color;

void main()
{
    Color = color;
    gl_Position = P * MV * vec4(vertPos, 1.0);
}

Using this code to initialize buffers given that g_vertices and g_colors are std::vector<glm::vec3>'s, I get all the vertices drawn properly but my shapes are black, so however I initialize the color buffer appears to be wrong.

EDIT: I just needed to enable that attribute in the Vertex Array. So all is well now in at least my small project. But I still would look forward to more comparisons to "plain old" OpenGL calls. Especially to clarify what's happening when I call, say, g_vao->setAttribute(0). At the end of that call, what exactly has happened in my Vertex Array? It's unclear without diving into the source code, at least to me. I think globjects could really benefit from some function documentation.

andrew-kennedy avatar Feb 12 '17 22:02 andrew-kennedy