Results 1 to 2 of 2

Thread: drawing two objects with two vbo,vao

  1. #1
    Newbie Newbie
    Join Date
    Nov 2016
    Posts
    1

    drawing two objects with two vbo,vao

    Code cpp:
        GLuint VBO[2], VAO[2];
     
        glGenVertexArrays(2, VAO);
        glGenBuffers(2, VAO);
     
     
     
        glBindVertexArray(VAO[0]);
        glBindBuffer(GL_ARRAY_BUFFER, VBO[0]);
        //Konfiguration bezieht sich jetzt auf VBO[0] wegen glbindvertexarray()
        glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
        glVertexAttribPointer(0,3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid *) 0);
        glEnableVertexAttribArray(0);
        glBindVertexArray(0);
     
     
        glBindVertexArray(VAO[1]);
        glBindBuffer(GL_ARRAY_BUFFER, VBO[1]);
        glBufferData(GL_ARRAY_BUFFER, sizeof(secVertices), secVertices, GL_STATIC_DRAW);
        glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE,0, (GLvoid *) 0);
        glEnableVertexAttribArray(1);
        glBindVertexArray(1);

    i am trying to draw two quads with two different vbos/vaos.
    i am absolutely new to opengl and i am learning with a pdf tutorial.
    when i start the program , only one quad is drawn
    its the quad from vao[1] and vbo[1].
    it has to do with glbufferdata but i dont really get it.

    please tell me what to do. sorry for my english and thanks for answears

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    Posts
    4,651
    Quote Originally Posted by eniddelemaj View Post
    Code cpp:
    GLuint VBO[2], VAO[2];
    ...
    glGenBuffers(2, VAO);
    ...
    This looks like a typo. Look at which array you're passing to glGenBuffers. Also...

    Code cpp:
    ...
    glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE,0, (GLvoid *) 0);
    glEnableVertexAttribArray(1);
    ...

    I suspect you want 0 here for the first argument of both functions. This call enables generic vertex attribute arrays. 0 is the conventional vertex attribute used for passing the positions array.

    The number you use here has to be matched with the vertex attribute index that the vertex shader is expecting the positions to come in on. And finally...

    Code cpp:
    ...
    glBindVertexArray(1);

    Here at the very end you probably want 0 here as well. Like the same call previously, the purpose of this is to unbind the vertex array object (VAO) that you're currently configuring.

Similar Threads

  1. Drawing 2 different objects at the same time...
    By adpward in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 09-29-2015, 01:07 PM
  2. drawing 2d objects
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 08-21-2004, 02:17 AM
  3. Drawing objects
    By imported_Ulrich in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 06-21-2004, 01:43 PM
  4. drawing 2 or more objects in one viewport
    By KC in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-29-2000, 05:34 PM
  5. Drawing objects on top of one another.
    By Dang in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-04-2000, 06:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean