Results 1 to 8 of 8

Thread: Few functions types

  1. #1
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,155
    Rep Power
    736

    Few functions types

    Hi,

    The DECLARE statement is definitely impressive, but
    it could be nice if functions like this could be declared:

    DECLARE SUB glVertex3f                 LIB "opengl32.dll" ALIAS "glVertex3f"               (BYVAL x AS SINGLE, BYVAL y AS SINGLE, BYVAL z AS SINGLE)
    
    ( 3 single parameters )

    DECLARE SUB glColor4f                  LIB "opengl32.dll" ALIAS "glColor4f"                (BYVAL red AS SINGLE, BYVAL green AS SINGLE, BYVAL blue AS SINGLE, BYVAL alpha AS SINGLE)
    
    (4 single parameters)

    DECLARE FUNCTION mciSendString LIB "WINMM.DLL" ALIAS "mciSendStringA" (lpstrCommand AS ASCIIZ, lpstrReturnString AS ASCIIZ, BYVAL uReturnLength AS DWORD, BYVAL hwndCallback AS DWORD) AS LONG
    
    ( ASCIIZ/STRING and numeric parameters )

    Thanks,
    Psch
    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

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

    Few functions types

    Psch,

    can you please give me an example script (no more than 5 lines if possible) I can use to see if declare is working? In this way I can make some tests.

    Regarding ASCIIZ passed as reference, it is like passing a DWORD. For example you can declare mciSendString in this way:
    DECLARE FUNCTION mciSendString    LIB "WINMM.DLL"     ALIAS "mciSendStringA"    (lpstrCommand AS dword, lpstrReturnString AS dword, BYVAL uReturnLength AS DWORD, BYVAL hwndCallback AS DWORD) AS LONG
    
    and passing parameters like: STRPTR(AnyNullTerminatedString)
    DIM SendStr AS STRING = "Play ALIAS WhatEvere wait"
    SendStr += chr$(0)
    mciSendString(strptr(SendStr), %NULL, %NULL, %NULL)
    
    or something like:
          SendStr = "set cdaudio door open" + chr$(0)
          mciSendString(strptr(SendStr), %NULL, %NULL, %NULL)
    
    Let me know.
    Eros
    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. #3
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,155
    Rep Power
    736

    Few functions types

    Hi Eros,

    that MCI trick works perfectly !

    Here is code ( I'm sorry, it's more than 5 lines )

    Uses "TBGL"
    
    
    DIM i AS LONG
    
    DECLARE function  glVertex3f                 LIB "opengl32.dll" ALIAS "glVertex3f"               (BYVAL x AS single, BYVAL y AS single, BYVAL z AS single) as long
    DECLARE FUNCTION  glColor4f                  LIB "opengl32.dll" ALIAS "glColor4f"                (BYVAL red AS SINGLE, BYVAL green AS SINGLE, BYVAL blue AS SINGLE, BYVAL alpha AS SINGLE) AS LONG
    
    TBGL_CreateWindow              ' Creates OpenGL window, it returns handle
    TBGL_ShowWindow      ' Shows the window
    
    FOR i = 1 TO 360              ' 360 iterations = 360 frames
        TBGL_ClearFrame              ' Prepares clear frame
        TBGL_Camera 0,0,5,0,0,0       ' Setups camera to look from 0,0,5 to 0,0,0
    
        TBGL_BeginPoly %GL_TRIANGLES  ' Starts polygon definition based on triangles
            glColor4f (1,0,0,1)       ' Sets RGBA color
            glVertex3f (-1,-1,0)      ' Adds vertex
            glColor4f (0,1,0,1)
            glVertex3f  (1,-1,0)
            glColor4f (0,0,1,1)
            glVertex3f  (0, 1,0)
        TBGL_EndPoly               ' Ends polygon definition
    
        TBGL_DrawFrame               ' Swaps the buffers - displays rendered image
    NEXT
    TBGL_DestroyWindow               ' Closes OpenGL window
    
    Hope it's representative example


    Thanks,
    Psch
    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. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,818
    Rep Power
    10

    Few functions types

    OK, thanks. I will have a look and see what I can do.

    Regarding ASCIIZ parameters, remember you can get back values also preparing enough space in the returing ASCIIZ. For example:
    DECLARE FUNCTION GetShortPathName LIB "KERNEL32.DLL"  ALIAS "GetShortPathNameA" (lpszLongPath AS dword, lpszShortPath AS dword, BYVAL cchBuffer AS LONG) AS LONG
      
    DIM szIn AS STRING = "C:\Program Files\Adobe\Acrobat 5.0\Resource\ENUtxt.pdf" &  CHR$(0)
    DIM szOut AS STRING = STRING$(%MAX_PATH + 1, CHR$(0))
    GetShortPathName(STRPTR(szIn), STRPTR(szOut), %MAX_PATH + 1)
    MSGBOX 0, szOut
    
    %MAX_PATH will be defined in next version
    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. #5
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,818
    Rep Power
    10

    Few functions types

    I think to have fixed SINGLE numeric type.
    Please download again thinBasic 1.0.7.1 from:
    http://www.thinbasic.com/public/prod...ic_1.0.7.1.zip

    Let me know.
    Ciao
    Eros


    PS: you forgot TBGL_Rotate i,1,1,1 in your example loop
    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. #6
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,155
    Rep Power
    736

    Few functions types

    Hi Eros,

    The glVertex3f and glColor4f seems to work as it should - that'ts really great.
    Many OpenGL statements are using similar syntax so I can access them directly now :
    Uses "TBGL"
    
    
    DIM i AS LONG
    
    %GL_COLOR_BUFFER_BIT                = &H00004000
    %GL_DEPTH_BUFFER_BIT                = &H00000100
    DECLARE function  glVertex3f                 LIB "opengl32.dll" ALIAS "glVertex3f"               ( x AS single,  y AS single,  z AS single) as long
    DECLARE FUNCTION  glColor4f                  LIB "opengl32.dll" ALIAS "glColor4f"                ( red AS SINGLE,  green AS SINGLE,  blue AS SINGLE,  alpha AS SINGLE) AS LONG
    DECLARE FUNCTION  glBegin                    LIB "opengl32.dll" ALIAS "glBegin"                  (BYVAL mode AS DWORD) As Long
    DECLARE FUNCTION  glEnd                      LIB "opengl32.dll" ALIAS "glEnd"                    () AS LONG
    DECLARE FUNCTION  glRotatef                  LIB "opengl32.dll" ALIAS "glRotatef"                (BYVAL angle AS SINGLE, BYVAL x AS SINGLE, BYVAL y AS SINGLE, BYVAL z AS SINGLE) AS LONG
    DECLARE FUNCTION  glClear                    LIB "opengl32.dll" ALIAS "glClear"                  (BYVAL mask AS DWORD) AS long
    DeCLARE FUNCTION  glLoadIdentity             LIB "opengl32.dll" ALIAS "glLoadIdentity"           () AS LONG
    
    DECLARE FUNCTION  gluLookAt                  LIB "glu32.dll"    ALIAS "gluLookAt"                (BYVAL eyex AS DOUBLE, BYVAL eyey AS DOUBLE, BYVAL eyez AS DOUBLE, BYVAL centerx AS DOUBLE, BYVAL centery AS DOUBLE, BYVAL centerz AS DOUBLE, BYVAL upx AS DOUBLE,BYVAL _
    upy AS DOUBLE, BYVAL upz AS DOUBLE) AS LONG
    
    
    TBGL_CreateWindow              ' Creates OpenGL window, it returns handle
    TBGL_ShowWindow                ' Shows the window
    
    For i = 1 to 360
        
        glClear (%GL_COLOR_BUFFER_BIT OR %GL_DEPTH_BUFFER_BIT)
        glLoadIdentity
        
        gluLookAt (0,0,5,0,0,0,0,1,0)     ' Setups camera to look from 0,0,5 to 0,0,0
        
        glRotatef (i,1,1,1)
        
        glBegin %GL_TRIANGLES  ' Starts polygon definition based on triangles
            glColor4f (1,0,0,1)       ' Sets RGBA color
            glVertex3f (-1,-1,0)      ' Adds vertex
            glColor4f (0,1,0,1)
            glVertex3f  (1,-1,0)
            glColor4f (0,0,1,1)
            glVertex3f  (0, 1,0)
        glEnd              ' Ends polygon definition
    
        TBGL_DrawFrame               ' Swaps the buffers - displays rendered image
    next 
    TBGL_DestroyWindow               ' Closes OpenGL window
    
    Thanks a lot,
    Psch

    P.S. No I didn't forgot , I just eliminated unnecessary code ( well I could delete even the main loop and add sleep before tbgl_DeleteWindow )
    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. #7
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,155
    Rep Power
    736

    Few functions types

    I forgot one thing ,

    here are converted headers for OpenGL 1.1, TBGL module is needed only to create, display,kill window and to swap the buffers.

    I haven't tested all the functions, but at least the majority should work.

    Enjoy,
    Psch
    Attached Files Attached Files
    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

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

    Few functions types

    Wow, that's cool.

    Please remember API interface is quite unstable and I will need to change it in some part. For numeric parameters there should not be big problems but for ASCIIZ and in general string buffers I will need to change and double check again all. BYVAL and BYREF are not 100% managed. In any case the whole proces seems working, just few refine are missing.

    Also we are trying to manage ASCIIZ type natively as thinBasic native data type. If we will be able to implement this, also API interface will be more easy and VARPTR or STRPTR will not be needed anymore.

    Ciao
    Eros
    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

Similar Threads

  1. Types
    By kryton9 in forum TBGL General
    Replies: 8
    Last Post: 26-11-2006, 00:36

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
  •