PDA

View Full Version : Preview: GBuffers for TBGL



Petr Schreiber
03-03-2010, 12:29
Hi guys,

I talked here about new way of defining geometry in TBGL, so here is the preview version for you to comment and test. If no problems observed, it will be included in next thinBASIC.

GBuffers are simple, internally based on Vertex Arrays(dynamic ones) and Vertex Buffer Objects (static ones).

Here is the new DLL(please copy to thinBasic/Lib) and examples, which should give you idea "how it works".
Full documentation will come in next TB release.

I think this new approach could be of interest for example to Stan, as it allows rendering big numbers of points (but not only) in fast way, with predictable memory consumption.


Petr

Attachement removed, feature present in latest thinBASIC

Charles Pegge
03-03-2010, 13:42
Thanks Petr!

With the new TBGL module, you will be able to run this script with one of Stan Blank's algorithmic patterns.

I could not resist it, but please do not gaze upon the gyrating image for too long :diablo:

Charles

zak
03-03-2010, 14:45
thanks Petr and Charles
Petr is this version of TBGL which you have refered to here http://community.thinbasic.com/index.php?topic=3265.msg24461#msg24461
ie: rendering in way the lines would be visible during computation.
and how to achieve this feat !.
regards

Petr Schreiber
03-03-2010, 17:12
Hi Zak,

yes, it is!

I will hold back regarding examples using GBuffers till the ThinBASIC with them is out, to avoid confusion, but here is the version of the Stans example, at full detail:


' Example: Section 7.7 (page 222-224), Explorations with the Mandlebrot Set

' From Stan Blank's Book:
' "Python Programming in OpenGL
' "A Graphical Approach to Programming

' Converted by Stan Blank, this version is slightly downgraded in detail by Petr Schreiber
' Using the Predator-Prey framework by Michael Clease
' Last modified: February 28, 2010

' thinBasic does not use GLUT, we use instead tbgl
Uses "TBGL"

' insert Eros Olmi's new iComplex module
Uses "iComplex"


Function TBMain()

' Handle for our window
Local hWnd As DWord
Local Width As Long
Local Height As Long
Local n As Long
Local x,y, zz As Double

' Declare iComplex variables
Local z, c As tComplex

'# Initial values of width And height
width = 400
height = 400
'
' Create and show window
hWnd = TBGL_CreateWindowEx("Mandelbrot Set", Width, Height, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX Or %TBGL_WS_DONTSIZE)
TBGL_ShowWindow

' -- Set background from default black to white
TBGL_BackColor(0,0,0)

' -- Init OpenGl, like gluOrtho2D in example code
TBGL_RenderMatrix2D( -2, -1.5, 1, 1.5 )

TBGL_PointSize 1

' Resets status of all keys
TBGL_ResetKeyState()

Local percent As Double

' -- Create new GBuffer
Local gbMandelbrot As DWord = TBGL_GBufferCreate(%TBGL_POINTS, %TBGL_2D)
Local MandelbrotIndex As Long
Local MandelbrotVertex(160000) As tbgl_tVector2f ' -- TYPE from TBGL
Local MandelbrotColor (160000) As tbgl_tRGB ' -- TYPE from TBGL

' -- Fill it with data
For x = -2 To 1 Step 0.0075

For y = -1.5 To 1.5 Step 0.0075
Incr MandelbrotIndex

' Set complex points
c = iComplex_Set(x,y)
z = iComplex_Set(x,y)
n = 0

For n = 1 To 50
' Equation is z = z*z + c
z = iComplex_Mul(z,z)
z = iComplex_Add(z,c)

' Distance from origin to complex point
zz = iComplex_Abs(z)

' if distance is > 2.0, then point is NOT in the M-Set
' so plot it... the M-Set will be black
If zz > 2.0 Then
MandelbrotColor (MandelbrotIndex).R = 255
MandelbrotVertex(MandelbrotIndex).x = x
MandelbrotVertex(MandelbrotIndex).y = y
End If
Next
Next

' -- Write status
percent = (x-(-2))/3*100
TBGL_SetWindowTitle(hWnd, Format$(percent, "#.00")+"%, rendering full detail")
DoEvents

' -- Dynamically say to TBGL where the data are, this is just pointer gymnastics, no copy
TBGL_GBufferDefineFromArray(gbMandelbrot, %TBGL_DYNAMIC, MandelbrotIndex, MandelbrotVertex(1), MandelbrotColor(1))

' -- Redraw
TBGL_ClearFrame
TBGL_GBufferRender(gbMandelbrot)
TBGL_DrawFrame

' -- Escape sooner?
If TBGL_GetWindowKeyOnce(hWnd, %VK_ESCAPE) Then Exit For

Next

TBGL_SetWindowTitle(hWnd, "Behold - the Mandlebrot! :)")

' Main loop
While TBGL_IsWindow(hWnd)

TBGL_ClearFrame

TBGL_GBufferRender(gbMandelbrot)

TBGL_DrawFrame

If TBGL_GetWindowKeyOnce(hWnd, %VK_ESCAPE) Then Exit While

Wend

TBGL_DestroyWindow

End Function


You can see the GBuffer set as "dynamic" only look ups ThinBASIC variables, without making any expensive memory copy.
This way, once the data are linked together and their amount does not change, you can only change values in the arrays, and changes will be immediately visible after new render.


Petr

zak
03-03-2010, 18:30
thanks Petr, i have the following notes:
the process of plotting keeps going on until it finished, after that i can move other windows or the tbgl scene; without deleting the finished scene,
but if during the plotting i put the cursor on the program icon on the taskbar 3 seconds as in the image below the scene will converted to white and the counter stop ,and it will not respond to ESC key, this is may be because it will recalculate again, but any way at the end the scene will rendered correctly. the problem to solve may be to continuasly storing the partialy finished scene so if we move anything the partialy scene will be refreshed again easily.
http://img717.imageshack.us/img717/9617/tbgl.jpg

Petr Schreiber
03-03-2010, 18:42
Thanks for bringing this up Zak,

I did not noticed this during the tests.
Solution?

DoEvents :)

I just updated the example above, let me know if it helped.


Thanks!,
Petr

zak
03-03-2010, 19:08
magnificent, it is perfect, and i was thinking that it is recalculating from start :unguee: i will read the GBuffer docs once the official release. this year 2010 is a big step for thinbasic, TBGL, and Oxygen.
regards

sblank
03-03-2010, 22:57
Oh wow... is this the '60's again? :D

I feel like I'm watching the closing sequence of 2001 when Bowman goes through the stargate...

Words fail me... just a darn good job Petr and Charles! Now when am I going to find time to learn all this new stuff? Every day brings something new and that's exciting.

Great work... and I know what I'm going to be doing this evening...

Cheers,

Stan




Thanks Petr!

With the new TBGL module, you will be able to run this script with one of Stan Blank's algorithmic patterns.

I could not resist it, but please do not gaze upon the gyrating image for too long :diablo:

Charles

kryton9
04-03-2010, 10:01
Thanks Petr and Charles for the examples. I am running and viewing these on my notebook with an ati 9600 mobility radeon video card. I was able to run and see all of Petr's examples. Charles, I just see a black square on a white background. No textures. Does it take a while to render the texture should I let it sit longer than the 30 seconds or so that I wait?

Petr Schreiber
04-03-2010, 10:59
Hi Kent,

mea culpa, it was wrong in original example.
I just tested on Radeon X1650 and same effect.
Just change:


TBGL_BackColor 255,255,255,0


to


TBGL_BackColor 255,255,255,255


It confused blending.


Petr

kryton9
04-03-2010, 11:16
Thanks Petr, I am so glad to finally see the "2001" monolith being hyperspaced to the moon.
Just to make sure I am seeing what I should see. I see fractals background fluxing in and out and the black plane, but it is rotating while going through the wormhole in the foreground.

Why would it work on nvidia cards and not on ati? Don't tell me they reverse 0 or 255 for alpha?

Petr Schreiber
04-03-2010, 11:33
Hi Kent,

no idea, we would need one NVIDIA and one ATi engineer + well equipped torture room :)

I noticed NVIDIA tends to extend behavior beyond the specifications, so for pro development, many people say it is more advantageous to pick ATi card, as they only implement what specification allows, so you get errors more easily.

I need to examine the alpha sample, if there are not some crimes against specs :)


Petr