Donate Now Goal amount for this month: 100 USD, Received: 0 USD (0%)
Donate to support this site and ThinBASIC project development

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
    47
    Posts
    7,556
    Blog Entries
    2
    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/ | psch.thinbasic.com
    Win7Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  3. #3
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Clearwater, Florida, USA
    Posts
    3,802
    Rep Power
    388

    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!

  4. #4
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    6,403
    Rep Power
    650

    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 7 64bit - Intel Core 2 Duo T6600 @ 2.2GHz - 4 GB RAM - NVIDIA GeForce G210M 512MB
    Windows 8 64bit - Intel Core i5-3350P @ 3.1GHz - 8 GB RAM - NVIDIA GeForce GT640 3GB

  5. #5
    thinBasic MVPs Michael Clease's Avatar
    Join Date
    May 2007
    Posts
    1,414
    Blog Entries
    1
    Rep Power
    149

    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

    Why is the world full of nobs trying to push my buttons!!

    Home Desktop : WinXP Pro SP3 - 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 : WinXP Pro SP3 - Intel Pentium 4 - 3 Ghz - 512 MB - ATI Mobile Radeon 7000 IGP
    Work Desktop : WinXP Pro SP3 - Intel core 2 Quad Q8200 - 2.33 Ghz - 2 Gb - 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 Michael Clease's Avatar
    Join Date
    May 2007
    Posts
    1,414
    Blog Entries
    1
    Rep Power
    149

    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
    Why is the world full of nobs trying to push my buttons!!

    Home Desktop : WinXP Pro SP3 - 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 : WinXP Pro SP3 - Intel Pentium 4 - 3 Ghz - 512 MB - ATI Mobile Radeon 7000 IGP
    Work Desktop : WinXP Pro SP3 - Intel core 2 Quad Q8200 - 2.33 Ghz - 2 Gb - Quadro Fx 370

  9. #9
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    47
    Posts
    7,556
    Blog Entries
    2
    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/ | psch.thinbasic.com
    Win7Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  10. #10
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    6,403
    Rep Power
    650

    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 7 64bit - Intel Core 2 Duo T6600 @ 2.2GHz - 4 GB RAM - NVIDIA GeForce G210M 512MB
    Windows 8 64bit - Intel Core i5-3350P @ 3.1GHz - 8 GB RAM - NVIDIA GeForce GT640 3GB

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

Bookmarks

Posting Permissions

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