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
    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);

  2. #2
    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.

  3. #3
    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





  4. #4
    Hello Will,

    Thanks for your reply. Well I didn't really see why posting my system specs would result in a better understanding of the problem. The option to format it is code I was looking for in the editor but couldn't find it (not in the quick, neither in the advanced mode). So therefore I could but the correct tags around it since it might differ per forum. So maybe it would be nice to make an Icon in the editor to add the code tags.

    Thanks for the help so far, but it still gives me problems
    @chronozphere, I didn't asked to read the documentation for me. But I am trying for over a week already and cant seem to get it working. I have seen all kind of examples but almost all are C++. I have copied an example from this OpenGL tutorial which compiles but just doesn't display anything and I have no clue why not. So I was just looking for someone who could point me in the right direction.

    Code:
      VertexBuffer: array [0..5] of TVertex2f = (
        (X : 200; Y : 200;),
        (X : 0; Y : 200;),
        (X : 0; Y : 0;),
        (X : 200; Y : 200;),
        (X : 0; Y : 0;),
        (X : 200; Y : 0;)
      );
      ColorBuffer: array [0..5] of TColor3f = (
        (R : 1; G : 0; B : 1),
        (R : 0; G : 0; B : 1),
        (R : 0; G : 1; B : 0),
        (R : 1; G : 0; B : 1),
        (R : 0; G : 1; B : 0),
        (R : 1; G : 1; B : 0)
      );
    
      glEnableClientState(GL_VERTEX_ARRAY);
      glEnableClientState(GL_COLOR_ARRAY);
      glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
      glColorPointer(3, GL_FLOAT, 0, @ColorBuffer[0]);
    
      glDrawArrays(GL_TRIANGLES, 0, Length(VertexBuffer));
    
      glDisableClientState(GL_VERTEX_ARRAY);
      glDisableClientState(GL_COLOR_ARRAY);

  5. #5
    Ok, I'll give you some tips then.

    First of all, can you show me your complete sourcecode? The last post only contains the render code, not the creation of the buffer etc..

    The most confusing part of VBO's is that it uses the functions that were meant for vertex array's. I see that you are passing a pointer to the array to glVertexPointer() and glColorPointer(). This is correct for vertex array's but NOT for VBO's. The functions are used differently. You must pass the data in a glBufferDataARB() call and use 0 as the last parameter for both glVertexPointer and glColorPointer().

    Just google some more and ask more specific questions. You could also check the following tutorial:

    http://playcontrol.net/ewing/jibberj...er_object.html

    I know that VBO's are confusing. You just HAVE to go thourgh one of the tutorials, write down the functions that are used and figure out what happens exactly.

    I may write a VBO tutorial one day, for pascal. Right now, I dont have time for that.

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

  6. #6
    Thanks for giving me tips. I have been playing with it all day again and this is what I have at the moment (but still nothing is drawn)
    (is from: http://www.ozone3d.net/tutorials/opengl_vbo_p2.php, my translation from C++ to Delphi). I checked it with your tutorial and did not see any strange things. My viewwindow is set up from (0,0) - (1024,76

    Code:
    var
      vc: Integer;
      ColorSize, PositionSize : Integer;
    const
      BufferSize = 2;
      POSITION_OBJECT = 0;
      COLOR_OBJECT = 1;
    var
      BufferName: array [0..BufferSize-1] of GLuint;
    begin
    
      glGenBuffersARB := wglGetProcAddress('glGenBuffersARB');
      glBindBufferARB := wglGetProcAddress('glBindBufferARB');
      glBufferDataARB := wglGetProcAddress('glBufferDataARB');
      glDeleteBuffersARB := wglGetProcAddress('glDeleteBuffersARB');
    
      PositionSize := length(VertexBuffer) * SizeOf(TVertex2f);
      ColorSize := length(ColorBuffer) * SizeOf(TColor3f);
    
      vc := Length(VertexBuffer);
    
      // allocate a new buffer
      glGenBuffersARB(1, @BufferName[COLOR_OBJECT]);
      // bind the buffer object to use
      glBindBufferARB(GL_ARRAY_BUFFER_ARB, BufferName[COLOR_OBJECT]);
      glBufferDataARB(GL_ARRAY_BUFFER_ARB, ColorSize, @ColorBuffer[0], GL_STREAM_DRAW);
      glColorPointer(3, GL_UNSIGNED_BYTE, 0, 0);
    
      glGenBuffersARB(1, @BufferName[POSITION_OBJECT]);
      glBindBufferARB(GL_ARRAY_BUFFER_ARB, BufferName[POSITION_OBJECT]);
      glBufferDataARB(GL_ARRAY_BUFFER_ARB, PositionSize, @VertexBuffer[0], GL_STREAM_DRAW);
      glVertexPointer(2, GL_FLOAT, 0, 0);
    
      glEnableClientState(GL_VERTEX_ARRAY);
      glEnableClientState(GL_COLOR_ARRAY);
    
      glDrawArrays(GL_TRIANGLES, 0, vc);
    
      glDisableClientState(GL_VERTEX_ARRAY);
      glDisableClientState(GL_COLOR_ARRAY);
    with data:
    Code:
    type
      TVertex2f = record
        X, Y: TPositionType;
      end;
    
      TColor3f = record
       R, G, B: GLubyte;
      end;
    
    const
      VertexBuffer: array [0..5] of TVertex2f = (
        (X : 0; Y : 0;),
        (X : 200; Y : 0;),
        (X : 200; Y : 200;),
        (X : 200; Y : 200;),
        (X : 0;  Y : 200;),
        (X : 0; Y : 0;)
      );
      ColorBuffer: array [0..5] of TColor3f = (
        (R : 255; G : 0; B : 0),
        (R : 255; G : 255; B : 0),
        (R : 0; G : 255; B : 0),
        (R : 0; G : 255; B : 0),
        (R : 0; G : 0; B : 255),
        (R : 255; G : 0; B : 0)
      );
    Last edited by WhatJac3; 23-09-2010 at 09:47 PM. Reason: additional information

  7. #7
    I noticed the following line:

    Code:
      glBufferDataARB(GL_ARRAY_BUFFER_ARB, ColorSize, @ColorBuffer[0], GL_STREAM_DRAW);
    Have a look at the last GL_STREAM_DRAW parameter. I couldn't find official documentation of this function, so I just quote the tutorial:

    "stream" means the data will be changed every frame (specified once and used once).
    I suggest you change it to GL_STATIC_DRAW, because I think GL_STREAM_DRAW will throw away your data after it is rendered once.

    The rest of your code looks ok.

    Hope this helps.

    Edit: About the WYSIWYG problem, you have to enable those buttons in your profile. Forum -> Forum Actions -> General settings, and then scroll down until you see the "Message Editor Interface" optoin.
    Last edited by chronozphere; 24-09-2010 at 06:43 AM.
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  8. #8
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25
    Quote Originally Posted by WhatJac3 View Post
    Thanks for your reply. Well I didn't really see why posting my system specs would result in a better understanding of the problem. The option to format it is code I was looking for in the editor but couldn't find it (not in the quick, neither in the advanced mode). So therefore I could but the correct tags around it since it might differ per forum. So maybe it would be nice to make an Icon in the editor to add the code tags.
    Hey no problem, I'm here to help. Well the Help Me forum may be nuked soon anyhow. If that happens, don't worry, I'll move your thread over to the Programming -> Graphics forum so it is not lost. (Along with all the other threads too.) Next time you are using the advanced editor, look for an icon that looks like a number sign ala "#". That's the code BB tag button you're looking for. It's not in the quick reply editor unfortunately, but clicking on 'Go Advanced' will keep any quoted text you have and enable all the other nice WYSIWYG buttons.
    Jason McMillen
    Pascal Game Development
    Co-Founder





  9. #9
    What WYSIWUG buttons? Can you please show them in my screenshot? This is what I get when I use the advanced editor:

    ps: I am using FireFox, but my IE8 gives me exactly the same view.
    Attached Images Attached Images

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
  •