DisplayText(x.I, y.I, Texte.S, Taille.I, Couleur.I, Angle.I)
Affiche un texte en épargnant le CPU de s'occuper de la fonte, pixel par pixel.
La fonte utilisée est "verdana" et peut être modifiée.
Il n'utilise qu'une fonte : c'est pour que quiconque veuille en utiliser plusieurs comprenne la technique, et fasse son ensemble de fonte à sa manière : ensemble de tableaux, listes ou maps. Les méthodes sont trop diversifiées pour en choisir une et, surtout, quand on veut du texte en GPU, très rapidement, donc une seule fonte, autant ne pas se coltiner une pavasse inutilisée (gestion de plusieurs fontes pour une seule fonte).
Les tableaux utilisés pour ça ont un nom qui commence par "Char" de l'anglais "character". Un petit clin d'oeil à l'ordinateur EXL100 et son instruction CALL CHAR(N, A$) en 1989 qui permettait de réécrire les 64 pixels d'un caractère entre 0 et 127 (N) en injectant un nombre hexadécimal de 64 bits sous forme de chaîne hexadécimale.
Mon conseil :
1) Cherchez l'appel DisplayText()
2) Rajouter vos DisplayText() perso pour tester.
3) Démontez le superflu qui ne vous intéresse pas.
4) Observez le principe, et gardez-le comme référence, il n'y a pas 36 méthodes en natif, seulement celle-là.
L'alphachannel est géré.
Si quelqu'un trouve un code antérieur à 2015 qui utilise ce principe, qu'il n'hésite pas à ajouter un lien, ça rendra hommage à d'autres. On est pionnier contre soi-même avant tout, avant d'être pionnier en concurrence contre les autres. L'allusion aux nombres premiers est assez éloquente : la logique étant stricte, il existe x domaines scientifiques où rechercher indépendamment aboutit à des résultats strictement similaires à d'autres, et donc à avoir perdu du temps. Et réfléchir en groupe en rangeant son ego, c'est tout simplement gagner du temps, beaucoup de temps.
Petite nota pour un très récent critiqueur :
Code : Tout sélectionner
ClearScreen(#BackColor)
Code : Tout sélectionner
;********************************************************************************************************************************************
Procedure InitScreen()
ExamineDesktops()
Global Dw = DesktopWidth(0)
Global Dh = DesktopHeight(0)
Global Dd = DesktopDepth(0)
InitSprite()
InitKeyboard()
OpenScreen(Dw, Dh, Dd, "")
EndProcedure
Global Dim CharFont.I(80)
Global Dim CharSprite.I(80, 255)
Global Dim CharW.I(80, 255)
Global Dim CharH.I(80, 255)
#BackColor = $406080
#CaseBackColor = $FFFFFF
#CaseTextColor = $000000
Procedure InitSpriteCharacter(SizeList.S)
Define SizeSize = CountString(SizeList, ";")
Dim Size.I(SizeSize)
For K = 0 To SizeSize
Size(K) = Val(StringField(SizeList, 1 + K, ";") )
Next
For K = 0 To SizeSize
J = Size(K)
CharFont(J) = LoadFont(#PB_Any, "Verdana", J)
Next
StartDrawing(ScreenOutput() )
For K = 0 To SizeSize
J = Size(K)
DrawingFont(FontID(CharFont(J) ) )
For I = 1 To 255
CharW(J, I) = TextWidth(Chr(I) )
CharH(J, I) = TextHeight(Chr(I) )
Next
Next
StopDrawing()
For K = 0 To SizeSize
J = Size(K)
For I = 48 To 57
CharSprite(J, I) = CreateSprite(#PB_Any, CharW(J, I), CharH(J, I), #PB_Sprite_AlphaBlending)
StartDrawing(SpriteOutput(CharSprite(J, I) ) )
DrawingFont(FontID(CharFont(J) ) )
DrawingMode(#PB_2DDrawing_AllChannels)
DrawText(0, 0, Chr(I), RGBA(0, 0, 0, 255), RGBA(255, 255, 255, 0) )
StopDrawing()
Next
For I = 65 To 90
CharSprite(J, I) = CreateSprite(#PB_Any, CharW(J, I), CharH(J, I), #PB_Sprite_AlphaBlending)
StartDrawing(SpriteOutput(CharSprite(J, I) ) )
DrawingFont(FontID(CharFont(J) ) )
DrawingMode(#PB_2DDrawing_AllChannels)
DrawText(0, 0, Chr(I), RGBA(0, 0, 0, 255), RGBA(255, 255, 255, 0) )
StopDrawing()
Next
Next
EndProcedure
Procedure DisplayText(x, y, A$, Size, Color, Angle = 0)
Define AngleRad.F = Angle * #PI / 180.0
If Angle
For I = 1 To Len(A$)
A = Asc(Mid(A$, I, 1) )
If Angle
RotateSprite(CharSprite(Size, A), Angle, #PB_Absolute)
EndIf
DisplayTransparentSprite(CharSprite(Size, A), X, Y, 255, Color)
X + (CharW(Size, A) * Cos(AngleRad) )
Y + (CharW(Size, A) * Sin(AngleRad) )
Next
Else
For I = 1 To Len(A$)
A = Asc(Mid(A$, I, 1) )
RotateSprite(CharSprite(Size, A), 0, #PB_Absolute)
DisplayTransparentSprite(CharSprite(Size, A), X, Y, 255, Color)
X + CharW(Size, A)
Next
EndIf
EndProcedure
Macro GraphDrawExemple()
InitSpriteCharacter()
Repeat
Lap0 = Lap
Lap = ElapsedMilliseconds()
Delay(16)
ExamineKeyboard()
ClearScreen(#BackColor)
DisplayText(0, 0, Str(Lap - Lap0), 20, RGB(255, 0, 0) )
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
EndMacro
Macro AjoutePremier(X)
Prim(PrimeQuantity) = X
Prime2(PrimeQuantity) = X * X
PrimeQuantity + 1
EndMacro
Macro IsPrime5(Nombre)
bPremier = 1
For Jprime = 2 To MostPrime2
If Nombre % Prim(Jprime) = 0
bPremier = 0
Break
EndIf
Next
EndMacro
Macro TestPrime5(Pas)
If Prime2(MostPrime2 + 1) <= Iprime
MostPrime2 + 1
EndIf
IsPrime5(Iprime)
If bPremier
AjoutePremier(Iprime)
EndIf
Iprime + Pas
EndMacro
InitScreen()
InitSpriteCharacter("10;20")
nDebut = 5
nFin = 100000
Global Dim Prim.I(nFin)
Global Dim Prime2.I(nFin)
AjoutePremier(2)
AjoutePremier(3)
Iprime = nDebut
Repeat
TestPrime5(2)
TestPrime5(4)
Until Iprime > nFin
MaxPrime = PrimeQuantity - 1
BackColor = RGB(0, 0, 255)
CellW = 64
CellH = 24
FirstColumnW = 40
FirstRowH = 80
CribleSp = CreateSprite(#PB_Any, CellW, CellH, #PB_Sprite_AlphaBlending)
If StartDrawing(SpriteOutput(CribleSp) )
DrawingMode(#PB_2DDrawing_AllChannels)
W = OutputWidth()
H = OutputHeight()
Box(0, 0, W, H, RGBA(0, 0, 0, 255) )
StopDrawing()
EndIf
Crible1er = CreateSprite(#PB_Any, CellW, CellH, #PB_Sprite_AlphaBlending)
If StartDrawing(SpriteOutput(Crible1er) )
DrawingMode(#PB_2DDrawing_AllChannels)
W = OutputWidth()
H = OutputHeight()
Box(0, 0, W, H, RGBA(255, 0, 0, 255) )
StopDrawing()
EndIf
DecalYMax = (CellH * (MaxPrime + 1) ) - (Dh - FirstRowH)
Repeat
Lap0 = Lap
Lap = ElapsedMilliseconds()
Delay(16)
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Right)
DecalAX + 2
EndIf
If KeyboardPushed(#PB_Key_Left)
DecalAX - 2
EndIf
If KeyboardPushed(#PB_Key_Down)
DecalAY + 2
EndIf
If KeyboardPushed(#PB_Key_Up)
DecalAY - 2
EndIf
If DecalAX
DecalX + DecalAX
If DecalAX > 0
DecalAX - 1
Else
DecalAX + 1
EndIf
If DecalX < 0
DecalX = 0
DecalAX = 0
EndIf
EndIf
If DecalAY
DecalY + DecalAY
If DecalAY > 0
DecalAY - 1
Else
DecalAY + 1
EndIf
If DecalY < 0
DecalY = 0
DecalAY = 0
EndIf
If DecalY > DecalYMax
DecalY = DecalYMax
DecalAY = 0
EndIf
EndIf
ClearScreen(BackColor)
DisplayText(0, 0, Str(Lap), 20, RGB(255, 0, 0) )
Displaytext(200, 0, Str(Prim(MaxPrime) ), 20, RGB(0, 255, 255) )
JDebutY = DecalY / CellH
JFinY = JDebutY + ((Dh - FirstRowH) / CellH)
For I = JDebutY To JFinY
DisplayText(0, FirstRowH + CellH * I - DecalY, Str(Prim(I) ), 10, RGB(255, 255, 255) )
Next
JDebutX = DecalX / CellW + 1
JFinX = JDebutX + ((Dw - FirstColumnW) / CellW)
For J = JDebutX To JFinX
DisplayText(FirstColumnW + CellW * J - DecalX, 40, Str(J), 10, RGB(255, 255, 255), -20)
Next
For I = JDebutY To JFinY
For J = JDebutX To JFinX
X = FirstColumnW + CellW * J - DecalX
Y = FirstRowH + CellH * I - DecalY
If (J % Prim(I) ) = 0
If J = Prim(I)
DisplaySprite(Crible1er, X, Y)
Else
DisplaySprite(CribleSp, X, Y)
EndIf
EndIf
Next
Next
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)