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

Potentially add even more basic examples? #336

Open
andrew-kennedy opened this issue Feb 10, 2017 · 3 comments
Open

Potentially add even more basic examples? #336

andrew-kennedy opened this issue Feb 10, 2017 · 3 comments

Comments

@andrew-kennedy
Copy link

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.

@scheibel
Copy link
Member

scheibel commented Feb 10, 2017

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:

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

@andrew-kennedy
Copy link
Author

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
Copy link
Author

andrew-kennedy commented Feb 12, 2017

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.

@cgcostume cgcostume added this to To do in globjects-2.0.0 via automation Oct 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

3 participants