PDA

View Full Version : qt: matrix + blurTextEffect



Lionheart008
30-12-2009, 14:31
good morning!

I am looking for the tbgl example here at the board (petr has done it?), where I can see some "matrix" effects for characters/letters dropping down from the top. Didn't found it. I found some letters for this "matrix effect", but not the special tbgl example (with "tbgl_font.bmp") as background so far as I can remember.

next: have done little play with blur texteffect, it's not new, but I like it and perhaps I can use this effect for my idea with matrix effects and all characters there. of course I have to adept this example with tbgl_entities mode, will come next days/week.


' frankos_Basic bluring effect

Uses "TBGL"
Uses "UI"

Dim hWnd As DWord
Dim cx As Integer
Dim cy As Integer

hWnd = TBGL_CreateWindowEx(" => test_bEffect - press ESC to quit, today: " + Date$, 1024, 768,32, %TBGL_WS_CLOSEBOX or %TBGL_WS_MaximizeBox or %TBGL_WS_MinimizeBox)
TBGL_ShowWindow
'TBGL_LoadTexture "Textures\Effect1abc.bmp", 1, %TBGL_TEX_MIPMAP
TBGL_LOADTEXTURE "Textures\M.bmp", 1, %TBGL_TEX_MIPMAP

TBGL_UseTexture 1 ' We will turn texturing on
TBGL_BindTexture 1 ' We will use texture 0


GetAsyncKeyState(%VK_ESCAPE) ' Resets ESC key status before checking

tbgl_UseDepthMask 0
TBGL_UseBlend 1
TBGL_UseBlend 2
'----------------------------------

Dim FrameRate As Single
dim i as long
Dim BlurFactor As Long = 48'32'64

dim R, G, B as long

Dim actualImage As Long = 1
dim actualImageAngle as single = 0
dim oldImageAngle(BlurFactor) as single = 0

R = rnd(0,255)
G = rnd(0,255)
B = rnd(0,255)

While IsWindow(hWnd)
FrameRate = TBGL_GetFrameRate

tbgl_ClearFrame
TBGL_Camera 0,0,7,0,0,0

actualImageAngle += 126 / FrameRate '96
ActualizeBlur(actualImageAngle)

if actualImageAngle > 180 then
ResetBlur
actualImage += 1
actualImageAngle = 0
R = rnd(0,255)
G = rnd(0,255)
B = rnd(0,255)
end if


for i = 1 to BlurFactor
tbgl_PushMatrix

tbgl_Rotate 180+oldImageAngle(i),0,0,1
tbgl_Scale 1+oldImageAngle(i)/45, 1+oldImageAngle(i)/45, 1
tbgl_Color R/i, G/i, B/i

DrawTextLineFromBMP(actualImage, 3)
sleep 10
tbgl_PopMatrix
next

tbgl_DrawFrame

If GetWindowKeyState( hWnd, %VK_ESCAPE) Then Exit While

Wend

TBGL_DestroyWindow

sub DrawTextLineFromBMP( nLine as long, numLines as long ) ' which line of how many
Local oneLineSize As Single = 2 / numLines

tbgl_BeginPoly %GL_QUADS
TBGL_TexCoord2D 0, 2 -(oneLineSize*(nLine-2))
TBGL_Vertex -2, oneLineSize, 0

TBGL_TexCoord2D 2, 2-(oneLineSize*(nLine-2))
TBGL_Vertex 2, oneLineSize, 0

TBGL_TexCoord2D 2, 2-(oneLineSize*nLine)
TBGL_Vertex 2, -oneLineSize, 0

TBGL_TexCoord2D 0, 2-(oneLineSize*nLine)
TBGL_Vertex -2, -oneLineSize, 0


tbgl_EndPoly
end sub

sub ActualizeBlur( bValue as single )

local j as long

for j = BlurFactor-1 to 1 step -1
oldImageAngle(j+1) = oldImageAngle(j)
next

oldImageAngle(1) = bValue

end sub

sub ResetBlur()
local j as long

for j = 1 to BlurFactor
oldImageAngle(j) = 0
next

end sub


thanks, nice day to all frank

Lionheart008
30-12-2009, 14:38
next one :)

I would like to build something like that and see "neo's" face in background coming up for closer shapes of his face for example by pixel or points modus. I will check if it's possible.


'------ franks searching for matrix effect

Uses "TBGL", "console", "ui"

Randomize Timer

DIM hWnd as dword
Dim cx,cxx As Integer
Dim cy,cyy As Integer
DIM hFont AS DWORD = Font_Create("Courier New", 14)

' We will initialize OpenGL and internal buffers
' Function also returns window handle
hWnd = TBGL_CreateWindowEx ("searching for matrix effect with Neo's face ", 1024, 768, 32, %TBGL_WS_CLOSEBOX Or %TBGL_WS_MINIMIZEBOX Or %TBGL_WS_MAXIMIZEBOX) '800, 600,

tbgl_ShowWindow ' This will display the window on the screen

TBGL_BuildFont hFont

GetAsyncKeyState %VK_ESCAPE ' Reset status of the ESCAPE to prevent immediate quit

'---This is necessary when using RND functions. It seeds random number generator
randomize

while IsWindow hWnd ' While window exists, we will draw and check for ESCAPE

'win_settitle(hWnd, TBGL_GetFramerate & " FPS")

tbgl_ClearFrame ' This clears the frame and prepares it for drawing

TBGL_Camera 50, 50, 100, 50, 50, 0
'TBGL_Camera 0, 0, 80, 0, 40, 0

TBGL_PointSize Rnd(0.25,0.9)
TBGL_LineWidth 1
TBGL_BeginPoly %GL_POINTS

for cy = 1 to 100
for cx = 1 to 136
If Mod(cx, 7) And Mod(cy, Rnd(180)) Then
TBGL_Color 255, 50 + Rnd(1, 80), 0
TBGL_PointSize Rnd(1, 4)
else
TBGL_Color 0, 175 + Rnd(1, 120), 255
TBGL_PointSize Rnd(0.25,2.35)
end if

tbgl_BeginPoly %GL_POINTS
tbgl_Vertex cx, cy, 0
TBGL_EndPoly

Next
Next

TBGL_BeginPoly %GL_POINTS
For cyy = 10 To 60
For cxx = 10 To 96
If Mod(cxx, 10) And Mod(cyy, Rnd(220)) Then
TBGL_Color 55, 200 + Rnd(1, 100), 250
TBGL_PointSize Rnd(0.25, 2)
Else
TBGL_Color 100, 175 + Rnd(100, 220), 255+Sin(GetTickCount*118)/100
TBGL_PointSize Rnd(0.15,0.45)
End If

TBGL_BeginPoly %GL_POINTS
TBGL_Vertex cxx, cyy, 0
TBGL_EndPoly
Next
Next

TBGL_Color 255, 175, 0
TBGL_USEBLEND %TRUE
TBGL_PrintFont "I am looking for a floating matrix effect for background", -1, 0, 0

TBGL_DrawFrame ' This will display the scene

IF GetAsyncKeyState %VK_ESCAPE THEN EXIT while

Wend
TBGL_Killfont

tbgl_DestroyWindow ' This will destroy the window


servus, frank

Michael Hartlef
30-12-2009, 14:38
Thanks for sharing! Nice example! :eusaclap:

Petr Schreiber
30-12-2009, 18:28
Nice examples Frank!

Lionheart008
30-12-2009, 22:56
thank you both :)

here a little modification of another tbgl font example. I have used matrix fontes ;)
you can push numbers (1-6) and push it multiple times to see font effect. it's a first step in right direction I hope, but I have to investigate more to get the whole and in my eyes heavy code (I have caught fully c++ code for matrix fall character effect ! ;) ).

my first example with this kind of fonts:

'---- matrixFontes play one from frank to 'explore fall characters matrix' effect
'---- from movie, started 30.12.2009

Uses "TBGL", "console"
Dim hWnd As Dword

hWnd = TBGL_CreateWindowEx("MatrixFontes Play1: Use 1,2,3,4,5,6 to create textfonts - press ESC to quit", 800, 600, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX)
TBGL_ShowWindow

type TEffect
eInUse as long
eType as string * 16
eX as long
eY as long
eStart as long
eText as string * 1024
eExtra as string * 1024
end type

TextFX_Init( "matrixfontes.bmp", 32 )
TextFX_Cast("Hello!"+$CRLF+"Use 1,2,3,4,5,6 to born texts", 1, 12, "fade", "255,0,0,10000,center")

tbgl_UseLighting %TRUE
tbgl_UseLightSource %GL_LIGHT0, %TRUE

TBGL_ResetKeyState

While TBGL_IsWindow(hWnd)

tbgl_ClearFrame

tbgl_Camera 10,10,10,0,0,0

tbgl_Color 255,255,255

TextFX_Engine

'TBGL_Rotate GetTickCount/100,1,1,1
'character = Cos(GetTickCount/3000)/2

tbgl_DrawFrame

If TBGL_GetWindowKeyState( hWnd, %VK_ESCAPE) Then Exit While

If TBGL_GetWindowKeyState( hWnd, %VK_1) Then
TextFX_Cast("Left is bad",1,Rnd(1,26), "fade", Format$(Rnd(128,255))+","+Format$(Rnd(128,255))+","+Format$(Rnd(128,255))+","+Format$(Rnd(1000,5000))+",left")
Sleep 70
end if

If TBGL_GetWindowKeyState( hWnd, %VK_2) Then
TextFX_Cast("Center is good",1,Rnd(1,26), "fade", Format$(Rnd(12,255))+","+Format$(Rnd(128,255))+","+Format$(Rnd(12,155))+","+Format$(Rnd(1000,5000))+",center")
Sleep 70
end if

If TBGL_GetWindowKeyState( hWnd, %VK_3) Then
TextFX_Cast("Right is superb",1,Rnd(1,26), "fade", Format$(Rnd(128,255))+","+Format$(Rnd(128,255))+","+Format$(Rnd(128,255))+","+Format$(Rnd(1000,5000))+",right")
Sleep 70
end if

If TBGL_GetWindowKeyState( hWnd, %VK_4) Then
TextFX_Cast("free texty",Rnd(1,15),Rnd(1,26), "fade", Format$(Rnd(128,255))+","+Format$(Rnd(128,255))+","+Format$(Rnd(128,255))+","+Format$(Rnd(1000,5000))+",hehe- nothing")
Sleep 70
end if

If TBGL_GetWindowKeyState( hWnd, %VK_5) Then
TextFX_Cast("*"+$CRLF+"***"+$CRLF+"*",1,Rnd(1,26), "fade", Format$(Rnd(100,255))+","+Format$(Rnd(128,255))+","+Format$(Rnd(128,155))+","+Format$(Rnd(1000,5000))+",center")
Sleep 70
end if

If TBGL_GetWindowKeyState( hWnd, %VK_6) Then
TextFX_Cast("all frankos eva loves",Rnd(1,12),Rnd(10,46), "fade", Format$(Rnd(128,255+Sin(GetTickCount*128)/20))+","+Format$(Rnd(50,155))+","+Format$(Rnd(100,255))+","+Format$(Rnd(4000,5000))+",center")
Sleep 70
End If
Wend

TBGL_DestroyWindow

sub TextFX_Init( fontFile as string, howMuchEffectsAtTheSameTime as long)

TBGL_LoadBMPFont fontFile

global EffectsMax as long = howMuchEffectsAtTheSameTime
global EffectsID as long
global EffectBuffer(EffectsMax) as TEffect

end sub

sub TextFX_Engine()

local i as long

tbgl_ResetMatrix
TBGL_USELighting %FALSE
TBGL_USEDepthMask %FALSE
TBGL_USEBlend %TRUE

for i = 1 to EffectsMax
if EffectBuffer(i).eInUse = 1 then call "TextEffectsFunction_"+trim$(EffectBuffer(i).eType) (i)
next

TBGL_USEDepthMask %TRUE
TBGL_USEBlend %FALSE
TBGL_USELighting %TRUE

end sub

sub TextEffectsFunction_Fade( index as long )

local CurTime as long = gettickcount
local DoNotDraw as long = 0
local i as long
local TextToRender as string = trim$(EffectBuffer(index).eText)
local TextChunk as string
local TextParams as string = trim$(EffectBuffer(index).eExtra)
local r as long = val(PARSE$(TextParams, ",", 1))
local g as long = val(PARSE$(TextParams, ",", 2))
local b as long = val(PARSE$(TextParams, ",", 3))
local duration as long = val(PARSE$(TextParams, ",", 4))
Local durationStep As Long = duration/3
local textAlign as string = PARSE$(TextParams, ",", 5)


local TimeDif as long = CurTime - EffectBuffer(index).eStart

if TimeDif < durationStep then
tbgl_Color r/255*(TimeDif)/(durationStep/255), g/255*(TimeDif)/(durationStep/255), b/255*(TimeDif)/(durationStep/255)

elseif TimeDif < durationStep*2 then
tbgl_Color r,g,b

elseif between(TimeDif, durationStep*2, durationStep*3) then

tbgl_Color r-r/255*(TimeDif-durationStep*2)/(durationStep/255), g-g/255*(TimeDif-durationStep*2)/(durationStep/255), b-b/255*(TimeDif-durationStep*2)/(durationStep/255)

else
DoNotDraw = 1

end if

if DoNotDraw = 0 then
for i = 1 to parsecount(TextToRender, $CRLF)
TextChunk = parse$(TextToRender, $CRLF, i)

select case TextAlign
case "center"
TextChunk = cset$( TextChunk, 35 using $SPC)

case "left"
TextChunk = lset$( TextChunk, 35 using $SPC)

case "right"
TextChunk = rset$( TextChunk, 35 using $SPC)

Case "all"
TextChunk = CSet$+4*Rnd( TextChunk, 35 Using $SPC)

End Select

tbgl_PrintBMP TextChunk,EffectBuffer(index).eX,EffectBuffer(index).eY-1+i
next
end if

end sub

sub TextFX_Cast( sText as string, x as long, y as long, effectType as string, extraPart as string )

incr EffectsID
if EffectsID > EffectsMax then EffectsID = 1

EffectBuffer(EffectsID).eInUse = 1
EffectBuffer(EffectsID).eType = effectType
EffectBuffer(EffectsID).eX = X
EffectBuffer(EffectsID).eY = Y
EffectBuffer(EffectsID).eStart = GetTickCount
EffectBuffer(EffectsID).eText = sText
EffectBuffer(EffectsID).eExtra = extraPart

end sub



nice evening, that's all for me this year! 8)

best regards to all thinbasic users and friends,

lionheart