View Full Version : Question for Petr (or any one else of course)
About :
8678
Hi all,
Made something that gave me two further questions (TB source attached).
(first : while it is called recursive , the program just uses iterations - in this case very fast and very easy in TB (the nucleus of the program is only 3 lines .. the idea is next : a classic turtle but extended form the xy plane into xz -- the symbols are (in the string : m for moving a unit, a number for turning (in degrees) and z is a switch between the horizontal and vertical plane .. for every iteration the m is replaced by the base formula itself - ). If you try this program and remove the z's you will see 2D.
(it is slow for the moment , but the calculations can be "oxydized" in an easy way. )
questions :
-At a certain moment the TBGL drawings (for some settings) seem to vanish behind a "black curtain" -- how do I change this parameter ?
-The intention is not the restart the program once running while changing the initial string / iteration number -- Am I sure I get a "cold start" when hitting "start" a second an further time and avoided unneeded background activity ??
Best and thanks in advance , Rob
(Pg Up / Dn allow zooming - my algorithm for the camera distance is not correct for the moment)
mike lobanovsky
23-11-2013, 03:11
Hello RobbeK,
Seems like your renders go beyond the visible volume defined by the clip planes. You can adjust those with TBGL_SetupClipPlane() proportionately to you zoom on the z-axis. Please correct me here Petr if I am mistaken.
Also, your code seems to leak memory slowly before pressing the Start button, at least on my PC. The leakage however stops as soon as the button is pressed.
Regards,
Hi Mike,
In the mean time (while browsing through the complete help files), I found TBGL_SetDrawDistance which standard is set to 150 units (metres). It is very possible some drawings go beyond it.
How do you monitor Memory usage ? (the classic Win TaskManager ? or another tool ? )
Thanks for ur help , Rob
Petr Schreiber
23-11-2013, 12:44
Hi Rob,
my apologies for late reply.
Black curtain problem
I can confirm TBGL_SetDrawDistance is the command you need to modify rendering depth.
TBGL_SetupClipPlane could be used for this too (inside region already tuned via TBGL_SetDrawDistance), but it is more suitable for chopping objects.
Second question
My apologies, could you please ask the question slightly differently - I am not sure I understand it now.
Petr
Hi Petr,
(it may be a remnant from LISP programming ;-) - but sometimes we had to force a garbage collection in such cases - free memory, space after a certain task or when a task was activated again. ( this was simply done by a (GC) call ).
Just (as you remarked) when initiating vars, arrays etc they are empty -- I sometimes am still fighting "old demons" (I started programming end 1970s).
So, when hitting "start" a 2nd (and further time) , do I start clean enough / or am I piling up tasks ? -- I checked the memory use (and it remains constant during all actions ).
Once again, I changed (also one of your previous advices ) into .. BeginPoly %GL_LINES and using Verteces -- runs smoother.
Also I'm thinking about moving the calculations from (distance,angle) -> (x,y,z) which is now done by TB (or maybe O2 in the future) completely to OpenGL /TBGL functions -- it has translations and rotations built in .. however my fear is when working with boxes (or so) there may be a serious slow down.
best Rob
mike lobanovsky
23-11-2013, 16:37
@Petr
Thanks for your comment.
@RobbeK
The overall leakage can be easily spotted in an ordinary Task Manager. And when I want to check memory on a per-module basis, I use Sysinternals' Process Explorer (procexp.exe).
My observations reveal a memory leak of approx. 8KB per second for the first script in the thread and approx. 20KB per second, for the last one, in both compiled and uncompiled form on all the platforms and computers I have. As soon as the Start button is clicked, the memory jumps up by another 2MB or so and stays put till the program exits.
[EDIT] Oh, and I forgot to add I'm still using TB v1.9.10 for my tests.
Regards,
Thanks Mike,
Ah, "Dispatcher" ! .. learning some new Russian words too !
Task Manager under Win7 ultimate gives no memory leaks here, TB 1.9.11 -- however, I think to notice a slow-down, but it's probably a hardware question.. To avoid Windows emulation my Intel chip runs on drivers which are an XP hack. (Intel has no update for this old gear on Win7).
(Infact is also runs smooth under Linux Wine - with some slight differences : old style buttons, caption (title) of any window is always centered etc... but under Linux this mainly is a question of loading/set up a skin for all this ).
.. made some slight changes on the program (mainly cosmetically if --> select case ) added a new initial string .. here the sum of angles in both planes is 0 (or k*360) - it gives more interesting "closed" images (imho).
For the moment using 2 planes (under 90°) it only can generate orthogonal composed 3D .. maybe more later, if it is not getting too boring.
best Rob
Petr Schreiber
23-11-2013, 20:31
Hi,
I see some memory movement, but I think it is some kind of driver optimization, it does not go too wild.
I manage to crash the program when clicking Start too many times.
To avoid this and be sure, that you don't stack it up, I would suggest to declare flag.
Addthe following in the beginning of the dlgCallback:
static startReady as long = true
...and in the handling of the button do this:
Case %bstart
If CBCTLMSG = %BN_CLICKED And startReady = TRUE Then
startReady = FALSE
' TBGL_UseVSync(0)
Control Get Text hDlg,%edformul To s
Control Get Text hDlg,%nrofiter To v
iteration=Val(v)
hkx=0 : hkz=0
compute()
startReady = TRUE
'test()
EndIf
This will do kind of lock, avoiding starting before previous start process ended.
As a speed hint - I would recommend to delete old, and create new display list, where you store whole geometry - no need to iterate over and over in RenderMyImage.
So, add this at the end of compute:
TBGL_DeleteList 1
TBGL_NewList 1
TBGL_BeginPoly %GL_LINES
For i = 1 To pos-1
TBGL_Vertex matrix(i).x,matrix(i).y,matrix(i).z
TBGL_Vertex matrix(i+1).x,matrix(i+1).y,matrix(i+1).z
Next
TBGL_EndPoly
TBGL_EndList
And change RenderMyImage to:
Function RenderMyImage( hCtrl As DWord )
Static FrameRate As Double
Local i As Long
If TBGL_CanvasBound(hCtrl) Then
FrameRate = TBGL_GetFrameRate
TBGL_UseVSync(0)
TBGL_ClearFrame
TBGL_Color (0,140,0)
TBGL_RenderMatrix3D
TBGL_Camera(0, 10, 24+trans, 0, 0, 0)
TBGL_Rotate(hk,1,1,0)
TBGL_CallList 1
TBGL_DrawFrame
hk += 1
If TBGL_GetWindowKeyState(hDlg, %VK_UP) Then trans -= 0.3
If TBGL_GetWindowKeyState(hDlg, %VK_DOWN) Then trans += 0.3
End If
End Function
I like this demo very much, please keep updating it :)
Petr
mike lobanovsky
23-11-2013, 21:20
@Rob
What a nice update you have here! Please keep up your work, now it looks much more ordered and spectacular. :)
@Petr
I've been testing some other TBGL samples and I confirm some of them (but not all) show a similar behavior on lauching. As you say, the leak isn't drastic and it stops as the time passes but it can add up to 1MB of extra memory in the meantime.
I'd be glad to torture TBGL some more in, say, FBSL which is thinBasic's closest kin even if it follows different trends, but regretfully I can't do it as TBGL doesn't expose its API's even when un-UPX'ed.
Anyway, I append a little clip that will show you what I'm talking about and what I'm seeing on my PC's.
Regards,
Great Petr !
The List construction / call is a fundamental necessity !
(yep, I think the flag is needed too)
Added the updated source. (one of the angles is slightly less than 90° now - some "objects" will not be closed now).
When I'm sure the code is 100% correct I'll convert the time critical pieces into O2.
For the moment there's a restriction of 120 000 lines to be displayed ; is that a reasonable amount on a modern computer, or could I go higher ? What is your opinion ?
thanks again, Rob
Thanks Mike,
Probably fractal dimensions are a kind of obsession to me ;-)
I also use it in my photography
http://www.ipernity.com/doc/294723/25805927
best, Rob
mike lobanovsky
24-11-2013, 21:45
Hello Rob,
Very impressive! :)
I'm awfully sorry for the offtopic, I'm hoping you'll pardon it, but fractals are also my long-term passion. I particularly admire this package (http://sourceforge.net/projects/boxplorer/) as I do about almost everything else that's been done by Rrrola (http://rrrola.wz.cz/files/puls.zip).
Regards,
Petr Schreiber
25-11-2013, 12:39
Rob,
I like your photos very much! Nice to see someone shooting with Jupiter lens, we have 50mm f2 Jupiter at home too, and plan to mount it to Nikon 1 via reduction.
Mike,
you are not the only one considering use of TBGL from other than thinBasic language. It is something I have on the list of possible new directions of ThinBASIC 2.x development, but what holds me back is the question - will I be able to support the library, when it is open to much wider user audience? Technically, it is not that big issue, but the support question is important to me.
The memory movements you see are something I see here too. When you launch for example SampleScripts/TBGL/Camera_FollowCube1, you can see it eats some memory after start and then it stops. I presume it is some kind of driver optimization on the fly - with TBGL/OpenGL, especially when using immediate mode (BeginPoly/EndPoly), the driver does not know how huge geometry structures will be built during the frame. It seems to me it tries to cache something on the go and once it seems "enough", it stops.
This is something I cannot control, OpenGL is just an graphic API, it does not allow me to dive deeper into drivers internals to see what happens.
Just to make me sure, I will check TBGL code for potential uncontroller allocations, but I don't give it much chance to be the reason behind the behaviour.
Petr
P.S. I like fractals too, I did a tree generator (http://psch.thinbasic.com/articles_tree_generation.html) in the past, based on them.
mike lobanovsky
25-11-2013, 16:14
Petr,
I appreciate your detailed comments on the phenomenon. My intention was just to make sure you're aware of it. I don't consider it dramatic as long as the leak seems to die out on its own as the application runs on.
I'm glad you're taking an active part in the development of the long-awaited thinBasic v2. I'm looking forward to the time when I'm able to grab my copy. :)
Have you considered a slightly different approach to the maintenance issue? If TBGL becomes a standalone module, it may lead its own independent life, whether maintained or not, for the benefit of others who might be interested in using it for whatever purpose they see fit. OTOH having it hardcoded exclusively in the thinBasic bundle may unnecessarily narrow down its applicability to a certain extent.
And oh, thanks for your heads-up on the tree generation techniques! :) To me, trees are a very special issue, and I have also tried my hand at the subject (http://www.fbsl.net/phpbb2/viewtopic.php?p=10084#p10084). The code should look very familiar to a thinBasic user so I don't think we're likely to have any semantic barriers. An executable is also there for your convenience.
Regards,
Thanks Mike, Petr ..
Strong examples you both showed (I think I have to catch up with textures and shading techniques - downloaded boxplorer, it needs GLSL -- again something new for me -- that dinosaur feeling becomes stronger and stronger ;-)
O/T done before I knew anything about TB , attached : the general form of quadratic mappings -- maybe some good ideas inside (for up to date people as you both --) I attached the source , but it is code for the compiler from GFA GmbH.
(this time I injected the XP style - so no *.manifest style anymore ).
Petr, Jupiter -- excellent stuff (but in fact Soviet war loots -- this one from Carl Zeiss , there was a lot of optical/camera industry in Dresden (or what was left after the pandemonium ) Jena and south of these (upto the Northern border of your country). Some production lines were rebuilt (as in Eisfeld) and then shipped to Kiev and Krasnagorsk (North of Moskwa). When I played competition chess I also bought "East - Czech, DDR, Russian" books ... much cheaper (and much better) -- somewhat similar as with optics ;-) oops O/T -- next will be about TB ...
best to you, Rob
Petr Schreiber
26-11-2013, 10:22
[Photo posts moved]
Hehe,
no ban from my side, especially with this kind of off topic :D The M39 reduction arrived yesterday, so...
But to keep it clean a bit, I opened a new thread for phototalk (http://www.thinbasic.com/community/showthread.php?t=12293&p=90325#post90325).
Petr