Results 1 to 2 of 2

Thread: VBO with multiple objects

  1. #1
    Member Contributor
    Join Date
    Apr 2011
    Location
    Barcelona, Catalunya
    Posts
    55

    VBO with multiple objects

    Hi,

    I need to use VBO method in a program where I need to draw 7 joints of a robot. Those joints are, each one, an object of "Joint" class.

    This class has a function to initialize the arrays:
    Code :
    void Joint::initArray()
    {
        vertexArray = new GLfloat[sizeVertex];
        normalArray = new GLfloat[sizeNormal];
        Vertex v;
        Vertex n;
        int i = 0;
        int j;
        for(j=0;j<vertexVector.size();j++)
        {
            v = vertexVector[j];
            vertexArray[i] = v.x;
            vertexArray[i+1] = v.y;
            vertexArray[i+2] = v.z;
            i+=3;
        }
     
        i = 0;
        for(j=0;j<normalVector.size();j++)
        {
            n = normalVector[j];
            normalArray[i] = n.x;
            normalArray[i+1] = n.y;
            normalArray[i+2] = n.z;
            i+=3;
        }
     
        GLuint vertexs,normals;
     
     
        glGenBuffers(1,&amp;vertexs);
        glBindBuffer(GL_ARRAY_BUFFER,vertexs);
        glBufferData(GL_ARRAY_BUFFER,sizeVertex*sizeof(GLfloat),vertexArray,GL_DYNAMIC_DRAW);
        glVertexPointer(3,GL_FLOAT,3*sizeof(GLfloat),0);
     
        glGenBuffers(1,&amp;normals);
        glBindBuffer(GL_ARRAY_BUFFER,normals);
        glBufferData(GL_ARRAY_BUFFER,sizeNormal*sizeof(GLfloat),normalArray,GL_DYNAMIC_DRAW);
        glNormalPointer(GL_FLOAT,3*sizeof(GLfloat),0);
    }

    After that, I have a render function:
    Code :
    void Joint::render()
    {
            glEnableClientState(GL_VERTEX_ARRAY);
            glDrawArrays(GL_TRIANGLES,0,sizeVertex);
            glDisableClientState(GL_VERTEX_ARRAY);
     
            glEnableClientState(GL_NORMAL_ARRAY);
            glDrawArrays(GL_TRIANGLES,0,sizeNormal);
            glDisableClientState(GL_NORMAL_ARRAY);
     
    }

    I think that everything is ok but the program just draw the first join. Do you know where's the problem?
    I thinnk it's in the buffer's name but in this case, I don't know how to solve it. Can someone help me plz?

    Thanks

  2. #2
    Senior Member OpenGL Pro Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    1,214

    Re: VBO with multiple objects

    Please go to wiki or elsewhere where you can learn how VBO works.
    Whenever you issue glDrawArray() you are actually drawing vertices. All enabled attributes are used.

    By the way, you haven't set attribute pointers (with glVertexPointer and glNormalPointer)! You have to bind appropriate VBO (since you are using two separate for vertices and normals), and while it is active call appropriate gl*Pointer function. You can enable attributes before of after those calls, but certainly before glDrawArray.

    Everything mentioned above considers using fixed functionality. It is a little bit different with shaders. (I assume you are using fixed functionality since you are calling glEnableClientState).

Similar Threads

  1. multiple objects?
    By snowyCoder in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 03-24-2015, 08:45 AM
  2. Multiple objects: single or multiple shaders?
    By sam_thedancer in forum OpenGL: Basic Coding
    Replies: 14
    Last Post: 04-29-2013, 03:29 AM
  3. Multiple objects in a VBO or Multiple VBOs?
    By Kreed in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 09-04-2012, 12:42 PM
  4. Multiple objects
    By whreckz in forum OpenGL ES
    Replies: 0
    Last Post: 05-28-2008, 12:43 AM
  5. Multiple Objects
    By in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 10-12-2000, 07:17 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