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

Thread: A challenge porting from FreeBasic (and originally from C)

  1. #11
    Member sblank's Avatar
    Join Date
    Feb 2010
    Location
    Wayne City, Illinois
    Posts
    80
    Rep Power
    23

    Porting question from "raw" OpenGL

    I worked on porting my FreeBasic OpenGL program over the weekend and became stuck on the following two lines in the chaptrack function:

    glMultMatrixf @aff(0)
    glGetFloatv GL_TEXTURE_MATRIX, @aff(0)

    The aff() matrix is the affine matrix used in the rotations of the 3D figure. I use the GL_TEXTURE_MATRIX because it is handy and not being used for any other purpose

    Anyway, I'm using a pointer to multiply the aff() matrix by the current transformation/rotation matrix and then storing the newly transformed matrix in GL_TEXTURE_MATRIX. Again, using pointers...

    I am not certain how to do this using TBGL or raw OpenGL in thinBasic... I tried using varptr but obviously did not know what I was doing

    Thanks for any "pointers" you might have,

    Stan

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

    no need to struggle with pointers, as the declaration is made to get the array by reference. So for the two lines, the TB code would look like:
    glMultMatrixf(matrix)
    glGetFloatv(%GL_TEXTURE_MATRIX, matrix)
    

    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
    Member sblank's Avatar
    Join Date
    Feb 2010
    Location
    Wayne City, Illinois
    Posts
    80
    Rep Power
    23
    Fantastic... thanks for the "pointer"

    Seriously, I'll give this a try. ByRef makes sense.

    Cheers,

    Stan

    Quote Originally Posted by Petr Schreiber View Post
    Hi Stan,

    no need to struggle with pointers, as the declaration is made to get the array by reference. So for the two lines, the TB code would look like:
    glMultMatrixf(matrix)
    glGetFloatv(%GL_TEXTURE_MATRIX, matrix)
    
    Petr

  4. #14
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,139
    Rep Power
    733
    I prefer the byref approach over pointers (less typing, same effect), that's why headers are translated this way.

    If you are unsure about parameters, you can always check the headers in the ThinBASIC/Inc directory or ask here of course!

    We had a few iterations of the headers until we found current state, originally there were the pointers everywhere, but I think the current way is more user friendly (once you know BYREF is there ).


    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

  5. #15
    Member sblank's Avatar
    Join Date
    Feb 2010
    Location
    Wayne City, Illinois
    Posts
    80
    Rep Power
    23
    I agree... ByRef is much simpler than trying to use pointers (for me, anyway). Sending the matrix name (ByRef) worked!

    Another question:

    What is the TBGL equivalent of the glutIdle() function? Is that your "while TBGL_IsWindow" function?

    I use glutIdle() in the program I'm trying to port... just curious.

    Thank,

    Stan

    Quote Originally Posted by Petr Schreiber View Post
    I prefer the byref approach over pointers (less typing, same effect), that's why headers are translated this way.

    If you are unsure about parameters, you can always check the headers in the ThinBASIC/Inc directory or ask here of course!

    We had a few iterations of the headers until we found current state, originally there were the pointers everywhere, but I think the current way is more user friendly (once you know BYREF is there ).


    Petr

  6. #16
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,139
    Rep Power
    733
    Hi Stan,

    it's up to you how you structure code in TBGL, the endless loop is just one approach possible.

    The another could be to use the periodic function and base the organization on that.

    Here minimal example, hWnd and FrameRate are passed to idle and input functions just in case you would like to use it, but it is not necessary of course.
    Uses "TBGL"    
    
    Global angle As Double
    
    Function TBMain()
      Local hWnd      As DWord
      Local FrameRate As Double
      
      ' -- Create and show window
      hWnd = TBGL_CreateWindowEx("TBGL script - press ESC to quit", 640, 480, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX) 
      TBGL_ShowWindow 
    
      ' -- Initialize lighting
      TBGL_UseLighting(%TRUE)
      TBGL_UseLightSource(%GL_LIGHT0, %TRUE)
    
      TBGL_SetLightParameter(%GL_LIGHT0, %TBGL_LIGHT_POSITION, 15, 10, 15, 1)
    
      ' -- Resets status of all keys 
      TBGL_ResetKeyState()
    
      TBGL_BindPeriodicFunction( hWnd, "funRender", 10 )
      TBGL_ProcessPeriodicFunction(hWnd)
    
      TBGL_DestroyWindow
    End Function 
    
    ' -- Do any calculations here
    Function funIdle( hWnd As DWord, frameRate As Double )
                                   
      angle += 90/FrameRate
      
    End Function
    
    ' -- Handle input here
    Function funInput( hWnd As DWord, frameRate As Double )
    
      If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then 
        TBGL_UnBindPeriodicFunction(hWnd)
        Exit Function
      End If
    
    End Function
    
    Function funRender()
    
      Dim hWnd As DWord = TBGL_CallingWindow
      Dim FrameRate As Double
      
      frameRate = TBGL_GetFrameRate    
        
      ' -- Process input
      funIdle( hWnd, FrameRate)
      
      ' -- Process calculations
      funInput( hWnd, FrameRate )
      
      FrameRate = TBGL_GetFrameRate
    
      TBGL_ClearFrame 
        TBGL_Camera(15, 15, 15, 0, 0, 0)
        
        TBGL_Rotate(angle,0,1,0)
        TBGL_Color(255, 128, 0)
        TBGL_Box(1, 1, 1)
    
      TBGL_DrawFrame   
    
    End Function
    

    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

  7. #17
    Member sblank's Avatar
    Join Date
    Feb 2010
    Location
    Wayne City, Illinois
    Posts
    80
    Rep Power
    23
    Hi Petr,

    Very nice! This should help immensely...

    When I finish the translation, I'll have to list you as a co-author

    Thank you very much for the tip... and for the elegant program example!

    Stan

    Quote Originally Posted by Petr Schreiber View Post
    Hi Stan,

    it's up to you how you structure code in TBGL, the endless loop is just one approach possible.

    The another could be to use the periodic function and base the organization on that.

    Here minimal example, hWnd and FrameRate are passed to idle and input functions just in case you would like to use it, but it is not necessary of course.
    Uses "TBGL"    
    
    Global angle As Double
    
    Function TBMain()
      Local hWnd      As DWord
      Local FrameRate As Double
      
      ' -- Create and show window
      hWnd = TBGL_CreateWindowEx("TBGL script - press ESC to quit", 640, 480, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX) 
      TBGL_ShowWindow 
    
      ' -- Initialize lighting
      TBGL_UseLighting(%TRUE)
      TBGL_UseLightSource(%GL_LIGHT0, %TRUE)
    
      TBGL_SetLightParameter(%GL_LIGHT0, %TBGL_LIGHT_POSITION, 15, 10, 15, 1)
    
      ' -- Resets status of all keys 
      TBGL_ResetKeyState()
    
      TBGL_BindPeriodicFunction( hWnd, "funRender", 10 )
      TBGL_ProcessPeriodicFunction(hWnd)
    
      TBGL_DestroyWindow
    End Function 
    
    ' -- Do any calculations here
    Function funIdle( hWnd As DWord, frameRate As Double )
                                   
      angle += 90/FrameRate
      
    End Function
    
    ' -- Handle input here
    Function funInput( hWnd As DWord, frameRate As Double )
    
      If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then 
        TBGL_UnBindPeriodicFunction(hWnd)
        Exit Function
      End If
    
    End Function
    
    Function funRender()
    
      Dim hWnd As DWord = TBGL_CallingWindow
      Dim FrameRate As Double
      
      frameRate = TBGL_GetFrameRate    
        
      ' -- Process input
      funIdle( hWnd, FrameRate)
      
      ' -- Process calculations
      funInput( hWnd, FrameRate )
      
      FrameRate = TBGL_GetFrameRate
    
      TBGL_ClearFrame 
        TBGL_Camera(15, 15, 15, 0, 0, 0)
        
        TBGL_Rotate(angle,0,1,0)
        TBGL_Color(255, 128, 0)
        TBGL_Box(1, 1, 1)
    
      TBGL_DrawFrame   
    
    End Function
    
    Petr

Page 2 of 2 FirstFirst 12

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
  •