Results 1 to 10 of 16

Thread: Optimize drawing 10.000 2D-lines with VBO?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Optimize drawing 10.000 2D-lines with VBO?

    System: Windows Vista, AMD 64 X2 Dual Core 2.7 Ghz, ATI Radeon 2600 PRO HD
    Compiler/IDE: Delphi 2009 for Win32
    API: OpenGL

    Hello,

    I am trying to optimize my code since it seems to be rather slow. I am drawing 10.000 lines and I heard that the usage of a VBO would be drastically faster. But I have some problems with it. So maybe someone could help me since I can't find good examples/tutorials. Maybe someone can help me with my little example. I try to draw 2 lines:
    (0,0) - (100,100) and (0,100) - (100,0).

    This is what I have so far:

    Code:
    var:
      arrLines: array[4] of array [2] of GLFloat;
      FVBO: GLUInt; 
    begin
      glGenBuffers(1, @FVBO);
      glBindBufferARB(GL_ARRAY_BUFFER, FVBO);
      glEnableClientState(GL_VERTEX_ARRAY);
      glVertexPointer(2, GL_FLOAT, 0, ); // What should be here?
    
      //Initialize array:
        arrlines[0][0] := 0;
        arrlines[0][1] := 0;
        arrlines[1][0] := 100;
        arrlines[1][1] := 100;
        arrlines[2][0] := 0;
        arrlines[2][1] := 100;
        arrlines[3][0] := 100;
        arrlines[3][1] := 0;
      //Draw the lines
    
        glDrawElements(GL_LINES, 2*4 , GL_FLOAT, arrLines); //Is this correct?
        glDisableClientState(GL_VERTEX_ARRAY);

    Please help and thanks in advance
    Last edited by WhatJac3; 23-09-2010 at 04:14 PM.

  2. #2
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45
    Quote Originally Posted by WhatJac3 View Post
    glVertexPointer(2, GL_FLOAT, 0, ); // What should be here?
    To answer that, and I admit I am no good at OpenGl, I would say 0. See [URL="http://www.opengl.org/sdk/docs/man/xhtml/glVertexPointer.xml"]

    from their description I would assume where the first variable in the array is? Please correct me, I think I am probably wrong here, but you never know. It never hurts to try/help? As the expression kind of goes... I'm tired. Maybe I should just go to sleep already.

    edit:
    one other thing, what do you specifically mean by VBO?
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

  3. #3
    OpenGL rendering with VBO's is quite confusing. Seems like you're mixing things up.
    You're missing a glBufferDataARB(). That function is used to fill the buffer with data.
    In your code, you send the vertex data to the draw call, which is wrong. The fourth parameter of glDrawElements is a pointer to the array of indices.

    This tutorial shows how to use VBO's to render indexed geometry. For lines, you don't really want indexed geometry so you have to dig a little further yourself. Check out this tutorial:


    http://www.songho.ca/opengl/gl_vbo.html


    Also have a look at their vertex array's tutorial. That may give you some ideas about the differences between VBO's and vertex arrays, because people confuse those two often.

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

  4. #4
    I expected to do something wrong. So VBO is the thing I am looking for for speed improvement?
    Thanks for the link but it is in C++ code again and that is confusing for me (pointer things and such). Isn't there a good pascal example? (I am looking for that for over a week already, so therefore I posted it here, since all those C++ example aint doing it for me).

    And while we are at it? What would be better? VBO or PBO?
    I want to do a lot with transparency.
    Last edited by WhatJac3; 23-09-2010 at 12:08 AM.

  5. #5
    So it should be more like this? But I still have problems on 3 lines (4 parameters in total)

    Code:
    glGenBuffersARB(1, @FVBO);
      glBindBufferARB(GL_ARRAY_BUFFER_ARB, FVBO);
      glBufferDataARB(GL_ARRAY_BUFFER_ARB, , ,GL_DYNAMIC_DRAW_ARB); //2nd and 3th parameter
      glEnableClientState(GL_VERTEX_ARRAY);
      glVertexPointer(2, GL_FLOAT, 0, ); // 4th parameter?
    
      arrlines[0][0] := 0;
      arrlines[0][1] := 0;
      arrlines[1][0] := 100;
      arrlines[1][1] := 100;
      arrlines[2][0] := 0;
      arrlines[2][1] := 100;
      arrlines[3][0] := 100;
      arrlines[3][1] := 0;
    
      glDrawElements(GL_LINES, , GL_FLOAT, @arrLines[0][0]); //Second parameter?
      glDisableClientState(GL_VERTEX_ARRAY);
    
      // bind with 0, so, switch back to normal pointer operation
      glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
      glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
      glDeleteBuffersARB(1, &vboId);

  6. #6
    Thanks for the link but it is in C++ code again and that is confusing for me (pointer things and such). Isn't there a good pascal example? (I am looking for that for over a week already, so therefore I posted it here, since all those C++ example aint doing it for me).
    Just get used to it. You won't get far if you only want to read pascal-tutorials because there aren't many. Moreover, there is almost no difference between pascal and C++ in that example, because it's just a few function calls. Just look at the global flow of the program and look up the documentation for each function and read it carefully. Also, browse these forums because I think there are more people who had problems with VBO's.

    PBO's are totally different and I have not used them much. My guess would be that it's not the fastest way to draw lines.

    The last parameter of glVertexPointer() is the offset into the given vertex array. If you want to use your entire vertex array, just set this to zero. That was all covered in the link I gave you. The only way to know how to use functions is read the documentation. I'm not going to do that for you.

    Good luck!
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  7. #7
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25
    Hi WhatJac3, I just modified your posts slightly to put your code into a code block. You should really try to use them as they help when you are trying to show your programming code nicely on the forums.

    Also, you have not followed the Help Me! forum rules for posting in this special forum. Please read item 3 from the FAQ for a clear definition of what I mean. However, since this forum here may be removed and each individual thread will be moved to a more appropriate on-topic forum instead, I've chosen to forgo the traditional warning. You may read about the decisions behind this at the following thread.

    Thanks for your attention and I hope that you get the help you require for your project.
    Jason McMillen
    Pascal Game Development
    Co-Founder





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
  •