Page 2 of 2 FirstFirst 12
Results 11 to 18 of 18

Thread: vertex buffer objects for OpenGl 1.5

  1. #11
    Hi Petr, DirectuX
    i remember Petr said that GBuffer is created using glDrawArrays, but it is not known that its coupled with glVertexPointer/glColorPointer/... without VBO context, or created with VBO Context and buffered to GPU with glBufferData, something like that. it is said glInterleavedArrays can speed the execution.
    but there is a problem :
    the arrays presented to Gbuffer is either VertexArray() [, ColorArray(), NormalArray(), TexCoordArray() ])
    but i can't use the data type like this

    Type Point3D
    x As Single
    y As Single
    z As Single
    r As Byte
    g As Byte
    b As Byte
    End Type

    i am restricted to something like :
    Type PointPosition
    x As Single
    y As Single
    z As Single
    End Type
    Type PointColor
    r As Byte
    g As Byte
    b As Byte
    End Type

    this works while the later does not work
    Uses "TBGL"
    Uses "math"
    
    Type PointPosition
      x As Single
      y As Single
      z As Single 
    End Type 
    Type PointColor
      r As Byte
      g As Byte
      b As Byte
    End Type 
     
    Function TBMain()
    
      Local hWnd      As DWord
      Local FrameRate As Double
       
      ' -- Create and show window
      hWnd = TBGL_CreateWindowEx("Plotting 3D Data in an array using GBuffers - press ESC to quit", 600, 600, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX) 
      TBGL_ShowWindow  
       
      TBGL_BackColor 255,255,255 
      TBGL_SetDrawDistance 250
     
      ' -- Create 3D points buffer
      'Dim  gbPoints As DWord = TBGL_GBufferCreate(%TBGL_POINTS, %TBGL_3D)
      Dim  gbPoints As DWord = TBGL_GBufferCreate(%TBGL_TRIANGLES, %TBGL_3D)
      
      Global Nb As DWord = 3 
      
      ' -- Define data for it
      Global VertexA(Nb) As PointPosition 'TBGL_TVECTOR3F
      Global ColorA(Nb)  As PointColor 'TBGL_TRGB
      
    VertexA(1).x = 0: VertexA(1).y = 1: VertexA(1).z = 0
    VertexA(2).x = -1: VertexA(2).y = -1: VertexA(2).z = 0 
    VertexA(3).x = 1: VertexA(3).y = -1: VertexA(3).z = 0
    
    ColorA(1).r = 255: ColorA(1).g = 0: ColorA(1).b=0
    ColorA(2).r = 0: ColorA(2).g = 255: ColorA(2).b=0
    ColorA(3).r = 0: ColorA(3).g = 0: ColorA(3).b=255
     
      ' -- Create buffer dynamically linked to the arrays above
      TBGL_GBufferDefineFromArray(gbPoints, %TBGL_DYNAMIC, CountOf(VertexA), VertexA(1), ColorA(1))
      
      ' -- Resets status of all keys 
      TBGL_ResetKeyState()
      'TBGL_PointSize 2
      
      ' -- Main loop
      While TBGL_IsWindow(hWnd)
      'init 
        FrameRate = TBGL_GetFrameRate
        
        TBGL_ClearFrame
          TBGL_Camera(0, 0, 5, 0, 0, 0)
           
          ' -- Turn triangle
          TBGL_Rotate GetTickCount/50, 0, 1, 0
          'TBGL_Scale 0.6, 0.6, 0.6
                                         
          ' -- Render it                              
          TBGL_GBufferRender(gbPoints)   
            
        TBGL_DrawFrame
     
        ' -- ESCAPE key to exit application
        If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While
     
      Wend        
      ' -- Destroying the buffer is not necessary,
      ' -- the garbage collector will take care of it
     
      ' -- Destroy window
      TBGL_DestroyWindow
    End Function
    
    this does not work:
    Uses "TBGL"
    Uses "math"
    
    Type Point3D
      x As Single
      y As Single
      z As Single
      r As Byte
      g As Byte
      b As Byte 
    End Type 
     
    Function TBMain()
    
      Local hWnd      As DWord
      Local FrameRate As Double
       
      ' -- Create and show window
      hWnd = TBGL_CreateWindowEx("Plotting 3D Data in an array using GBuffers - press ESC to quit", 600, 600, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX) 
      TBGL_ShowWindow  
       
      TBGL_BackColor 255,255,255 
      TBGL_SetDrawDistance 250
     
      ' -- Create 3D points buffer
      'Dim  gbPoints As DWord = TBGL_GBufferCreate(%TBGL_POINTS, %TBGL_3D)
      Dim  gbPoints As DWord = TBGL_GBufferCreate(%TBGL_TRIANGLES, %TBGL_3D)
      
      Global Nb As DWord = 3 
      
      ' -- Define data for it
      Global data(Nb) As Point3D 'TBGL_TVECTOR3F
      'Global ColorA(Nb)  As PointColor 'TBGL_TRGB
      
    data(1).x = 0: data(1).y = 1: data(1).z = 0
    data(2).x = -1: data(2).y = -1: data(2).z = 0 
    data(3).x = 1: data(3).y = -1: data(3).z = 0
    
    data(1).r = 255: data(1).g = 0:   data(1).b=0
    data(2).r = 0:   data(2).g = 255: data(2).b=0
    data(3).r = 0:   data(3).g = 0:   data(3).b=255
    'MsgBox(0, Str$(CountOf(data)))
      ' -- Create buffer dynamically linked to the arrays above
      TBGL_GBufferDefineFromArray(gbPoints, %TBGL_DYNAMIC, CountOf(data), data(1).x, data(1).r)
      
      ' -- Resets status of all keys 
      TBGL_ResetKeyState()
      'TBGL_PointSize 2
      
      ' -- Main loop
      While TBGL_IsWindow(hWnd)
      'init 
        FrameRate = TBGL_GetFrameRate
        
        TBGL_ClearFrame
          TBGL_Camera(0, 0, 5, 0, 0, 0)
           
          ' -- Turn triangle
          TBGL_Rotate GetTickCount/50, 0, 1, 0
          'TBGL_Scale 0.6, 0.6, 0.6
                                         
          ' -- Render it                              
          TBGL_GBufferRender(gbPoints)   
            
        TBGL_DrawFrame
     
        ' -- ESCAPE key to exit application
        If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While
     
      Wend        
      ' -- Destroying the buffer is not necessary,
      ' -- the garbage collector will take care of it
     
      ' -- Destroy window
      TBGL_DestroyWindow
    End Function
    
    also i suggest to let the color type Single , since it is hard coded as byte.

  2. #12
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Hi Primo,

    GBuffers are "abstraction for geometry definition and rendering". The fact they use Vertex Arrays internally now is an implementation detail which might or might not change anytime on the future.

    With that I want to say - let's not restrict our vision with what we have. It can be expanded, improved, reworked.

    Of course it does not work now, because the documentation indicates this is not one of the valid uses - now.

    I could keep the current TBGL_GBufferDefineFromArray, and add different TBGL_GBufferDefine* function to work with interleaved format, for example. Just thinking out loud.

    Just let me know if you see any benefit in this.

    DirectuX - I think it is important to collect inspiration from users continuously, not just once all issues are resolved. I see no harm with adding them to the issue list as they come.


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #13
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Primo,

    could you please explain more what do you mean by "also i suggest to let the color type Single , since it is hard coded as byte."?

    Do you mean you would like to specify color channels in range 0.0 - 1.0 as a 32bit floating point?


    Thank you,
    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  4. #14
    Hi Petr, yes TBGL_GBufferDefine will be appropriate
    regarding the single versus Byte,
    this works:
    Type PointColor
      r As Byte
      g As Byte
      b As Byte
    End Type
    
    while this:
    Type PointColor
      r As Single
      g As Single
      b As Single 
    End Type
    
    does not work

    so it is hard coded.
    Do you mean you would like to specify color channels in range 0.0 - 1.0 as a 32bit floating point?
    Yes, the reason is what if we need more than the eye can see, also with single we have more freedom .
    i remember the perlin noise example posted 2 years ago using byte for color channels in a gbuffer example gives different results than when we use single for color in an opengl example

  5. #15
    Quote Originally Posted by Petr Schreiber View Post
    Hi Primo,

    GBuffers are "abstraction for geometry definition and rendering". The fact they use Vertex Arrays internally now is an implementation detail which might or might not change anytime on the future.

    With that I want to say - let's not restrict our vision with what we have. It can be expanded, improved, reworked.

    Of course it does not work now, because the documentation indicates this is not one of the valid uses - now.

    I could keep the current TBGL_GBufferDefineFromArray, and add different TBGL_GBufferDefine* function to work with interleaved format, for example. Just thinking out loud.

    Just let me know if you see any benefit in this.

    DirectuX - I think it is important to collect inspiration from users continuously, not just once all issues are resolved. I see no harm with adding them to the issue list as they come.


    Petr
    indeed Petr, I've just entierly left the choice to Primo, it is his code example after all
    ThinBasic 1.11.6.0 ALPHA - Windows 8.1 x64

  6. #16
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Primo,

    well, it is documented behaviour. If you want, I can add TBGL_tRGB_f32 and TBGL_tRGBA_f32 for 32bit floating point colors. Deal?


    Petr
    Last edited by Petr Schreiber; 23-01-2020 at 21:48.
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  7. #17
    Thanks Petr,
    TBGL_tRGB_f32 and TBGL_tRGBA_f32 for 32bit floating point colors.
    this is a nice suggestion. Deal.

  8. #18
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Hi primo,

    I added the support for single color, you can grab new TBGL here:
    https://github.com/ThinBASIC/thinBas...s/tag/1.11.2.3

    Will be present in next release

    The interleaved arrays need deeper thought, so I will switch now to another issue we discussed with DirectuX and then will get back to interleaved.


    Petr
    Last edited by Petr Schreiber; 24-01-2020 at 20:25.
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 4
    Last Post: 31-10-2012, 19:31
  2. stencil buffer question
    By largo_winch in forum TBGL module by Petr Schreiber
    Replies: 16
    Last Post: 13-09-2011, 11:41
  3. how to make "smooth openGL objects"?
    By Lionheart008 in forum TBGL General
    Replies: 8
    Last Post: 16-11-2010, 11:34
  4. How to read the keyboard buffer?
    By Michael Hartlef in forum thinBasic General
    Replies: 7
    Last Post: 18-05-2009, 08:47
  5. PowerBasic: 6th post from Bob about objects
    By ErosOlmi in forum Power Basic
    Replies: 2
    Last Post: 08-08-2008, 17:30

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

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