-
1 Attachment(s)
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.
-
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
-
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!
-
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
-
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
-
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.
-
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+128))
Next
Next
'pageflip
page=-page+1
FBGFX_Sync(1)
FBGFX_ScreenSet(page,-page+1)
wend[/code]
Thanks,
misthema.
-
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+128))
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
-
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+128)[/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
-
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:
Code:
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
-
Re: FBGFX module for thinBasic, to handle 2D graphics
Hi,
thanks Eros. That might be better to do some of those functions straight to the module.
I still made it go faster (smaller loop):
[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 step 3
For y = 0 To h step 3
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_Color(Rgb(Sin(c)*64+128,Cos(c)*64+128,Cos(-c/2)*64+128), 0)
FBGFX_Circle(x,y,3)
Next
Next
'pageflip
page=-page+1
FBGFX_Sync(1)
FBGFX_ScreenSet(page,-page+1)
wend[/code]
Also you guys can suggest some functions that I'll put to the module.
Thanks everyone,
misthema.
-
Re: FBGFX module for thinBasic, to handle 2D graphics
eh :D
smaller loops are a trick. But I'm sure that with module functions you will get some real boost.
The key point to decide to have a module function is if that function can be enough general to be used also in other scripts.
If yes, than go with module function. You will have a better module and faster scripts.
Ciao
Eros
-
Re: FBGFX module for thinBasic, to handle 2D graphics
change from double to single you dont need the precision should make it faster.
If you want some ideas just google 2d librarys and see what they do and recreate them.
-
Re: FBGFX module for thinBasic, to handle 2D graphics
Hi,
I created new thread for assembler optimization of plasma code, to not break high-level structure of samples in this thread.
I did first optimization of one expression, just 1.3-1.5 faster - not bad sign for thinBASIC parsing engine :).
But it gives me 3FPS instead of 2, which is thing many would die for ... or at least someone ... hey ... anyone ? :D
Petr
-
1 Attachment(s)
Re: FBGFX module for thinBasic, to handle 2D graphics
And here my version with an external DLL written in Power Basic implementing the two functions I mentioned.
I get a speed incremented by 3/4 times the original speed.
Ciao
Eros
-
Re: FBGFX module for thinBasic, to handle 2D graphics
Cool demo Petr and Eros. The one in Eros's post is significantly faster than the copy and paste one from Petr's. In both however, I can't close the window in any standard way and have to use the TaskManager to kill the running app.
Other than that, those kind of nice smooth color changes always impress me!
-
Re: FBGFX module for thinBasic, to handle 2D graphics
Kent,
you have to press "q" key to close the window.
You can get it from the main WHILE/WEND loop.
Ciao
Eros
-
Re: FBGFX module for thinBasic, to handle 2D graphics
Quote:
Originally Posted by kryton9
In both however, I can't close the window in any standard way and have to use the TaskManager to kill the running app.
I have to use the "q" key, becouse I haven't figured out how can I use ESCAPE in FBGFX_InKey function. Maybe I'll make it work with scancodes and make equates for them.
Bye,
misthema.
-
Re: FBGFX module for thinBasic, to handle 2D graphics
Thank for this module. Is there a way to make it work with thinBasic windows?
-
Re: FBGFX module for thinBasic, to handle 2D graphics
Michael,
I don't think so, becouse FBGFX creates its own window and viewport where it draws everything.
Or did I miss what you ment?
Bye,
misthema.
-
Re: FBGFX module for thinBasic, to handle 2D graphics
No, that is what I ment. Thanks.
-
Re: FBGFX module for thinBasic, to handle 2D graphics
Mike from reading the FB docs it looks like its just a standard OpenGL window with some with some commands which probably generate somekind of managed displaylists.
TBGL should of been able to do this along time ago Petr :P only messing.
-
Re: FBGFX module for thinBasic, to handle 2D graphics
Hi,
[OT]
Abraxas, could you please make a post in TBGL / Suggest new features?
I use that to check where I should go, and although I must admit we were speaking about this possiblity, I simply forgot it.
So if you could make post specifying what you need from TBGL control, I can keep it in mind more easily
[/OT]
I did not know FreeBASIC 2D commands are OpenGL based, I thought it is just "soft" rendering to bitmap.
Thanks,
Petr
-
Re: FBGFX module for thinBasic, to handle 2D graphics
Its not totally clear, it maybe a bit of both GL and some "soft" stuff.
If you have a look at the commands available they all seem possible in GL.
-
Re: FBGFX module for thinBasic, to handle 2D graphics
Hi,
reading Abraxas's posts, this module feels like it's useless. If TBGL is able to do what this module does, why should I develop it?
I've thought that I'll make new 2D module from other programming language or C++ library.
Maybe the ClanLib that Abraxas's suggested in other post, or allegro? They seem to be much more powerfull than this...
-
Re: FBGFX module for thinBasic, to handle 2D graphics
Misthema,
no, no, no! Your module is very important!
The lines and points in OpenGL are possible, good to have them, but I would not be surprised if the performance would be lower ( in case of many entities ) than in your module.
Lines and points in TBGL/OpenGL break a bit the rasterization pipeline, so they are not a fast ones as they need special handling.
Also your FBGFX window seems to be persistent, TBGL one needs continuous redraws.
I think it will be good if you will continue your project!
Petr
-
Re: FBGFX module for thinBasic, to handle 2D graphics
Ok... Maybe I really should continue with this.. Thanks Petr. :)
Also there's an update coming soon! I've changed few command names and made more commands. :)
I'll let you know!
Thanks,
misthema.
-
Re: FBGFX module for thinBasic, to handle 2D graphics
Dont stop the development of your module.
Even if it did the same functions as TBGL the freebasic version may be slightly faster at certain things.
I think its better to have more than 1 option to do graphics, If i was to look at DirectX(3d) and develope a module should I bother because opengl can do can do the same sort of functions, simple answer YES.
Come on I want to see this update, so carry on the good work.
-
Re: FBGFX module for thinBasic, to handle 2D graphics
Misthema,
maybe you was just making some experiment or maybe you was thinking to something more serious.
In any case, developing a thinBasic module give a great responsability because you are creating a kind of trust between you (the developer) and the users using your work. It is important to consider also the "others" in those situations. And it means: coding, listening to suggestions, being active in development, think at documentation, think to release source code or just compiled dlls. In other words: have a planning.
Again, it is your choice if to continue or not or just say "I was just making some experiment" or whatever. Up to you.
Just consider your motivations.
Ciao and good work.
Eros
-
Re: FBGFX module for thinBasic, to handle 2D graphics
Again, thank you for all the work you did so far.
I totally agree with Eros. It's up to you. If you don't go further, then please release the source so other people can work on it if the need to or want to.
One thing that you also should be aware of, this comunity is small and so it can take some time, if ever, someone will release some work using your module. But that should not stop you from developing modules. With your work you support thinBasic as a whole and make it more powerfull. Just like Abraxas said, the more the better.
Michael
-
Re: FBGFX module for thinBasic, to handle 2D graphics
I would first like to say that I think the module is a good idea. I would like to use it if you are willing to continue working on it. I do have a question about its further development.
Are there any plans for the module to be able to handle bitmaps? I was thinking that in a game using it that it would be good to be able to put bitmaps in the window and then move them around using the arrow keys.
I have a couple of ideas that sound like they would be workable using the module.
Thanks
Sandy
-
Re: FBGFX module for thinBasic, to handle 2D graphics
Hi,
I'm working with the bitmap handling at the moment. I'm trying to make it as simple as I can, so you don't have to work with it so much (it's really hard to handle bitmaps in FB (imo), so that's why I'm simpling it for you).
The developing has been a bit slow in these few weeks, 'coz I've started to play MMORPG (it really wastes my time, but it's easier to play than develop :D) I'm still working on the module and I'll let you know the news as soon as possible!
Thanks,
misthema.
-
Re: FBGFX module for thinBasic, to handle 2D graphics
Thanks for the message,
don't worry about playing games too much, better to code with relaxed brain than to bite fingers in nervous state :)
Petr
-
Re: FBGFX module for thinBasic, to handle 2D graphics
Gaming is inspiration and should be considered work for us too, well maybe research ? :)
-
Re: FBGFX module for thinBasic, to handle 2D graphics
I was wondering.....
Is the FBGFX module still being developed?
Thanks
Sandy
-
Re: FBGFX module for thinBasic, to handle 2D graphics
FBGFX is not an official module. I released FBGFX module as source code to show how to implement a thinBasic module using FreeBasic compiler. Everyone can take it and play with it as preferred.
Misthema took it and implemented further adding new functions.
Everyone can do the same. It can be a very good way to understand how to develop thinBasic modules. And maybe it can be the basis for more advanced modules.
Ciao
Eros
-
Re: FBGFX module for thinBasic, to handle 2D graphics
Quote:
FBGFX is not an official module. I released FBGFX module as source code to show how to implement a thinBasic module using FreeBasic compiler. Everyone can take it and play with it as preferred.
Where can I get a copy of the source?
Thanks
Sandy
-
Re: FBGFX module for thinBasic, to handle 2D graphics
-
Re: FBGFX module for thinBasic, to handle 2D graphics
Eros, Thank you. I found it under \thinBasic\SDK\SDK.zip file.
Sandy
-
Re: FBGFX module for thinBasic, to handle 2D graphics
OK, perfect.
\thinBasic\SDK\SDK.zip file contains info and examples on how to implement thinBasic modules in various languages.
Once you will be more familiar with DLL creation, you will see that a thinBasic module is quite easy to be implemented.
Ciao
Eros