Hi Albert.
I've set the text to opengl.
Just the 8 X 8 version.
I might make up an 8 X 16 version, for it definitely produces better quality, but less speed.
I've used your original method of separating characters with different colours, it is better and you can control the spacing.
Since line thickness in opengl only goes so far (4 I think), thus the text size is limited to about 8 or 9, above that the maximum line thickness is not enough to fill the characters.
However opengl can rotate every pixel along with the textangle and use no extra resources.
I've also included opengl polygon and filled polygon.
With about 60 sides to the polygon circles are produced, so it is easy to do a gl circle or filled circle.
I've set a block behind the text, and set the regulator to 33 fps (which I get).
Code: Select all
'old drawstring
#Include "GL/gl.bi"
Sub setup
Dim As Integer xres,yres
Screeninfo xres,yres
glOrtho (0,xres, 0,yres, -1, 1)
glDisable (GL_DEPTH_TEST)
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)
glEnable (GL_BLEND)
glEnable (GL_LINE_SMOOTH)
End Sub
#macro Glpolygonfill(x,y,z,rx,ry,numsides,colour)
Scope
Var pi2 = 8*Atn(1),st=pi2/(numsides)
glend
glcolor4f colour
glBegin GL_TRIANGLE_FAN
For a As Single=0 To pi2 Step st
glVertex3f (x)+Cos(a)*(rx),(y)+Sin(a)*(ry),(z)
Next
glEnd
End Scope
#endmacro
#macro Glpolygon(x,y,z,rx,ry,numsides,colour)
Scope
Var pi2 = 8*Atn(1),st=pi2/(numsides)
glend
glcolor4f colour
glBegin GL_LINES
For a As Single=0 To pi2-st Step st
glVertex3f (x)+Cos(a)*(rx),(y)+Sin(a)*(ry),(z)
glVertex3f (x)+Cos(a+st)*(rx),(y)+Sin(a+st)*(ry),(z)
Next
glEnd
End Scope
#endmacro
Sub drawstring(xpos As Integer,ypos As Integer,text As String,colour() As Double,size As Single,textangle As Single=0,charangle As Single=0,im As Any Pointer=0)
Dim As Integer wy
glColor4f (colour(1),colour(2),colour(3),colour(4))
Screeninfo ,wy
glend
glLineWidth(1.1*size)
glBegin (GL_LINES)
Type point2d
As Single x,y
End Type
Dim As Integer flag,codenum=256
if instr(text,"|") then flag=1
Static As Integer runflag
Static As point2d infoarray()
Redim Preserve As point2d infoarray(64,codenum) '64 = 8 x 8 pixel size
If runflag=0 Then ' 'scan codenum of codepage once
Dim As Uinteger background=0
Screenres 10,10 '8 x 8 pixels on this screen
Dim count As Integer
For ch As Integer=1 To codenum
Cls
Draw String(1,1),Chr(ch)
For x As Integer=1 To 8 'scan for characters
For y As Integer=1 To 8
If Point(x,y)<>background Then
count=count+1
infoarray(count,ch)=Type<point2d>(x,y)'save pixel position
End If
Next y
Next x
count=0
Next ch
runflag=1
End If
If size=0 Then Exit Sub
Dim As point2d temp(1 To 64,codenum),np
Dim As Single cr= 0.01745329 'degs to radians
dim as single d_x=(size/2)*(cos(textangle*cr))
dim as single d_y=size/2*(sin(textangle*cr))
#macro rotate(p1,p2,a,d)
np.x=d*(Cos(a*cr)*(p2.x-p1.x)-Sin(a*cr)*(p2.y-p1.y)) +p1.x
np.y=d*(Sin(a*cr)*(p2.x-p1.x)+Cos(a*cr)*(p2.y-p1.y)) +p1.y
#endmacro
Dim As point2d cpt(1 To 64),c=Type<point2d>(xpos,ypos),c2
Dim As Integer dx=xpos,dy=ypos
For z6 As Integer=1 To Len(text)
var asci=text[z6-1]
If asci=124 Then
if charangle<>0 then xpos=xpos+12*sin(charangle*cr)
dx=xpos:dy=dy+12:Goto skip 'pipe | for new line
End If
For _x1 As Integer=1 To 64
temp(_x1,asci).x=infoarray(_x1,asci).x+dx
temp(_x1,asci).y=infoarray(_x1,asci).y+dy
rotate(c,temp(_x1,asci),textangle,size)
cpt(_x1)=np
var copyy=np.y
If charangle<>0 Then
if flag then var p=1 else p=(z6-1)
c2=Type<point2d>(xpos+(size*8)*p*(Cos(textangle*cr)),ypos+(size*8)*p*(Sin(textangle*cr)))
rotate(c2,cpt(_x1),charangle,1)
if flag then np.y=copyy
cpt(_x1)=np
End If
If infoarray(_x1,asci).x<>0 Then 'paint only relevant points
If Abs(size)>0 Then
glVertex3f (cpt(_x1).x-d_x,wy-(cpt(_x1).y-d_y),0)
glColor4f (colour(1),colour(2),colour(3),colour(4))
glVertex3f (cpt(_x1).x+d_x,wy-(cpt(_x1).y+d_y),0)
End If
End If
Next _x1
dx=dx+8+4*(sin(charangle*cr))*flag
skip:
Next z6
glend
End Sub
Sub init Constructor 'automatic loader
Dim As Double col(1 To 4)
drawstring(0,0,"",col(),0)
Screen 0
End Sub
Function framecounter() As Integer
Var t1=Timer,t2=t1
Static As Double t3,frames,answer
frames=frames+1
If (t2-t3)>=1 Then
t3=t2
answer=frames
frames=0
End If
Return answer
End Function
Function regulate(MyFps As Integer,Byref fps As Integer) As Integer
fps=framecounter
Static As Double timervalue
Static As Double delta,lastsleeptime,sleeptime
Var k=1/myfps
If Abs(fps-myfps)>1 Then
If fps<Myfps Then delta=delta-k Else delta=delta+k
End If
sleeptime=lastsleeptime+((1/myfps)-(Timer-timervalue))*(2000)+delta
If sleeptime<1 Then sleeptime=1
lastsleeptime=sleeptime
timervalue=Timer
Return sleeptime
End Function
sub gltextcolor(a() as double,r as double,g as double,b as double,al as double=255)
a(1)=r/255:a(2)=g/255:a(3)=b/255:a(4)=al/255
end sub
#define map(a,b,x,c,d) ((d)-(c))*((x)-(a))/((b)-(a))+(c)
dim as integer xres,yres
screeninfo xres,yres
Screenres xres,yres,32,,2
setup
dim as double pi=4*atn(1)
dim as double rot=7*pi
dim as double inc
dim as integer fps
dim as double c(1 to 4)
do
var sleepytime=regulate(33,fps)
inc=inc+.1
glClear (GL_COLOR_BUFFER_BIT)
'example for fast fillcircle and circle
glpolygonfill(.1*xres,.9*yres,0,40,40,60,(1,0,1,1))
glpolygon(.1*xres,.7*yres,0,40,40,60,(0,1,1,1))
for z as double=inc to rot+inc step rot/250
var angledegrees=z*180/pi
var radius=map(inc,(rot+inc),z,30,300)
var xpos1=xres/2+ ((radius+00)*cos(z))
var ypos1=yres/2+ ((radius+00)*sin(z))
var xpos2=xres/2+ ((radius+20)*cos(z))
var ypos2=yres/2+ ((radius+20)*sin(z))
var xpos3=xres/2+ ((radius+45)*cos(z))
var ypos3=yres/2+ ((radius+45)*sin(z))
var size=map(inc,(rot+inc),z,1.5,3.5)
var col=map(inc,(rot+inc),z,120,250)
'my method
''gltextcolor c(),col/2,col/2,75
''drawstring xpos1,ypos1 , " * " , c(), size, angledegrees,
''gltextcolor c(),col/1.5,col/1.5,75
'' drawstring xpos1,ypos1 , "( )" , c(), size, angledegrees,
'Albert's method
gltextcolor c(),col/1.5,col/1.5,75
drawstring xpos1,ypos1 , "(" , c(), size, angledegrees,
gltextcolor c(),col/2,col/2,75
drawstring xpos2,ypos2 , "*" , c(), size, angledegrees,
gltextcolor c(),col/1.5,col/1.5,75
drawstring xpos3,ypos3 , ")" , c(), size, angledegrees,
if (rot+inc)-z <rot/250 then
drawstring xpos1,ypos1 , chr(2) ,c(),2.5* size, angledegrees,
end if
next z
var text = "!!--SNAKEY--!!"
if int(inc) mod 2 = 0 then
gltextcolor c(),100,0,100
drawstring (xres/2)-((len(text)*70)/2) ,yres/2.5-6,string(len(text)-1,chr(219)),c(),8.5
gltextcolor c(),200,200,0
drawstring (xres/2)-((len(text)*70)/2),yres/2.5 , text , c() , 8 ,0,
end if
gltextcolor c(),0,200,0
drawstring 10,10,"FPS= " & fps,c(),2
flip
sleep sleepytime,1
loop until len(inkey)