Page 3 of 24 FirstFirst 1234513 ... LastLast
Results 21 to 30 of 236

Thread: thinBasic 1.11.x.x

  1. #21
    Thanks Eros,
    i want to try the Simpson figure generator as a test, i have posted before http://www.thinbasic.com/community/s...-as-FreeBasic)

    for now my strategy is to make array of UDT xyz inside thinbasic VertexA() and three Linear arrays arrX, arrY, arrZ to pass to freebasic for filling it with data. then after return from freebasic to put the data inside arrX arrY arrZ into thinbasic VertexA.x VertexA.y VertexA.z
    the example works nicely but when i exit the program i got an error thinbasic has stopped working (in win 7) and a GUI error in winXP. else everything is okay

    to let the example works you will need to put the attached BartSimpsonsData.tbasic in the same folder as the following code , it contains just data (13 KB) like this
    x = ((-5/37 *Sin(61/42-8 *t)-112/41....
    y = ((-9/23 *Sin(38/25-6 *t)-67/38 ....
    and the good thing it is added to inside freebasic code inside the #Compiled ... #EndCompiled Block with #INCLUDE "BartSimpsonsData.tbasic"
    .
    Uses "TBGL"
    'Uses "math"
    
    Function TBMain()
    
    Type Point3D
        x As Single
        y As Single
        z As Single
    End Type
    
    Type Colr
      r As Byte
      g As Byte
      b As Byte
    End Type
    
      Local hWnd      As DWord
      Local FrameRate As Double
      Local i as long 
      ' -- Create and show window
      hWnd = TBGL_CreateWindowEx("Plotting 3D Data in an array using GBuffers- Calculate with freebasic..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
      DWord gbPoints = TBGL_GBufferCreate(%TBGL_POINTS, %TBGL_3D)
        
      Global Nb As DWord = 22619 ' 72*pi/0.01
      ' -- Define data for it
      dim VertexA(Nb) As Point3D ' single
      dim ColorA(Nb) As Colr      ' Byte
      
      'dim VertexA(Nb) As TBGL_TVECTOR3F
      'dim ColorA(Nb)  As TBGL_TRGB
      
      global arrX(Nb) as double
      global arrY(Nb) as double
      global arrZ(Nb) as double
      
      'call freeBasic to fill the arrays with data
      FB_Array_Of_Double(arrX(1), arrY(1), arrZ(1))
      
       for i=1 to Nb
        VertexA(i).x = arrX(i)
        VertexA(i).y = arrY(i)
        VertexA(i).z = arrZ(i)
        ColorA(i).r = 255
        ColorA(i).g = 0
        ColorA(i).b = 0
       next
        
      ' -- 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, 90, 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  
       
    #compiled "===Numric arrays==="
    Function theta(a As Single) As Single
       If a<=0 Then
        Function = 0
        Else
        Function = 1
       End If
    End Function
    
    function FB_Array_Of_Double Cdecl (byref pDouble1 as double, byref pDouble2 as double, byref pDouble3 as double) As long Export
      ' passing a Double ByRef means passing a pointer to the memory location where the first Double is allocated
    	'----------------------------------------------------------------------------
        
        Dim pArray1  As double Ptr
        Dim pArray2  As double Ptr
        Dim pArray3  As double Ptr
        dim N    as Long
       '"We are now inside FreeBasic function"
      '---Get pointer to the first element of the array
        pArray1 = @pDouble1
        pArray2 = @pDouble2
        pArray3 = @pDouble3
        
    Dim x As SINGLE
    Dim y As SINGLE
    Dim z As SINGLE
    Dim t As SINGLE
    Dim Pi As SINGLE
    Pi = 3.141592
    
    FOR N = 0 TO 22618
        #INCLUDE "BartSimpsonsData.tbasic"      
        
        *(pArray1 + N - 1) = x * 0.05
        *(pArray2 + N - 1) = y * 0.05
        *(pArray3 + N - 1) = 0
        'print *(pArray1 + N - 1)
        t = t + 0.01
    next
    
        return 0
        
    end Function
    
    #endcompiled
    
    Attached Files Attached Files

  2. #22
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Great
    And thanks for testing.
    By next week I will publish 1.10.8 for all.

    I will check this evening your examples and why GPF on exit.
    I saw that some FreeBasic programs (both exe or DLL) must have an "End" command in order to properly exit but I have to study it first.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  3. #23
    Eros
    i have found the reason of error: in:
    FOR N = 0 TO 22618
    #INCLUDE "BartSimpsonsData.tbasic"
    *(pArray1 + N - 1) = x * 0.05
    *(pArray2 + N - 1) = y * 0.05
    *(pArray3 + N - 1) = 0

    we replace with:
    FOR N = 0 TO 22618
    #INCLUDE "BartSimpsonsData.tbasic"
    *(pArray1 + N ) = x * 0.05
    *(pArray2 + N ) = y * 0.05
    *(pArray3 + N ) = 0

    and then No error happened

  4. #24
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Great.

    Yes because base pointer is already pointing to the first element of the array.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  5. #25
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    This is the version directly passing UDT array ... in reality passing to FreeBasic byref the first element of the thinBasic UDT array and then using pointers to change all the elements.
    Maybe also better to pass number of elements in such a way to have a dynamic function working with the elements known in thinBasic.

    Note that I had defined Point3D both in thinBasic and FreeBasic.
    Actually it is the only method to share an UDT structure: define in both world.

    Uses "TBGL"'Uses "math"
    
    
    Type Point3D
      x As Single
      y As Single
      z As Single
    End Type
    
    
    Type Colr
      r As Byte
      g As Byte
      b As Byte
    End Type
    
    
    Function TBMain()
    
    
      Local hWnd      As DWord
      Local FrameRate As Double
      Local i         as long
      
      ' -- Create and show window
      hWnd = TBGL_CreateWindowEx("Plotting 3D Data in an array using GBuffers- Calculate with freebasic..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
      DWord gbPoints = TBGL_GBufferCreate(%TBGL_POINTS, %TBGL_3D)
        
      Global Nb As DWord = 22619 ' 72*pi/0.01
      ' -- Define data for it
      dim VertexA(Nb) As Point3D ' single
      dim ColorA(Nb) As Colr      ' Byte
      
      'dim VertexA(Nb) As TBGL_TVECTOR3F
      'dim ColorA(Nb)  As TBGL_TRGB
      
      'call freeBasic to fill the arrays with data
      FB_Array_Of_Point3D(VertexA(1))
      
       for i=1 to Nb
        ColorA(i).r = 255
        ColorA(i).g = 0
        ColorA(i).b = 0
       next
        
      ' -- 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, 90, 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
    
    
    #compiled "===Array of UDT==="
      Type Point3D
        x As Single
        y As Single
        z As Single
      End Type
    
    
      Function theta(a As Single) As Single
        If a<=0 Then
          Function = 0
        Else
          Function = 1
        End If
      End Function
    
    
      function FB_Array_Of_Point3D Cdecl (byref pPoint3D as Point3D) As long Export 
        ' passing first element of an UDT ByRef allows to manage the UDT even if it is an array using some pointer math
        '----------------------------------------------------------------------------
          
          Dim pArray  As Point3D Ptr
    
    
          dim N    as Long
         '"We are now inside FreeBasic function"
        '---Get pointer to the first element of the array
          pArray = @pPoint3D
          
        Dim x As SINGLE
        Dim y As SINGLE
        Dim z As SINGLE
    
    
        Dim t As SINGLE
        Dim Pi As SINGLE
        Pi = 3.141592
    
    
        FOR N = 0 TO 22618
            #INCLUDE ".\BartSimpsonsData.tbasic"
            
            *(pArray + N).x = x * 0.05
            *(pArray + N).y = y * 0.05
            *(pArray + N).z = 0
            'print *(pArray1 + N - 1)
            t = t + 0.01
        next
    
    
          return 0
          
      end Function
    
    
    #endcompiled
    
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by ErosOlmi; 13-08-2019 at 08:59.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  6. #26
    Thank you Eros very much. your method is neat, small and concise
    this extra speed will be useful with fractals such as mandelbrot set, also with perlin noise generators...
    infinite possibilities.

  7. #27
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    The following example is even simpler and still very fast.

    It uses a compiled FreeBasic function passing BYREF the 3 Single element of the UDT.

    The main loop FOR/NEXT is inside thinBasic interpreted code but the hard job is done by FreeBASIC compiled function.
    Only pay attention to t variable that I declared Static to the function so it will retain its value on function exit.

    Uses "TBGL"'Uses "math"
    
    
    Type Point3D
      x As Single
      y As Single
      z As Single
    End Type
    
    
    Type Colr
      r As Byte
      g As Byte
      b As Byte
    End Type
    
    
    Function TBMain()
    
    
      Local hWnd      As DWord
      Local FrameRate As Double
      Local i         as long
      
      ' -- Create and show window
      hWnd = TBGL_CreateWindowEx("Plotting 3D Data in an array using GBuffers- Calculate with freebasic..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
      DWord gbPoints = TBGL_GBufferCreate(%TBGL_POINTS, %TBGL_3D)
        
      Global Nb As DWord = 22619 ' 72*pi/0.01
      ' -- Define data for it
      dim VertexA(Nb) As Point3D ' single
      dim ColorA(Nb) As Colr      ' Byte
        
       for i=1 to Nb
        
        'call freeBasic function to fill the arrays with data
        FB_3SingleByRef(VertexA(i).x, VertexA(i).y, VertexA(i).z)
    
    
        ColorA(i).r = 255
        ColorA(i).g = 0
        ColorA(i).b = 0
       next
        
      ' -- 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, 90, 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
    
    
    #compiled "===Passing 3 single variable ByRef==="
    
    
      Function theta(a As Single) As Single
        If a<=0 Then
          Function = 0
        Else
          Function = 1
        End If
      End Function
    
    
      '----------------------------------------
      function FB_3SingleByRef Cdecl (byref x as single, byref y as single, byref z as single) As long Export
      '----------------------------------------
        Static t As SINGLE  '---<<<< STATIC !
    
    
        Dim Pi As SINGLE
        Pi = 3.141592
    
    
          '---This contain BIG expression too complex for thinBasic interpeter
          #INCLUDE ".\BartSimpsonsData.tbasic"
          
          x = x * 0.05
          y = y * 0.05
          z = 0
          t = t + 0.01
    
    
        return 0
          
      end Function
    
    
    #endcompiled
    
    Attached Files Attached Files
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  8. #28
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    thinBasic 1.10.8.0 released for all.

    In first post of this thread please find download url: https://www.thinbasic.com/community/...Basic-1-10-8-0

    Consider all new features are under development so there will be many changes in next weeks.
    Have fun.
    Last edited by ErosOlmi; 13-08-2019 at 11:08.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  9. #29
    Hi Eros
    i have tried to grasp your shorter version:
    FB_3SingleByRef(VertexA(i).x, VertexA(i).y, VertexA(i).z)
    but still have ambiguity. the older version can be understood easily, but the newest is simpler of course.
    i have noticed also that you have declared the UDT outside the TB main loop, and so it is globally known
    i still run the older 1.10.8.0 and will install the newest shorly
    big thanks

  10. #30
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Even if thinBasic is able to parse UDT definition inside subs/functions ... UDT definition should be defined outside any subs/functions.
    UDT definition is always globally known, it is just a definition and not a variable/memory allocation.

    UDT definition done in thinBasic code is actually not known inside FreeBasic #Compiled/#EndCompiled code.
    In case you need to let both world known about UDT definition, you have to re-declare them.
    Maybe I will be able to work on this aspect in order to let both world know about each other UDT definitions or at least UDT in thinBasic be passed to FreeBasic compiled code.

    Will see.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

Page 3 of 24 FirstFirst 1234513 ... LastLast

Members who have read this thread: 2

Posting Permissions

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