I tested cairo, not as smooth as opengl.
The reason I used settimer and freetimer on windows was to make sure a sleep 1 was 1 millisecond.
Normally it is about 15 milliseconds on windows.
Google chrome used to set this one millisecond automatically when online in the freebasic forum, but I note that this is not happening now.
Maybe Linux is actually one millisecond for sleep 1 anyway, I don't know.
In order to get about 120 fps here I must use settimer and freetimer now.
Can you get 120 fps on Linux by moving the slider up?
Code: Select all
#ifdef __FB_WIN32__
declare function settimer alias "timeBeginPeriod"(as Ulong=1) as long
declare function freetimer alias "timeEndPeriod" (as Ulong=1) as long
#endif
#define map(a,b,x,c,d) ((d)-(c))*((x)-(a))/((b)-(a))+(c)
#define inbox (mx>125) and (mx<475)' and (my>300) and (my<350)
#define incircle(cx,cy,radius,x,y) (cx-x)*(cx-x) +(cy-y)*(cy-y)<= radius*radius
#macro display
fr=map(125,475,cx,10,120)
screenlock
cls
draw string(20,20),"Actual Framerate = " &fps
draw string(20,40),"Requested Framerate = " &fr
draw string(20,60),"Sleeping time = " &sleeptime
draw string(100,280),"10"
draw string(480,280),"120"
draw string(250,280),"<--slider-->"
angle+=.1
drawline(600,200,.2*sin(angle)-pi/2,300,4)
line(100,300)-(500,350),2,bf
circle(cx,cy),25,5,,,,f
screenunlock
#ifdef __FB_WIN32__
settimer
#endif
sleep sleeptime,1
#ifdef __FB_WIN32__
freetimer
#endif
#endmacro
#macro mouse
Dim As Long x=mx,y=my,dx,dy
While mb = 1
Display
Getmouse mx,my,,mb
If inbox Then
If mx<>x Or my<>y Then
dx = mx - x
dy = my - y
x = mx
y = my
cx=x+dx
if cx<125 then cx=125
if cx>475 then cx=475
End If
End If
Wend
#endmacro
sub drawline(x as long,y as long,angle as single,length as long,col as ulong)
var x2=x+length*cos(angle)
var y2=y-length*sin(angle)
line(x,y)-(x2,y2)
circle(x2,y2),10,6,,,,f
end sub
Function Regulate(Byval MyFps As long,Byref fps As long) As long
Static As Double timervalue,lastsleeptime,t3,frames
frames+=1
If (Timer-t3)>=1 Then t3=Timer:fps=frames:frames=0
Var sleeptime=lastsleeptime+((1/myfps)-Timer+timervalue)*1000
If sleeptime<1 Then sleeptime=1
lastsleeptime=sleeptime
timervalue=Timer
Return sleeptime
End Function
screen 19
dim as integer mx,my,mb
dim as long cx=125,cy=325,fps,fr,sleeptime
dim as single angle,pi=4*atn(1)
do
getmouse mx,my,,mb
display
if incircle(cx,cy,25,mx,my) and mb=1 then
mouse
end if
sleeptime= regulate(fr,fps)
loop until len(inkey)