Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: getting started with vbo's

  1. #1

    getting started with vbo's

    I am trying to get vbo vertex buffer objects working. But i cannot get it to work. Tutorials or simple bare bone examples would be nice.
    http://3das.noeska.com - create adventure games without programming

  2. #2
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  3. #3

    getting started with vbo's

    which method are trying to use? there are many ways to get VBOs work, some code would be nice to see what you are doing wrong.
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  4. #4

    getting started with vbo's

    This is the code i have now:
    First i declare 4 vars:
    Code:
    var 
        FVBO: TGluInt; 
        FVBOPointer: PGlVoid;  
        i: integer; 
        VertexPointer: PVertex;
    Then i initialize the vertex buffer object and fill it with the vertexes making up the triangle.
    Code:
    glGenBuffersARB(1, @FVBO); //create a vertex buffer 
    glBindBufferARB(GL_ARRAY_BUFFER_ARB, FVBO); //bind the buffer 
    glEnableClientState(GL_VERTEX_ARRAY); //enable the buffer 
    
    glBufferDataARB(GL_ARRAY_BUFFER_ARB, 3*SizeOf(TVertex), nil, GL_STATIC_DRAW_ARB); //reserve memory 
    
    FVBOPointer := glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); //get a pointer to the vbo 
    
    VertexPointer    := FVBOPointer; 
    VertexPointer^.X := 1.0; 
    VertexPointer^.Y := -1.0; 
    VertexPointer^.Z := 0.0; 
    inc(Integer(FVBOPointer), SizeOf(TVertex)); 
    
    VertexPointer    := FVBOPointer; 
    VertexPointer^.X := -1.0; 
    VertexPointer^.Y := -1.0; 
    VertexPointer^.Z := 0.0; 
    inc(Integer(FVBOPointer), SizeOf(TVertex)); 
    
    VertexPointer    := FVBOPointer; 
    VertexPointer^.X := 0.0; 
    VertexPointer^.Y := 1.0; 
    VertexPointer^.Z := 0.0; 
    inc(Integer(FVBOPointer), SizeOf(TVertex)); 
    
    glUnmapBufferARB(GL_ARRAY_BUFFER_ARB);
    Now when i want to render it i do:
    Code:
    glInterleavedArrays(GL_V3F, SizeOf(TVertex), nil); 
    glDrawArrays(GL_TRIANGLES, 0, 3 );
    http://3das.noeska.com - create adventure games without programming

  5. #5

    getting started with vbo's

    aren't you supposed to call glEnableClientState before binding or creating it? shouldn't it be th first thing you call?
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  6. #6

    getting started with vbo's

    I changed the possition of that line, but still nothing.

    Also i forgot to post the typedef for PVertex:
    Code:
    type
      PVertex = ^TVertex;
      TVertex = packed record
        X,Y,Z : TGLFloat;
      end;
    http://3das.noeska.com - create adventure games without programming

  7. #7

    getting started with vbo's

    And more importantly: You aren't incrementing your VertexPointer.

    You are doing this:

    Set to 0
    write data
    inc
    Set to 0 again
    write data
    inc
    Set to 0 again
    write data
    inc

    So you are just overwriting one Vertex all the time.

  8. #8

    getting started with vbo's

    changed that to
    Code:
        TVertex(FVBOPointer^).X := -1.0;
        TVertex(FVBOPointer^).Y := 1.0;
        TVertex(FVBOPointer^).Z := 0.0;
        inc(Integer(FVBOPointer), SizeOf(TVertex));
    
    
        TVertex(FVBOPointer^).X := -1.0;
        TVertex(FVBOPointer^).Y := -1.0;
        TVertex(FVBOPointer^).Z := 0.0;
        inc(Integer(FVBOPointer), SizeOf(TVertex));
    
    
        TVertex(FVBOPointer^).X := 1.0;
        TVertex(FVBOPointer^).Y := -1.0;
        TVertex(FVBOPointer^).Z := 0.0;
        inc(Integer(FVBOPointer), SizeOf(TVertex));
    As it turned out the vertexes were all wrong also.
    Now i see a nice white triangle.

    Ok on to something more exiting...
    http://3das.noeska.com - create adventure games without programming

  9. #9

    getting started with vbo's

    The last incrementation is useless and so is the cast to "TVertex".

    If you don't do this usually:
    [pascal]
    var
    a: integer;
    b: ^integer;
    begin
    b := @a;
    integer(b^) := -123;
    end.
    [/pascal]

    You might also have used GL_V2F instead of V3F since you aren't
    using Z anyway.

    Also you could cast the pointer to "cardinal" instead "integer" because
    negative pointers don't make sense (to humans, the computer doesn't care).
    It just sounds more logically.

    Glad its working, now to make it more aesthetic; just giving tips here,
    don't feel upset

  10. #10

    getting started with vbo's

    So instead of making FVBOPointer: PGlVoid; i should make that a PVertex?

    is not your example the same as what i do with TVertex?

    You are right the last increment is useless as nothing new is added. So when used in a loop i should take care that the last time the increment is not done. Ok cardinals are the way to cast pointers to.

    Z was not used for this specific triangle, but might be for another one. (e.g. i was not making a 2d example.) So i decided to use V3F.
    http://3das.noeska.com - create adventure games without programming

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

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