Page 1 of 4 123 ... LastLast
Results 1 to 10 of 40

Thread: FBGFX module for thinBasic, to handle 2D graphics

  1. #1

    FBGFX module for thinBasic, to handle 2D graphics

    Hi,

    I started developing FBGFX right away, when Eros gave me the full source to it.
    I've now added few commands to it, and it works nicely.

    Here's an example code what it looks like:

    [code=thinbasic]'**********************
    '** FBGFX Example #1 **
    '**********************

    uses "FBGFX"

    FBGFX_ScreenRes(320,240,32) 'Create FBGFX-window (width, height, dept)

    dim t
    dim x
    dim y
    dim c

    while FBGFX_InKey() <> "q" 'Program runs until "q" is pressed

    x = 160 + sin(c) * 40
    y = 120 + cos(c) * 40
    c = c + .01

    FBGFX_Pset(x,y,FBGFX_RGB(255,255,255)) 'This function draws pixel on the screen
    FBGFX_Circle(x,y,16,FBGFX_RGB(255,50,50)) 'This draws circle ( who would've known ;o )
    FBGFX_Circle(x,y,32,FBGFX_RGB(255,0,255))

    FBGFX_Sync(1) 'Syncronize screen
    FBGFX_Cls() 'And then clear it

    wend[/code]

    Developing this is so wonderful! And if someone takes it away from me, I will die! :<
    Just love making this! ^^
    And I just wanted to make own topic for this, so sorry if it disturbes you.

    FBGFX module is attached in this post.

    Thanks,
    misthema.
    Attached Files Attached Files
    ¯\_†_/¯º¯¹¯²¯³¯\_†_/¯³¯²¯¹¯º¯\_†_/¯

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

    Re: FBGFX module for thinBasic, to handle 2D graphics

    Perfect mistema. Nice job!

    A little note. In thinBasic, if you do not define a specific type for variable declaration, variable is defined as VARIANT. VARIANTs are very powerful kind of data because they can store almost anything but are also quite slow due to the time needed to manage thir complexity. So you can get a little speed improvement declaring variable with type like:

    [code=thinbasic]dim t as double
    dim x as double
    dim y as double
    dim c as double[/code]

    Ciao and thanks again.
    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
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404

    Re: FBGFX module for thinBasic, to handle 2D graphics

    All of you creating these fantastic modules, thanks. My hats off to you and the work you guys are doing!
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

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

    Re: FBGFX module for thinBasic, to handle 2D graphics

    Thanks misthema,

    you are fast, hope you enjoy being parent of next thinBASIC module
    New sample is nice and fast on my PC, good job!


    Thanks,
    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. #5
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    159

    Re: FBGFX module for thinBasic, to handle 2D graphics

    good work.

    Perhaps FBGFX_GraphicWindow would be a better name than FBGFX_screenres.

    only thing i would add is some equates for screenres colour depth

    %FBGFX_DEPTH16 = 16
    %FBGFX_DEPTH24 = 24
    %FBGFX_DEPTH32 = 32

    and the sync could use

    %FBGFX_SYNCON = 1
    %FBGFX_SYNCOFF = 0

    Just Ideas

    Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

  6. #6

    Re: FBGFX module for thinBasic, to handle 2D graphics

    Thanks everyone!

    Good ideas Abraxas. I might do so. I'll let you know more as soon as possible!

    Thanks again,
    misthema.
    ¯\_†_/¯º¯¹¯²¯³¯\_†_/¯³¯²¯¹¯º¯\_†_/¯

  7. #7

    Re: FBGFX module for thinBasic, to handle 2D graphics

    Hi,

    I'm a bit worried about the speed.. The next plasma-like example runs very slow at higher resolution on my computer.
    Could you guys test this and say is it slow or not.

    [code=thinbasic]'Plasma-like effect with FBGFX
    uses "FBGFX"

    Dim w,h As Double
    w=200
    h=150

    FBGFX_ScreenRes(w,h,32,2)

    Dim x,y,page As Double
    Dim c,t As Double

    while FBGFX_InKey() <> "q" 'Program runs until "q" is pressed
    t=t+1
    For x = 0 To w
    For y = 0 To h

    c= (Sin((x+y+t)/100)+Cos((x-t)/100)+Cos((y-t)/100)+Cos((x-y+t)/100))*2+Sin(t/100)*15
    FBGFX_PSet(x,y,Rgb(Sin(c)*64+128,Cos(c)*64+128,Cos(-c/2)*64+12)
    Next
    Next

    'pageflip
    page=-page+1
    FBGFX_Sync(1)
    FBGFX_ScreenSet(page,-page+1)

    wend[/code]

    Thanks,
    misthema.
    ¯\_†_/¯º¯¹¯²¯³¯\_†_/¯³¯²¯¹¯º¯\_†_/¯

  8. #8
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    159

    Re: FBGFX module for thinBasic, to handle 2D graphics

    try this

    [code=thinbasic]
    'Plasma-like effect with FBGFX
    uses "FBGFX"

    Dim w,h As Double
    w=200
    h=150
    Dim T1, T2 As QUAD
    '---Initialize hi resolution timer
    HiResTimer_Init

    FBGFX_ScreenRes(w,h,32,2)

    Dim x,y,page As Double
    Dim c,t As Double

    'while FBGFX_InKey() <> "q" 'Program runs until "q" is pressed
    T1 = HiResTimer_Get
    t=t+1
    For x = 0 To w
    For y = 0 To h

    c= (Sin((x+y+t)/100)+Cos((x-t)/100)+Cos((y-t)/100)+Cos((x-y+t)/100))*2+Sin(t/100)*15
    FBGFX_PSet(x,y,Rgb(Sin(c)*64+128,Cos(c)*64+128,Cos(-c/2)*64+12)
    Next
    Next
    T2 = HiResTimer_Get
    MSGBOX 0, "Elapsed time in microseconds: " & FORMAT$(T2-T1, "#0")

    'pageflip
    page=-page+1
    FBGFX_Sync(1)
    FBGFX_ScreenSet(page,-page+1)

    'wend

    [/code]

    Results

    Laptop = 183700 microseconds
    Work = 283810 microseconds
    Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

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

    Re: FBGFX module for thinBasic, to handle 2D graphics

    mistema,

    we have always to remember that thinBasic is an interpreted language so big loops are not the strongest area.
    In your FOR/FOR/NEXT/NEXT example you are making 30000 loops (200x150) so thinBasic engione is calculating (well parsing plus interpreting) 30000 times a match expression (c = ...) plus 30000 times the second line.

    When we are in similar situations the best way is to see if some of the interpreted code can be generalized as Module Function (so compiled code).
    For example:
    [code=thinbasic]c= (Sin((x+y+t)/100)+Cos((x-t)/100)+Cos((y-t)/100)+Cos((x-y+t)/100))*2+Sin(t/100)*15[/code]
    can be setup as modules function and exposed as a new keyword with 3 numeric param (x, y, t) or maybe other parameters
    Let's say FBGFX_NewFunction1 function

    Also the following
    [code=thinbasic]Rgb(Sin(c)*64+128,Cos(c)*64+128,Cos(-c/2)*64+12[/code]
    can be a module function with c as param (or other params)
    Let's say FBGFX_NewFunction2 function

    So the final Code can be something
    [code=thinbasic]
    For x = 0 To w
    For y = 0 To h
    c= FBGFX_NewFunction1(x, y, t)
    FBGFX_PSet(x, y, FBGFX_NewFunction2(c) )
    Next
    Next
    [/code]

    In this way the work the parser has to do is much less.
    Of course, this is just a possible way.

    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

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

    Re: FBGFX module for thinBasic, to handle 2D graphics

    ... or the calculation could be solved using Oxygen module

    Here is a decomposition of:
    [code=thinbasic]
    c = (Sin((x+y+t)/100)+Cos((x-t)/100)+Cos((y-t)/100)+Cos((x-y+t)/100))*2+Sin(t/100)*15
    [/code]

    to RPN set of operations:
    x
    y
    +
    t
    +
    100
    /
    SIN
    x
    t
    -
    100
    /
    COS
    +
    y
    t
    -
    100
    /
    COS
    x
    y
    -
    t
    +
    100
    /
    COS
    +
    2
    *
    t
    100
    /
    SIN
    15
    *
    
    So only one step is necessary RPN -> ASM syntax, sadly I am not very good at floating point assembly, but should be doable


    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

Page 1 of 4 123 ... LastLast

Similar Threads

  1. module to handle 2d plus more
    By Michael Clease in forum Experimental modules or library interface
    Replies: 2
    Last Post: 13-01-2008, 10:56

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
  •