Decided to see how hard it was to use OpenGL instead of fbgfx
http://back2basic.phatcode.net/?Issue-% ... %3A-Part-1
http://back2basic.phatcode.net/?Issue-% ... %3A-Part-2
The examples use,
fbgl2d.bi
which I have been unable to find with a google search or in the FreeBASIC download?
missing fbgl2d.bi
-
- Posts: 3906
- Joined: Jan 01, 2009 7:03
- Location: Australia
-
- Posts: 139
- Joined: May 28, 2009 20:07
Re: missing fbgl2d.bi
the zip contains a file named as fbgl2d.bi
https://games.freebasic.net/BASICGaming ... amples.zip
https://games.freebasic.net/BASICGaming ... amples.zip
Re: missing fbgl2d.bi
basiccoder2
you will need to add
#include "gl/glext.bi"
to fbgl2d.bas
to get the GL_BGRA bit.
It is a nice demo.
Where is relsoft these days?
Here is a crude replica,I have no rotation on the ellipse and missed some stuff out (GLOW) to be figured out yet.
you will need to add
#include "gl/glext.bi"
to fbgl2d.bas
to get the GL_BGRA bit.
It is a nice demo.
Where is relsoft these days?
Here is a crude replica,
Code: Select all
#include "gl/gl.bi"
Namespace gl2d
#macro incircle(cx,cy,r,mx,my,a,result)
If (a)<=1 Then
result=(a)*((cx)-(mx))*(a)*((cx)-(mx)) +((cy)-(my))*((cy)-(my))<= (r)*(r)*(a)*(a)
Else
result=(a)*((cx)-(mx))*(a)*((cx)-(mx)) +((cy)-(my))*((cy)-(my))<= (r)*(r)
End If
#endmacro
#macro rotate2d(pivotx,pivoty,px,py,a,scale)
rotx=scale*(Cos(a)*(px-pivotx)-Sin(a)*(py-pivoty))+pivotx
roty=scale*(Sin(a)*(px-pivotx)+Cos(a)*(py-pivoty))+pivoty
#endmacro
#define max(a,b) iif(a>b,a,b)
Sub screen_init(w As Integer,h As Integer)
Screenres w,h,32,,2
glOrtho (0,w, h,0, -1, 1)
glDisable (GL_DEPTH_TEST)
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)
glEnable (GL_BLEND)
glEnable (GL_LINE_SMOOTH)
glclearcolor 0,0,.2,1
End Sub
Sub clear_screen
glClear GL_COLOR_BUFFER_BIT Or GL_DEPTH_BUFFER_BIT
End Sub
Sub circle_2d_filled(x As Long,y As Long,radius As Long,c As Ulong)
Dim As Long result
glbegin gl_points
glcolor4ub(Cast(Ubyte Ptr,@c)[2],Cast(Ubyte Ptr,@c)[1],Cast(Ubyte Ptr,@c)[0],Cast(Ubyte Ptr,@c)[3])
For xx As Long=x-radius To x+radius
For yy As Long=y-radius To y+radius
incircle(x,y,radius,xx,yy,1,result)
If result Then
glvertex2i xx,yy
End If
Next
Next
glend
End Sub
Sub circle_2d(x As Long,y As Long,radius As Long,c As Ulong)
Dim As Long result
glbegin gl_points
glcolor4ub(Cast(Ubyte Ptr,@c)[2],Cast(Ubyte Ptr,@c)[1],Cast(Ubyte Ptr,@c)[0],Cast(Ubyte Ptr,@c)[3])
For xx As Long=x-radius To x+radius
For yy As Long=y-radius To y+radius
incircle(x,y,radius,xx,yy,1,result)
If result Then
incircle(x,y,radius-1,xx,yy,1,result)
If result =0 Then
glvertex2i xx,yy
End If
End If
Next
Next
glend
End Sub
Sub ellipse(x As Long,y As Long,radius1 As Long,radius2 As Long,a as single,c As Ulong)
Dim As Long result
dim as single rotx,roty
Dim As Single aspect=radius1/radius2
Dim As Single radius=max(radius1,radius2)
glpointsize 1
glbegin gl_points
glcolor4ub(Cast(Ubyte Ptr,@c)[2],Cast(Ubyte Ptr,@c)[1],Cast(Ubyte Ptr,@c)[0],Cast(Ubyte Ptr,@c)[3])
For xx As Long=x-radius To x+radius
For yy As Long=y-radius To y+radius
incircle(x,y,radius,xx,yy,aspect,result)
If result Then
incircle(x,y,radius-4,xx,yy,aspect,result)
If result=0 Then
rotate2d(x,y,xx,yy,a,1)
glvertex2i rotx,roty
End If
End If
Next
Next
glend
End Sub
Sub ellipse_filled(x As Long,y As Long,radius1 As Long,radius2 As Long,a as single,c As Ulong)
Dim As Long result
dim as single rotx,roty
Dim As Single aspect=radius1/radius2
Dim As Single radius=max(radius1,radius2)
glpointsize 2
glbegin gl_points
glcolor4ub(Cast(Ubyte Ptr,@c)[2],Cast(Ubyte Ptr,@c)[1],Cast(Ubyte Ptr,@c)[0],Cast(Ubyte Ptr,@c)[3])
For xx As Long=x-radius To x+radius
For yy As Long=y-radius To y+radius
incircle(x,y,radius,xx,yy,aspect,result)
If result Then
rotate2d(x,y,xx,yy,a,1)
glvertex2i rotx,roty
End If
Next
Next
glend
End Sub
Sub box_filled(x1 As Long,y1 As Long,x2 As Long,y2 As Long,c As Ulong)
glcolor4ub(Cast(Ubyte Ptr,@c)[2],Cast(Ubyte Ptr,@c)[1],Cast(Ubyte Ptr,@c)[0],Cast(Ubyte Ptr,@c)[3])
glbegin gl_quads
glvertex2i(x1,y1)
glvertex2i(x1,y1+(y2-y1))
glvertex2i(x1+(x2-x1),y1+(y2-y1))
glvertex2i(x1+(x2-x1),y1)
glend
End Sub
Sub box(x1 As Long,y1 As Long,x2 As Long,y2 As Long,c As Ulong)
glcolor4ub(Cast(Ubyte Ptr,@c)[2],Cast(Ubyte Ptr,@c)[1],Cast(Ubyte Ptr,@c)[0],Cast(Ubyte Ptr,@c)[3])
gllinewidth 1
glbegin gl_lines
glvertex2i(x1,y1)
glvertex2i(x1,y1+(y2-y1))
glvertex2i(x1+(x2-x1),y1+(y2-y1))
glvertex2i(x1+(x2-x1),y1)
glvertex2i(x1,y1)
glvertex2i(x1+(x2-x1),y1)
glvertex2i(x1,y1+(y2-y1))
glvertex2i(x1+(x2-x1),y1+(y2-y1))
glend
End Sub
Sub triangle(x1 As Long,y1 As Long,x2 As Long,y2 As Long,x3 As Long,y3 As Long,c As Ulong)
glcolor4ub(Cast(Ubyte Ptr,@c)[2],Cast(Ubyte Ptr,@c)[1],Cast(Ubyte Ptr,@c)[0],Cast(Ubyte Ptr,@c)[3])
glbegin gl_lines
glvertex2i(x1,y1)
glvertex2i(x2,y2)
glvertex2i(x2,y2)
glvertex2i(x3,y3)
glvertex2i(x3,y3)
glvertex2i(x1,y1)
glend
End Sub
Sub triangle_filled(x1 As Long,y1 As Long,x2 As Long,y2 As Long,x3 As Long,y3 As Long,c As Ulong)
glcolor4ub(Cast(Ubyte Ptr,@c)[2],Cast(Ubyte Ptr,@c)[1],Cast(Ubyte Ptr,@c)[0],Cast(Ubyte Ptr,@c)[3])
glbegin gl_triangles
glvertex2i(x1,y1)
glvertex2i(x2,y2)
glvertex2i(x3,y3)
glend
End Sub
Sub Triangle_filled_gradient(x1 As Long,y1 As Long,x2 As Long,y2 As Long,x3 As Long,y3 As Long,c1 As Ulong,c2 As Ulong,c3 As Ulong)
glbegin gl_triangles
glcolor4ub(Cast(Ubyte Ptr,@c1)[2],Cast(Ubyte Ptr,@c1)[1],Cast(Ubyte Ptr,@c1)[0],Cast(Ubyte Ptr,@c1)[3])
glvertex2i(x1,y1)
glcolor4ub(Cast(Ubyte Ptr,@c2)[2],Cast(Ubyte Ptr,@c2)[1],Cast(Ubyte Ptr,@c2)[0],Cast(Ubyte Ptr,@c2)[3])
glvertex2i(x2,y2)
glcolor4ub(Cast(Ubyte Ptr,@c3)[2],Cast(Ubyte Ptr,@c3)[1],Cast(Ubyte Ptr,@c3)[0],Cast(Ubyte Ptr,@c3)[3])
glvertex2i(x3,y3)
glend
End Sub
Sub put_pixel(x As Long, y As Long,c As Ulong)
glcolor4ub(Cast(Ubyte Ptr,@c)[2],Cast(Ubyte Ptr,@c)[1],Cast(Ubyte Ptr,@c)[0],Cast(Ubyte Ptr,@c)[3])
glpointsize 1
glbegin gl_points
glvertex2i x,y
glend
End Sub
sub line_glow(x1 as long,y1 as long,x2 as long,y2 as long,a as single,c as ulong)
glcolor4ub(Cast(Ubyte Ptr,@c)[2],Cast(Ubyte Ptr,@c)[1],Cast(Ubyte Ptr,@c)[0],Cast(Ubyte Ptr,@c)[3])
gllinewidth a
glbegin gl_lines
glvertex2i(x1,y1)
glcolor4ub 255,255,255,255/a
glvertex2i(x2,y2)
glend
end sub
Sub print_scale(Byval xpos As Long,Byval ypos As Long,size As Single,Byref text As String,Byval col As Ulong)
glend
glcolor4ub(Cast(Ubyte Ptr,@col)[2],Cast(Ubyte Ptr,@col)[1],Cast(Ubyte Ptr,@col)[0],Cast(Ubyte Ptr,@col)[3])
glpointsize size
glBegin (gl_points)
Type D2
As Long x,y
End Type
size=Abs(size)
Static As d2 XY()
Static As Long runflag
If runflag=0 Then
Redim XY(128,127)
Screen 8
Width 640\8,200\16
Dim As Ulong Pointer img
Dim count As Long
For ch As Long=1 To 127
img=Imagecreate(9,17)
Draw String img,(1,1),Chr(ch)
For x As Long=1 To 8
For y As Long=1 To 16
If Point(x,y,img)<>0 Then
count=count+1
XY(count,ch)=Type<D2>(x,y)
End If
Next y
Next x
count=0
Imagedestroy img
Next ch
runflag=1
End If
If size=0 Then Exit Sub
Dim As D2 np,t
#macro Scale(p1,p2,d)
np.x=d*(p2.x-p1.x)+p1.x
np.y=d*(p2.y-p1.y)+p1.y
#endmacro
Dim As D2 c=Type<D2>(xpos,ypos)
Dim As Long dx=xpos,dy=ypos,f
If Abs(size)=1.5 Then f=3 Else f=2
For z6 As Long=1 To Len(text)
Var asci=text[z6-1]
For _x1 As Long=1 To 64*2
t=Type<D2>(XY(_x1,asci).x+dx,XY(_x1,asci).y+dy)
Scale(c,t,size)
If XY(_x1,asci).x<>0 Then
glvertex2f(np.x,np.y)
End If
Next _x1
dx=dx+8
Next z6
glend
End Sub
Sub init Constructor
print_scale(0,0,0,"",0)
Screen 0
End Sub
End Namespace
Function GL2D_RGBA(r As Ubyte,g As Ubyte,b As Ubyte,al As Ubyte) As Ulong
Return Rgba(r,g,b,al)
End Function
Function Regulate(Byval MyFps As Long,Byref fps As Long=0) As Long
Static As Double timervalue,lastsleeptime,t3,frames
Var t=Timer
frames+=1
If (t-t3)>=1 Then t3=t:fps=frames:frames=0
Var sleeptime=lastsleeptime+((1/myfps)-T+timervalue)*1000
If sleeptime<1 Then sleeptime=1
lastsleeptime=sleeptime
timervalue=T
Return sleeptime
End Function
Const SCR_WIDTH = 640
Const SCR_HEIGHT = 480
Const As Single PI = Atn(1)*4
'' initialize gl2d (640 x 480)
gl2d.screen_init( SCR_WIDTH, SCR_HEIGHT )
Dim As Integer frame = 0
Dim As Long fps
Do
frame += 1
'' clear buffer always
gl2d.clear_screen()
'' circle test
gl2d.circle_2d_filled(100,100,150-Abs(Sin(frame/25)*150),GL2D_RGBA(0,255,0,255))
gl2d.circle_2d(100,100,Abs(Sin(frame/25)*150),GL2D_RGBA(255,255,0,255))
'' Draw black(ish) box
GL2D.box_filled(400,40,639,479,GL2D_RGBA(0,0,0,150))
'' ellipse test
gl2d.ellipse(320, 240, 50, 200,-(PI/6*5), GL2D_RGBA(255, 128, 64, 255))
'
gl2d.ellipse_filled(320, 240, 10+Abs(Sin(frame/25)*250), 10+250-Abs(Sin(frame/25)*250),-frame/65, GL2D_RGBA(255, 128, 64, 255))
'' box
GL2D.box(400,40,639,479,GL2D_RGBA(220,255,55,255))
'' triangle test
gl2d.triangle(480,100,630,50,560,200,GL2D_RGBA(25,2,255,255))
GL2D.Triangle_filled(490,105,610,60,590,135,GL2D_RGBA(255,255,255,255))
GL2D.Triangle_filled_gradient(290,150,510,60,490,135,_
GL2D_RGBA(0,255,255,255),_
GL2D_RGBA(255,255,0,255),_
GL2D_RGBA(255,0,255,255))
'' pset test
For i As Integer = 0 To 359 Step 10
Dim As Integer px = 20 * Cos(i*PI/180)
Dim As Integer py = 20 * Sin(i*PI/180)
gl2d.put_pixel(430+px,70+py,GL2D_RGBA(255,2,255,255))
Next i
for i as integer = frame to 359+frame step 20
dim as integer px = 120 * cos(i*PI/180)
dim as integer py = 120 * sin(i*PI/180)
dim as integer px2 = 120 * cos((i+20)*PI/180)
dim as integer py2 = 120 * sin((i+20)*PI/180)
dim as integer adder = abs(7*sin(frame/20))
for j as integer= 0 to adder
gl2d.line_glow (320+px,240+py,320+px2,240+py2,20-(adder*2),GL2D_RGBA(255+frame,255-frame,128+frame,255))
next j
next i
gl2d.print_scale(40, 10,2, "Easy GL2D simple test FPS = " + Str(fps),GL2D_RGBA(255,255,255,255))
Flip
Sleep regulate(30,fps)
Loop Until Multikey( 1 ) '<esc>
Last edited by dodicat on Apr 10, 2020 18:29, edited 2 times in total.
Re: missing fbgl2d.bi
Where he always was:dodicat wrote:...
Where is relsoft these days?
https://rel.phatcode.net/
I think it was superseded with EasyGL2D (look for it in Rel's site above).BasicCoder2 wrote:...
The examples use,
fbgl2d.bi
which I have been unable to find with a google search or in the FreeBASIC download?
-
- Posts: 3906
- Joined: Jan 01, 2009 7:03
- Location: Australia
Re: missing fbgl2d.bi
@dodicat,
Thanks. Result,
tute_2D_and3D.bas, tute_metaballs.bas, tute-sprites.bas, tute_sprites.bas compiled and ran but only displayed a momentary white screen.
tute_glowlines_bounce_zoom.bas, tute_lasers_lightsabers.bas, tute_simple.bas worked as expected.
Your example worked ok.
Thanks. Result,
tute_2D_and3D.bas, tute_metaballs.bas, tute-sprites.bas, tute_sprites.bas compiled and ran but only displayed a momentary white screen.
tute_glowlines_bounce_zoom.bas, tute_lasers_lightsabers.bas, tute_simple.bas worked as expected.
Your example worked ok.
Re: missing fbgl2d.bi
Thanks for testing basiccoder2.
opengl is too slow at glpoints (psetting), but it seems OK at filling 2D shapes.
Thus I have reverted to my old method of triangle fan for circles and ellipses, much faster.
I can get about 90 fps here.
opengl is too slow at glpoints (psetting), but it seems OK at filling 2D shapes.
Thus I have reverted to my old method of triangle fan for circles and ellipses, much faster.
I can get about 90 fps here.
Code: Select all
#include "gl/gl.bi"
Namespace gl2d
#macro rotate2d(pivotx,pivoty,px,py,a,scale)
rotx=scale*(Cos(a)*(px-pivotx)-Sin(a)*(py-pivoty))+pivotx
roty=scale*(Sin(a)*(px-pivotx)+Cos(a)*(py-pivoty))+pivoty
#endmacro
'for circles/ellipses
const Number_of_sides=60
Const pi2 = 8*Atn(1)
const st=pi2/(Number_of_sides)
Sub screen_init(w As Integer,h As Integer,c as ulong=0)
var r=Cast(Ubyte Ptr,@c)[2]/255,g=Cast(Ubyte Ptr,@c)[1]/255,b=Cast(Ubyte Ptr,@c)[0]/255,al=Cast(Ubyte Ptr,@c)[3]/255
Screenres w,h,32,,2
glOrtho (0,w, h,0, -1, 1)
glDisable (GL_DEPTH_TEST)
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)
glEnable (GL_BLEND)
glEnable (GL_LINE_SMOOTH)
glclearcolor r,g,b,al
End Sub
Sub clear_screen
glClear GL_COLOR_BUFFER_BIT Or GL_DEPTH_BUFFER_BIT
End Sub
Sub circle_2d(x As Long,y As Long,radius As Long,c As Ulong)
Dim As Long lx,ly,xx,yy
glcolor4ub(Cast(Ubyte Ptr,@c)[2],Cast(Ubyte Ptr,@c)[1],Cast(Ubyte Ptr,@c)[0],Cast(Ubyte Ptr,@c)[3])
gllinewidth 1
glBegin GL_lines
For a As Single=0 To pi2 Step st
xx=(x)+Cos(a)*(radius)
yy=(y)+Sin(a)*(radius)
If a=0 Then lx=xx:ly=yy
glvertex2i xx,yy
glvertex2i lx,ly
lx=xx
ly=yy
Next
glEnd
End Sub
Sub circle_2d_filled(x As Long,y As Long,radius As Long,c As Ulong)
glcolor4ub(Cast(Ubyte Ptr,@c)[2],Cast(Ubyte Ptr,@c)[1],Cast(Ubyte Ptr,@c)[0],Cast(Ubyte Ptr,@c)[3])
glBegin GL_TRIANGLE_FAN
For a As Single=0 To pi2 Step st
glVertex2f (x)+Cos(a)*(radius),(y)+Sin(a)*(radius)
Next
glEnd
End Sub
Sub ellipse_filled(x As Long,y As Long,rx As Long,ry As Long,an As Single,c As Ulong)
Dim As Single rotx,roty
glcolor4ub(Cast(Ubyte Ptr,@c)[2],Cast(Ubyte Ptr,@c)[1],Cast(Ubyte Ptr,@c)[0],Cast(Ubyte Ptr,@c)[3])
glBegin GL_TRIANGLE_FAN
For a As Single=0 To pi2 Step st
rotate2d(x,y,((x)+Cos(a)*(rx)),((y)+Sin(a)*(ry)),an,1)
glvertex2i rotx,roty
Next
glEnd
End Sub
Sub ellipse(x As Long,y As Long,rx As Long,ry As Long,an As Single,c As Ulong)
Dim As Single rotx,roty,lrotx,lroty
Const pi2 = 8*Atn(1),st=pi2/(Number_of_sides)
glcolor4ub(Cast(Ubyte Ptr,@c)[2],Cast(Ubyte Ptr,@c)[1],Cast(Ubyte Ptr,@c)[0],Cast(Ubyte Ptr,@c)[3])
gllinewidth 1
glBegin GL_lines
For a As Single=0 To pi2 Step st
rotate2d(x,y,((x)+Cos(a)*(rx)),((y)+Sin(a)*(ry)),an,1)
If a=0 Then lrotx=rotx:lroty=roty
glvertex2i rotx,roty
glvertex2i lrotx,lroty
lrotx=rotx
lroty=roty
Next
glEnd
End Sub
Sub box_filled(x1 As Long,y1 As Long,x2 As Long,y2 As Long,c As Ulong)
glcolor4ub(Cast(Ubyte Ptr,@c)[2],Cast(Ubyte Ptr,@c)[1],Cast(Ubyte Ptr,@c)[0],Cast(Ubyte Ptr,@c)[3])
glbegin gl_quads
glvertex2i(x1,y1)
glvertex2i(x1,y1+(y2-y1))
glvertex2i(x1+(x2-x1),y1+(y2-y1))
glvertex2i(x1+(x2-x1),y1)
glend
End Sub
Sub box(x1 As Long,y1 As Long,x2 As Long,y2 As Long,c As Ulong)
glcolor4ub(Cast(Ubyte Ptr,@c)[2],Cast(Ubyte Ptr,@c)[1],Cast(Ubyte Ptr,@c)[0],Cast(Ubyte Ptr,@c)[3])
gllinewidth 1
glbegin gl_lines
glvertex2i(x1,y1)
glvertex2i(x1,y1+(y2-y1))
glvertex2i(x1+(x2-x1),y1+(y2-y1))
glvertex2i(x1+(x2-x1),y1)
glvertex2i(x1,y1)
glvertex2i(x1+(x2-x1),y1)
glvertex2i(x1,y1+(y2-y1))
glvertex2i(x1+(x2-x1),y1+(y2-y1))
glend
End Sub
Sub triangle(x1 As Long,y1 As Long,x2 As Long,y2 As Long,x3 As Long,y3 As Long,c As Ulong)
glcolor4ub(Cast(Ubyte Ptr,@c)[2],Cast(Ubyte Ptr,@c)[1],Cast(Ubyte Ptr,@c)[0],Cast(Ubyte Ptr,@c)[3])
glbegin gl_lines
glvertex2i(x1,y1)
glvertex2i(x2,y2)
glvertex2i(x2,y2)
glvertex2i(x3,y3)
glvertex2i(x3,y3)
glvertex2i(x1,y1)
glend
End Sub
Sub triangle_filled(x1 As Long,y1 As Long,x2 As Long,y2 As Long,x3 As Long,y3 As Long,c As Ulong)
glcolor4ub(Cast(Ubyte Ptr,@c)[2],Cast(Ubyte Ptr,@c)[1],Cast(Ubyte Ptr,@c)[0],Cast(Ubyte Ptr,@c)[3])
glbegin gl_triangles
glvertex2i(x1,y1)
glvertex2i(x2,y2)
glvertex2i(x3,y3)
glend
End Sub
Sub Triangle_filled_gradient(x1 As Long,y1 As Long,x2 As Long,y2 As Long,x3 As Long,y3 As Long,c1 As Ulong,c2 As Ulong,c3 As Ulong)
glbegin gl_triangles
glcolor4ub(Cast(Ubyte Ptr,@c1)[2],Cast(Ubyte Ptr,@c1)[1],Cast(Ubyte Ptr,@c1)[0],Cast(Ubyte Ptr,@c1)[3])
glvertex2i(x1,y1)
glcolor4ub(Cast(Ubyte Ptr,@c2)[2],Cast(Ubyte Ptr,@c2)[1],Cast(Ubyte Ptr,@c2)[0],Cast(Ubyte Ptr,@c2)[3])
glvertex2i(x2,y2)
glcolor4ub(Cast(Ubyte Ptr,@c3)[2],Cast(Ubyte Ptr,@c3)[1],Cast(Ubyte Ptr,@c3)[0],Cast(Ubyte Ptr,@c3)[3])
glvertex2i(x3,y3)
glend
End Sub
Sub put_pixel(x As Long, y As Long,c As Ulong)
glcolor4ub(Cast(Ubyte Ptr,@c)[2],Cast(Ubyte Ptr,@c)[1],Cast(Ubyte Ptr,@c)[0],Cast(Ubyte Ptr,@c)[3])
glpointsize 1
glbegin gl_points
glvertex2i x,y
glend
End Sub
Sub line_glow(x1 As Long,y1 As Long,x2 As Long,y2 As Long,a As Single,c As Ulong)
glcolor4ub(Cast(Ubyte Ptr,@c)[2],Cast(Ubyte Ptr,@c)[1],Cast(Ubyte Ptr,@c)[0],Cast(Ubyte Ptr,@c)[3])
gllinewidth a
glbegin gl_lines
glvertex2i(x1,y1)
glcolor4ub 255,255,255,255/a
glvertex2i(x2,y2)
glend
End Sub
Sub print_scale(Byval xpos As Long,Byval ypos As Long,size As Single,Byref text As String,Byval col As Ulong)
glend
glcolor4ub(Cast(Ubyte Ptr,@col)[2],Cast(Ubyte Ptr,@col)[1],Cast(Ubyte Ptr,@col)[0],Cast(Ubyte Ptr,@col)[3])
glpointsize size
glBegin (gl_points)
Type D2
As Long x,y
End Type
size=Abs(size)
Static As d2 XY()
Static As Long runflag
If runflag=0 Then
Redim XY(128,127)
Screen 8
Width 640\8,200\16
Dim As Ulong Pointer img
Dim count As Long
For ch As Long=1 To 127
img=Imagecreate(9,17)
Draw String img,(1,1),Chr(ch)
For x As Long=1 To 8
For y As Long=1 To 16
If Point(x,y,img)<>0 Then
count=count+1
XY(count,ch)=Type<D2>(x,y)
End If
Next y
Next x
count=0
Imagedestroy img
Next ch
runflag=1
End If
If size=0 Then Exit Sub
Dim As D2 np,t
#macro Scale(p1,p2,d)
np.x=d*(p2.x-p1.x)+p1.x
np.y=d*(p2.y-p1.y)+p1.y
#endmacro
Dim As D2 c=Type<D2>(xpos,ypos)
Dim As Long dx=xpos,dy=ypos,f
If Abs(size)=1.5 Then f=3 Else f=2
For z6 As Long=1 To Len(text)
Var asci=text[z6-1]
For _x1 As Long=1 To 64*2
t=Type<D2>(XY(_x1,asci).x+dx,XY(_x1,asci).y+dy)
Scale(c,t,size)
If XY(_x1,asci).x<>0 Then
glvertex2f(np.x,np.y)
End If
Next _x1
dx=dx+8
Next z6
glend
End Sub
Sub init Constructor
print_scale(0,0,0,"",0)
Screen 0
End Sub
End Namespace
Function Regulate(Byval MyFps As Long,Byref fps As Long=0) As Long
Static As Double timervalue,lastsleeptime,t3,frames
Var t=Timer
frames+=1
If (t-t3)>=1 Then t3=t:fps=frames:frames=0
Var sleeptime=lastsleeptime+((1/myfps)-T+timervalue)*1000
If sleeptime<1 Then sleeptime=1
lastsleeptime=sleeptime
timervalue=T
Return sleeptime
End Function
Const SCR_WIDTH = 640
Const SCR_HEIGHT = 480
Const As Single PI = Atn(1)*4
'' initialize gl2d (640 x 480)
gl2d.screen_init( SCR_WIDTH, SCR_HEIGHT,rgb(0,0,50) )
Dim As Integer frame = 0
Dim As Long fps
Do
frame += 1
'' clear buffer always
gl2d.clear_screen
'' circle test
gl2d.circle_2d_filled(100,100,150-Abs(Sin(frame/25)*150),Rgba(0,255,0,255))
gl2d.circle_2d(100,100,Abs(Sin(frame/25)*150),Rgba(255,255,0,255))
'' Draw black(ish) box
GL2D.box_filled(400,40,639,479,Rgba(0,0,0,150))
'' ellipse test
gl2d.ellipse(320, 240, 50, 200,(PI/6*5), Rgba(255, 128, 64, 255))
'
gl2d.ellipse_filled(320, 240, 10+Abs(Sin(frame/25)*250), 10+250-Abs(Sin(frame/25)*250),frame/65, Rgba(255, 128, 64, 255))
'' box
GL2D.box(400,40,639,479,Rgba(220,255,55,255))
'' triangle test
gl2d.triangle(480,100,630,50,560,200,Rgba(25,2,255,255))
GL2D.Triangle_filled(490,105,610,60,590,135,Rgba(255,255,255,255))
GL2D.Triangle_filled_gradient(290,150,510,60,490,135,_
Rgba(0,255,255,255),_
Rgba(255,255,0,255),_
Rgba(255,0,255,255))
'' pset test
For i As Integer = 0 To 359 Step 10
Dim As Integer px = 20 * Cos(i*PI/180)
Dim As Integer py = 20 * Sin(i*PI/180)
gl2d.put_pixel(430+px,70+py,Rgba(255,2,255,255))
Next i
For i As Integer = frame To 359+frame Step 20
Dim As Integer px = 120 * Cos(i*PI/180)
Dim As Integer py = 120 * Sin(i*PI/180)
Dim As Integer px2 = 120 * Cos((i+20)*PI/180)
Dim As Integer py2 = 120 * Sin((i+20)*PI/180)
Dim As Integer adder = Abs(7*Sin(frame/20))
For j As Integer= 0 To adder
gl2d.line_glow (320+px,240+py,320+px2,240+py2,20-(adder*2),Rgba(255+frame,255-frame,128+frame,255))
Next j
Next i
gl2d.print_scale(40, 10,2, "Easy GL2D simple test FPS = " + Str(fps),Rgba(255,255,255,255))
Flip
Sleep regulate(100,fps)
Loop Until Multikey( 1 ) '<esc>