Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Problem in vertex_buffer_object

  1. #1
    Junior Member Regular Contributor
    Join Date
    Apr 2009
    Posts
    185

    Problem in vertex_buffer_object

    Please reply to this

    hi,

    i am by allot of hard work come at a point that now i draw a point without Begin/End and Vertex2f
    but i have some Question regarding to the following code:

    I Declared
    Code :
    GLuint Vertex;
    GLfloat TriVert[] = {0.0f,0.5f,
    0.0f,0.0f,
    -0.5f,0.0f};

    What i call for Display
    Thsee are inside Push/Pop Matrix and MatrixMode with LoadIdentity
    Code :
    glVertexPointer(2,GL_FLOAT,0,0);
    glBindBufferARB(GL_ARRAY_BUFFER_ARB,Vertex);
     
    glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_READ_WRITE_ARB);
     
    glEnableClientState(GL_VERTEX_ARRAY);
    glColor3f(1.0f,1.0f,1.0f);
    glDrawElements(GL_POINTS,1,GL_UNSIGNED_SHORT,&TriVert[0]);
    glDrawElements(GL_POINTS,1,GL_UNSIGNED_SHORT,&TriVert[2]);
    glDrawElements(GL_POINTS,1,GL_UNSIGNED_SHORT,&TriVert[4]);
    glDisableClientState(GL_VERTEX_ARRAY);

    Here a GLEW help Me
    Code :
    if(GLEW_ARB_vertex_buffer_object)
    {
    printf("Let's try some VBO and job on the almost AGP/VGA i915\n");
     
    glGenBuffersARB(1,&Vertex);
     
    glBindBufferARB(GL_ARRAY_BUFFER_ARB,Vertex);
     
    glBufferDataARB(GL_ARRAY_BUFFER_ARB,sizeof(TriVert),0,GL_STREAM_DRAW_ARB);
     
    glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, sizeof(TriVert), TriVert);
     
    glGetBufferParameterivARB(GL_ARRAY_BUFFER_ARB, GL_BUFFER_SIZE_ARB, &bufferSize);
            fprintf(stdout,"Vertex size %i bytes\n",bufferSize);
     
     
    }
    My Question are

    Q1.Is The job i do is in My VGA/AGP(anything that is) Memory

    Q2.As for getting result i try POINTS instead of TRIANGLES but i got only one point in my screen at (0.0,0.5)
    while there are 3 DrawElement Functions are Called
    so what ido for 2 more so there is a triangle job


    Please reply this and

    Thanks for just reading my Topic post and also thanks for just thinking on My Questions

    Thanks in advance
    haven't made a game [img]<<GRAEMLIN_URL>>/frown.gif[/img]

  2. #2
    Junior Member Regular Contributor
    Join Date
    Apr 2009
    Posts
    185

    Re: Problem in vertex_buffer_object

    Problem solved but with Question


    Hey any one who read this


    i resolved my problem by just one hit of glDrawArrays in place of glDrawElements which just need GLfloat Array's starting an ending position [0] and [end]


    and it draw the triangle for me
    but there still some

    Q1.Is the triangle goes in AGP/VGA Memory or it is a
    done in just a way Vertexf do

    Q2. Primitive drawn by that single hit command is ye good but
    what id that glDrawElement can it used

    please reply
    and thanks for just reading and thinking on it


    thanks in advance
    vivek
    haven't made a game [img]<<GRAEMLIN_URL>>/frown.gif[/img]

  3. #3
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    2,882

    Re: Problem in vertex_buffer_object

    Quote Originally Posted by vivek vyas
    i resolved my problem by just one hit of glDrawArrays in place of glDrawElements which just need GLfloat Array's starting an ending position [0] and [end] and it draw the triangle for me but there still some

    Q1.Is the triangle goes in AGP/VGA Memory or it is a
    done in just a way Vertexf do

    Q2. Primitive drawn by that single hit command is ye good but
    what id that glDrawElement can it used
    Your questions are getting lost in the language barrier.

    There are some issues in your code. First, you should bind your VBO buffer before you latch it with a "gl*Pointer" call. Second, you should put "all" of your vertex data in vertex attribute arrays (either client side OR server side, don't mix as that leads to bad performance).

    I'd suggest you take one smaller step. Don't use server arrays (aka VBOs) for a minute. Just use client arrays (i.e. comment out all the buffer stuff). That is, do this if you just need vertex positions and colors:

    glEnableClientState( GL_VERTEX_ARRAY );
    glEnableClientState( GL_COLOR_ARRAY );
    glVertexPointer( size, type, stride, cpu_pointer );
    glColorPointer( size, type, stride, cpu_pointer );
    glDrawArrays( ... )
    glDisableClientState( GL_VERTEX_ARRAY );
    glDisableClientState( GL_NORMAL_ARRAY );

    Get comfy with that. Then, switch to tfDrawElements(). For the indices argument, pass in a pointer to an array that contains 0,1,2. For one triangle its overkill, but for big meshes it can save the GPU a lot of work!

    Now switch your two vertex attribute arrays from client arrays to server arrays (aka VBOs) but putting them both and the index list in buffer objects. Start with putting them each in their own VBO. Get that working. Then realize you can put both vertex attribute arrays in one VBO, interleaving the values. Consider trying that as well.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •