View Full Version : Lydia - Particles [SPLIT from original hunters thread]
lydia_sp
18-08-2009, 20:16
hello, dear petr, thanks for your explanations. first I thought it was a joke with tbgl_getlastGLerror. (I used it but got no comment!) . Do you know the command "tbgl get_lastGLerrorfixedall" ? it`s really new! press F1 and wonder. it`s also a secret horrible command!
I try to learn to use particles. after producting some error messages with other particle scripts I tried the tbgl example with particles and fonts. thanks for this example to make experience. my little work I publish here. three light new versions of your original particle-font script. but I seem to know where you have found this script ;)
my question:
a) how I can reduce speed of particles
b) make a break to the running script, how ?
c) particles are points ? you have used a sphere, isn`t it? I can use everything as particle as object (UDT) I can imagine.
ok. my pc make trouble again. I uses whole time pc of my girl friend. I will buy next month new netbook. Anybody has made good experiences with netbooks ? (Asus). Would be nice to hear some critics if this little pc has mercedes or porsche power.
hasta luego cervisa !
Petr Schreiber
18-08-2009, 21:46
Do you know the command "tbgl get_lastGLerrorfixedall" ? it`s really new! press F1 and wonder. it`s also a secret horrible command!
Hehe, I wish all problems would be that easy to fix :)
how I can reduce speed of particles
Assigning smaller value to Particle(i).speed could do the job :). Please note the code as is is not fully framerate synced.
I would recommend to start your own particle system based of some more modern code, like here (http://community.thinbasic.com/index.php?topic=2849.msg21496#msg21496).
make a break to the running script, how ?
Like a pause? Just stop rendering :)
Or you can divide the particle rendering to two braches:
- calculations
- render
When you need to pause script, but watch the output, you will not call calculations procedure
particles are points ? you have used a sphere, isn`t it? I can use everything as particle as object (UDT) I can imagine.
Well, in the code there is quad used, the sphere was used to just represent the particle emitter:
TBGL_BeginPoly %GL_Quads
TBGL_TexCoord2D 0,1
TBGL_Vertex -1,1,0
TBGL_TexCoord2D 1,1
TBGL_Vertex 1,1,0
TBGL_TexCoord2D 1,0
TBGL_Vertex 1,-1,0
TBGL_TexCoord2D 0,0
TBGL_Vertex -1,-1,0
TBGL_EndPoly
... but you are free to experiment with other shapes.
For graphic programming, I would not go for netbook, they usually have Intel graphics. If you find something with NVIDIA or ATi, then go for it :)
Petr
lydia_sp
19-08-2009, 12:20
hello again. my solution with star_twinkled, but you cannot see anymore stars ! :shock:
I eat them. gulp. therefore many spheres are raising. may be there are some things going wrong with blending and masking, but I am learning. I made new light entity input. But I have destroyed stars, sorry!
This star twinkled script makes a lot of fun. what is new about this tbgl entities kind of coding? will be a good basis for my particle example. pause or break isn't important. later.
thanks petr for your advices! I need them one day. the star twinkled version of charles I love it too!
cheerios. lydia
Petr Schreiber
20-08-2009, 20:23
Hi Lydia,
it looks interesting, but I must warn you to not use sphere in such a huge amounts.
One sphere has by default about 600 triangles* (unless changed by tbgl_setPrimitiveQuality).
Rendering 3000 spheres means spitting 1 800 000 triangles on screen. Considering mostly spread Intel onboard cards can handle at smooth rate barely 30 000 (60times less), you can see building your scripts this way will result in situation, where only the owners of middle and high end cards can watch it at 25+ FPS.
Of course, take the above as strictly technical point of view - the effect is nice!
Do not hesitate to experiment more to the extreme> change the moving path, make them pulse... :)
Petr
* sure the rendering code is optimized using quad strips to eliminate big data traffic, but graphic card driver will convert it to triangles anyway
lydia_sp
21-08-2009, 18:33
hi petr, all other guys.
Do not hesitate to experiment more to the extreme> change the moving path, make them pulse... Smile
ok :) I play with my script!
make pause with space bar and insert pulsing, but not very strong, you can see. I need time to create own particle entity. I have all things I need for. thats good for me. perhaps next week I am ready. I see green land to understand more about tbgl. two weeks ago there was only a black hole. thanks for help. test my script. or make it better. you are welcome.
'
' The starfield
' Petr Schreiber, started on 08-07-2009
' lydia_sp partido
Uses "TBGL"
BEGIN CONST
' -- Setup
%numStars = 2000
%numSphere = 200
' -- Display lists
%lStar = 1
%lSphere = 1
%lLight = 1
%lPCODE = 1
' -- Textures
%tStar = 1
' -- Scene IDs
%sScene = 1
' -- Entity IDs
%eCamera = 1
%eFirstStar
%eLastStar = %eFirstStar + %numStars - 1
%eFirstSphere
%eLastSphere = %eFirstSphere + %numSphere - 1
%eLight
END CONST
dim p_StarPulse, pause as single
dim j as long
%EFFECT_QUALITY = 12
FUNCTION TBMAIN()
LOCAL hWnd As DWORD
LOCAL FrameRate AS DOUBLE
' -- Create and show window
local dx, dy, db as long
tbgl_GetDesktopInfo dx, dy, db
hWnd = TBGL_CreateWindowEx("TBGL Lydias StarLight_Script - press ESC to quit, Spacebar to pause", dx, dy, db, %TBGL_WS_WINDOWED or %TBGL_WS_CLOSEBOX)
TBGL_ShowWindow
' -- Prepare resources
tbgl_LoadTexture "Textures\Star.bmp", %tStar, %TBGL_TEX_ANISO, 16
tbgl_NewList %lStar
tbgl_UseTexturing %TRUE
tbgl_BindTexture %tStar
tbgl_BeginPoly %GL_QUADS
tbgl_TexCoord2D 0, 0
tbgl_Vertex -1, -1
tbgl_TexCoord2D 1, 0
tbgl_Vertex 1, -1
tbgl_TexCoord2D 1, 1
tbgl_Vertex 1, 1
tbgl_TexCoord2D 0, 1
tbgl_Vertex -1, 1
tbgl_EndPoly
tbgl_EndList
tbgl_NewList %lSphere
tbgl_sphere 0.25
tbgl_EndList
tbgl_NewList %lLight
tbgl_sphere 0.125
tbgl_EndList
tbgl_NewList %lPCODE
tbgl_sphere 0.125
LydPCode()
tbgl_EndList
' -- Create scene
TBGL_SceneCreate(%sScene)
' -- Create basic entities
TBGL_EntityCreateCamera(%sScene, %eCamera)
TBGL_EntitySetPos(%sScene, %eCamera, 0, 0, 0)
TBGL_EntitySetTargetPos(%sScene, %eCamera, 0, 0, -2)
''-- LIGHT
TBGL_EntityCreateLight(%sScene, %eLight, %TBGL_Lighttype_Directional)
'TBGL_EntitySetAmbient( %sScene, %eLight, 100, 255, 220 )
TBGL_EntitySetPos(%sScene, %eLight, 0, 0, 0)
TBGL_EntitySetColor(%sScene, %eLight, 100, 255, 220)
TBGL_EntitySetTargetPos(%sScene, %eLight, 0, 0, -2)
' -- Create something to look at - star billboards
dim e,f as long
dim s,k as double
for e = %eFirstStar to %eLastStar
TBGL_EntityCreateDLSlot(%sScene, e, 0, %lStar)
TBGL_EntitySetPos(%sScene, e, rndf(-50,50), rndf(-50,50), rndf(-150, 0))
s = rndf(0.1, 0.5)
TBGL_EntitySetScale(%sScene, e, s,s,s)
next
TBGL_UseBlend %TRUE
TBGL_UseDepthMask %FALSE
dim x,y,z,c,p as double
dim fr,fg,fb,msk as long
msk=127
' -- Resets status of all keys
TBGL_ResetKeyState()
' -- Main loop
While TBGL_IsWindow(hWnd)
FrameRate = TBGL_GetFrameRate
''--- one
for e = %eFirstStar to %eLastStar
TBGL_EntityTurn(%sScene, e, 0, 0, 45/FrameRate)
TBGL_EntityPush(%sScene, e, 0, 0, 5/FrameRate)
TBGL_EntityGetPos(%sScene, e, x, y, z)
' -- Color change to simulate twinkle
c = sin(gettickcount*0.01+e)*.25+1.75
'
'pseudorandom tints
fr=(e*123) and msk
fg=(e*571) and msk
fb=(e*579) and msk
'
TBGL_EntitySetColor(%sScene, e, fr*c, fg*c, fb*c)
' -- If particle is behind camera, it is time to recycle it in depth
if z > 1 then
TBGL_EntitySetPos(%sScene, e, rndf(-50,50), rndf(-50,50), -150)
s = rndf(0.1, 1.25)
TBGL_EntitySetScale(%sScene, e, s,s,s)
end if
next
TBGL_UseBlend %TRUE
TBGL_UseDepthMask %TRUE
''-- lydia input ---------------------------------
for f = %eFirstSphere to %eLastSphere
TBGL_EntityCreateDLSlot(%sScene, f, 0, %lSphere)
TBGL_EntitySetPos(%sScene, f, rndf(-40,40), rndf(-40,40), rndf(-80, 0))
k = rndf(0.1, 0.4)
TBGL_EntitySetScale(%sScene, f, k,k,k)
next
p_StarPulse = 1.25+cos(GetTickCount/500)*128
for f = %eFirstSphere to %eLastSphere
TBGL_EntityTurn(%sScene, f, 0, 0, 75/FrameRate)
TBGL_EntityPush(%sScene, f, p_StarPulse, 25/FrameRate, p_StarPulse)
'TBGL_EntityPush(%sScene, f, 0, 0, 12/FrameRate)
TBGL_EntityGetPos(%sScene, f, x, y, z)
' -- Color change to simulate twinkle
p = sin(gettickcount*0.02+f)*.45+1.55
'
'pseudorandom tints
fr=(f*123) and msk
fg=(f*571) and msk
fb=(f*579) and msk
'
TBGL_EntitySetColor(%sScene, f, fr*c, fg*c, fb*c)
' -- If particle is behind camera, it is time to recycle it in depth
if y > 10 then
TBGL_EntitySetPos(%sScene, f, rndf(-40,40), rndf(-40,40), -120)
k = rndf(0.2, 1.25)
TBGL_EntitySetScale(%sScene, f, k,k,k)
end if
next
tbgl_calllist %lSphere
tbgl_calllist %lLight
tbgl_calllist %lPCODE
TBGL_UseBlend %TRUE
TBGL_UseDepthMask %TRUE
''- light
TBGL_EntityTurn(%sScene, %eLight, 0, p_StarPulse, -25/FrameRate)
TBGL_EntityPush(%sScene, %eLight, 0, 75/FrameRate, p_StarPulse)
TBGL_EntityPush(%sScene, %eCamera, 0, 0.75/FrameRate, 0.2/FrameRate)
TBGL_EntityGetPos(%sScene, %eLight, x, y, z)
TBGL_GETLASTGLERROR
'' lydia fin --------------------------------------------
TBGL_ClearFrame
TBGL_SceneRender(%sScene)
TBGL_DrawFrame
''pause = 1/FrameRate
' -- ESCAPE key to exit application
if TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While
if tbgl_GetWindowKeyOnce(hWnd, %VK_SPACE) then
sleep 500
Pause = iif(Pause = %TRUE, %FALSE, %TRUE)
end if
if Pause = %true then
doevents
iterate while
end if
Wend
TBGL_DestroyWindow
END FUNCTION
Function LydPCode() as long
TBGL_BeginPoly %GL_POINTS
TBGL_TexCoord2D 0,1
TBGL_Vertex -1,1,0
TBGL_TexCoord2D 1,1
TBGL_Vertex 1,1,0
'TBGL_TexCoord2D 1,0
'TBGL_Vertex 1,-1,0
'TBGL_TexCoord2D 0,0
'TBGL_Vertex -1,-1,0
TBGL_EndPoly
End Function
info: improved script at saturday afternoon.
lydia.
lydia_sp
22-08-2009, 16:47
improved my starlight script :) see last post. time after time this makes more and more fun. tbgl and ui become my loved pets!
improved script:
'
' The starfield
' Petr Schreiber, started on 08-07-2009
' lydia_sp partido
Uses "TBGL", "console", "UI"
randomize timer
BEGIN CONST
' -- Setup
%numStars = 2000
%numSphere = 200
' -- Display lists
%lStar = 1
%lSphere = 1
%lSphere1 = 1
%lLight = 1
%lPCODE = 1
' -- Textures
%tStar = 1
' -- Scene IDs
%sScene = 1
' -- Entity IDs
%eCamera = 1
%eFirstStar
%eLastStar = %eFirstStar + %numStars - 1
%eFirstSphere
%eLastSphere = %eFirstSphere + %numSphere - 1
%eLight
%eSphere1
%EFFECT_QUALITY = 12
END CONST
dim p_StarPulse, pause as single
dim i, j as long
dim xMaxi, yMaxi as long
GLOBAL D() AS LONG
FUNCTION TBMAIN()
LOCAL hWnd As DWORD
LOCAL FrameRate AS DOUBLE
' -- Create and show window
local dx, dy, db as long
tbgl_GetDesktopInfo dx, dy, db
hWnd = TBGL_CreateWindowEx("TBGL Lydias StarLight_Script - press ESC to quit, Spacebar to pause", dx, dy, db, %TBGL_WS_WINDOWED or %TBGL_WS_CLOSEBOX)
TBGL_ShowWindow
' -- Prepare resources
tbgl_LoadTexture "Textures\Star.bmp", %tStar, %TBGL_TEX_ANISO, 16
tbgl_NewList %lStar
tbgl_UseTexturing %TRUE
tbgl_BindTexture %tStar
tbgl_BeginPoly %GL_QUADS
tbgl_TexCoord2D 0, 0
tbgl_Vertex -1, -1
tbgl_TexCoord2D 1, 0
tbgl_Vertex 1, -1
tbgl_TexCoord2D 1, 1
tbgl_Vertex 1, 1
tbgl_TexCoord2D 0, 1
tbgl_Vertex -1, 1
tbgl_EndPoly
tbgl_EndList
tbgl_NewList %lSphere
tbgl_sphere 0.25
tbgl_EndList
tbgl_NewList %lLight
tbgl_sphere 0.125
tbgl_EndList
tbgl_NewList %lPCODE
tbgl_sphere 0.125
LydPCode()
LydCalc()
tbgl_EndList
' -- Create scene
TBGL_SceneCreate(%sScene)
' -- Create basic entities
TBGL_EntityCreateCamera(%sScene, %eCamera)
TBGL_EntitySetPos(%sScene, %eCamera, 0, 0, 0)
TBGL_EntitySetTargetPos(%sScene, %eCamera, 0, 0, -2)
''-- LIGHT
TBGL_EntityCreateLight(%sScene, %eLight, %TBGL_Lighttype_Directional)
TBGL_EntitySetAmbient( %sScene, %eLight, 20, 45, 40 ) '' dark light
TBGL_EntitySetPos(%sScene, %eLight, 0, 0, 0)
TBGL_EntitySetColor(%sScene, %eLight, 140, 225, 240)
TBGL_EntitySetTargetPos(%sScene, %eLight, 0, 0, -2)
TBGL_EntityCreateSphere(%sScene, %eSphere1, 0, 4.5) '' planet
TBGL_EntitySetColor(%sScene, %eSphere1, 40+sin(gettickcount/500)*128, 25, 240+sin(gettickcount/500)*128)
TBGL_EntitySetPos(%sScene, %eSphere1, -8, 1, -85)
TBGL_EntitySetTargetPos(%sScene, %eSphere1, 0, 0, -2)
' -- Create something to look at - star billboards
dim e,f as long
dim s,k as double
for e = %eFirstStar to %eLastStar
TBGL_EntityCreateDLSlot(%sScene, e, 0, %lStar)
TBGL_EntitySetPos(%sScene, e, rndf(-50,50), rndf(-50,50), rndf(-150, 0))
s = rndf(0.1, 0.5)
TBGL_EntitySetScale(%sScene, e, s,s,s)
next
TBGL_UseBlend %TRUE
TBGL_UseDepthMask %FALSE
dim x,y,z,c,p as double
dim fr,fg,fb,msk as long
msk=127
' -- Resets status of all keys
TBGL_ResetKeyState()
' -- Main loop
While TBGL_IsWindow(hWnd)
FrameRate = TBGL_GetFrameRate
''--- one
for e = %eFirstStar to %eLastStar
TBGL_EntityTurn(%sScene, e, 0, 0, 45/FrameRate)
TBGL_EntityPush(%sScene, e, 0, 0, 5/FrameRate)
TBGL_EntityGetPos(%sScene, e, x, y, z)
' -- Color change to simulate twinkle
c = sin(gettickcount*0.01+e)*.25+1.75
'
'pseudorandom tints
fr=(e*123) and msk
fg=(e*571) and msk
fb=(e*579) and msk
'
TBGL_EntitySetColor(%sScene, e, fr*c, fg*c, fb*c)
' -- If particle is behind camera, it is time to recycle it in depth
if z > 1 then
TBGL_EntitySetPos(%sScene, e, rndf(-50,50), rndf(-50,50), -150)
s = rndf(0.1, 1.25)
TBGL_EntitySetScale(%sScene, e, s,s,s)
end if
next
TBGL_UseBlend %TRUE
TBGL_UseDepthMask %TRUE
''-- lydia input ---------------------------------
for f = %eFirstSphere to %eLastSphere
TBGL_EntityCreateDLSlot(%sScene, f, 0, %lSphere)
TBGL_EntitySetPos(%sScene, f, rndf(-40,40), rndf(-40,40), rndf(-80, 0))
k = rndf(0.1, 0.4)
TBGL_EntitySetScale(%sScene, f, k,k,k)
next
p_StarPulse = 1.25+cos(GetTickCount/500)*128
for f = %eFirstSphere to %eLastSphere
TBGL_EntityTurn(%sScene, f, 0, 0, 75/FrameRate)
TBGL_EntityPush(%sScene, f, p_StarPulse, 25/FrameRate, p_StarPulse)
'TBGL_EntityPush(%sScene, f, 0, 0, 12/FrameRate)
TBGL_EntityGetPos(%sScene, f, x, y, z)
' -- Color change to simulate twinkle
p = sin(gettickcount*0.02+f)*.45+1.55
'
'pseudorandom tints
fr=(f*123) and msk
fg=(f*571) and msk
fb=(f*579) and msk
'
TBGL_EntitySetColor(%sScene, f, fr*c, fg*c, fb*c)
' -- If particle is behind camera, it is time to recycle it in depth
if y > 10 then
TBGL_EntitySetPos(%sScene, f, rndf(-40,40), rndf(-40,40), -120)
k = rndf(0.2, 1.25)
TBGL_EntitySetScale(%sScene, f, k,k,k)
end if
next
tbgl_calllist %lSphere
tbgl_calllist %lLight
tbgl_calllist %lPCODE
TBGL_UseBlend %TRUE
TBGL_UseDepthMask %TRUE
''- light
dim r as integer
TBGL_EntityTurn(%sScene, %eLight, 0, p_StarPulse, -25/FrameRate)
TBGL_EntityPush(%sScene, %eLight, 0, 75/FrameRate, p_StarPulse)
TBGL_EntityPush(%sScene, %eCamera, 0, 0.75/FrameRate, 0.2/FrameRate)
TBGL_EntityPush(%sScene, %eSphere1, 0, 0.25+sin(timer)-0.5/FrameRate, -2.5/FrameRate+sin(timer))
TBGL_EntityGetPos(%sScene, %eLight, x, y, z)
printl
printl "light pos: " + x + " ," + y + " ," + z + " ,"
TBGL_GETLASTGLERROR
'' lydia fin --------------------------------------------
TBGL_ClearFrame
TBGL_SceneRender(%sScene)
TBGL_DrawFrame
''pause = 1/FrameRate
' -- ESCAPE key to exit application
if TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While
if tbgl_GetWindowKeyOnce(hWnd, %VK_SPACE) then
sleep 500
Pause = iif(Pause = %TRUE, %FALSE, %TRUE)
end if
if Pause = %true then
doevents
iterate while
end if
Wend
TBGL_DestroyWindow
END FUNCTION
Function LydPCode() as long
TBGL_BeginPoly %GL_POINTS
TBGL_TexCoord2D 0,1
TBGL_Vertex -1,1,0
TBGL_TexCoord2D 1,1
TBGL_Vertex 1,1,0
'TBGL_TexCoord2D 1,0
'TBGL_Vertex 1,-1,0
'TBGL_TexCoord2D 0,0
'TBGL_Vertex -1,-1,0
TBGL_EndPoly
End Function
''-------------------------------------------------------------------------
function LydCalc() as long '' make still no sense ;) dummy block
dim x,y,z as integer
xMaxi = 400 : yMaxi = 400
DIM D(xMaxi,yMaxi) as long
x=150 : z = 250
FOR x = .3*xMaxi TO .33*xMaxi : D(x,2) = RND(0,1)*%RED : NEXT i
FOR x = .6*xMaxi TO .63*xMaxi : D(x,4) = RND(0,1)*%GREEN : NEXT i
FOR x = .3*xMaxi TO .33*xMaxi : D(x,2) = RND(0,1)*D(x,2) : NEXT i
FOR x = .6*xMaxi TO .63*xMaxi : D(x,4) = RND(0,1)*D(x,4) : NEXT i
tbgl_point x,D(x,4),z
end function
next: create bitmap for my big sphere (like a planet). will try to fetch this knowledge.
for you profis and cowboys it`s simple. create new worlds with tbgl or ui. not for a java programming girl. but I am learning a lot with example by example. that`s satisfy myself. rome wasnt built at one day ;)
bye, lydia
Lionheart008
22-08-2009, 21:33
hi lydia :)
a shorty... your first steps remember to myself. good luck! thanks for your nice words. petr too. I hope you will find your way and special favourite module here. there are a lot of good guys here, you will see, they can help. from my side, best wishes. I am completely out. that`s good, there is another great wide open world beside thinbasic. but this forum is still alive. other forums are quite dead. I wish thinbasic the best way to get the gold cup. they are here on a very good way, I see and I feel myself amoung good people. it`s important to feel good to work with an engaged forum and nice people. all you will get it here. :D
nice evening, ciao, lionheart
Petr Schreiber
22-08-2009, 23:12
Hi Lydia,
new version looks interesting! Little bit like Xmas tree lights effect.
There are just two problems:
#1 Display list override
You define all display lists in code as "1", it is better to define them with different number, else you will get only one geometric object in the end.
TBGL_GetLastGLError
I am very happy you learned to use this command, but I recommend to use it only during testing, not in final code (it can hurt speed of drawing).
The visual effect is very nice, but it runs slow on my PC ( 1 200 000 triangles in tiny batches ), you can consider setting lower detail to spheres using TBGL_SetPrimitiveQuality.
Thanks,
Petr