the Entity from Gbuffers deserve to be added to the official thinbasic distribution Like Entity from display List or from a Function
it is much speedier than display list for some tasks
here is a proof using the Petr example above
galaxy shape from display list: 600000 points : FPS= 20
galaxy shape from Gbuffer: 600000 points : FPS= 60
from display list:
'adapted from:
' The entity skeleton for TBGL
' Petr Schreiber, started on 10-25-2014
'
#Include Once "%APP_INCLUDEPATH%\thinbasic_gl.inc"
#Include Once "%APP_INCLUDEPATH%\thinbasic_glu.inc"
Uses "TBGL"
Begin Const
' -- Scene IDs
%sScene = 1
' -- Entity IDs
%eCamera = 1
%lMyPoints 'display List number
%ePoints 'the number to represent the Entity made from the Display List
End Const
Function TBMain()
Local hWnd As DWord
Local FrameRate As Long 'Double
Global tot As Long
' -- Create and show window
hWnd = TBGL_CreateWindowEx("TBGL script - press ESC to quit", 640, 480, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX)
TBGL_ShowWindow
' -- Create scene
TBGL_SceneCreate(%sScene)
' -- Create basic entities
' -- Create camera to look from 15, 15, 15 to 0, 0, 0
TBGL_EntityCreateCamera(%sScene, %eCamera)
TBGL_EntitySetPos(%sScene, %eCamera, 0, 3, 8)
TBGL_EntitySetTargetPos(%sScene, %eCamera, 0, 0, 0)
TBGL_EntityCreateDLSlot(%sScene, %ePoints, 0, %lMyPoints)
TBGL_EntityCreateDLSlot(%sScene, %ePoints, 0, %lMyPoints)
TBGL_EntitySetColor(%sScene, %ePoints, 255, 255, 255)
TBGL_EntitySetPos(%sScene, %ePoints, 0, 0, 0)
' -- Define data for it
DrawPoints()
' -- Resets status of all keys
TBGL_ResetKeyState()
'TBGL_PointSize 2
'glEnable(%GL_POINT_SMOOTH)
TBGL_UseLighting %FALSE
' -- Main loop
While TBGL_IsWindow(hWnd)
FrameRate = TBGL_GetFrameRate
TBGL_SetWindowTitle( hWnd, "FPS = "+Str$(FrameRate)+" points = "+Str$(tot))
TBGL_EntityTurn(%sScene, %ePoints, 0,30/FrameRate, 0)
TBGL_ClearFrame
TBGL_SceneRender(%sScene)
TBGL_DrawFrame
' -- ESCAPE key to exit application
If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While
If TBGL_GetWindowKeyState(hWnd, %VK_LEFT) Then
TBGL_EntityTurn(%sScene, %ePoints, 0,-90/FrameRate, 0)
ElseIf TBGL_GetWindowKeyState(hWnd, %VK_RIGHT) Then
TBGL_EntityTurn(%sScene, %ePoints, 0, 90/FrameRate, 0)
End If
Wend
TBGL_DestroyWindow
End Function
Sub DrawPoints()
Dim e As Single
Dim x, y, z, y1 As Single
Dim rand, indx As Long
e = 2.718281828459
x=-4: z=-4
TBGL_NewList %lMyPoints
TBGL_BeginPoly %GL_POINTS
While z<= 4
'Randomize
While x<=4
'Randomize
tot = tot + 1
If x*x+z*z<=13 Then
y = Pow(e,(0.1-x*x-z*z)) ' the formula
'Repeat
rand = Rnd(-1,1)'Rnd(-2,2)
'Until rand <> 0 ' To Get rid of Value zero
y1 = y * rand + Rndf(0.1, 0.4)' y * rand: let the point go up And down the galaxy disk, Rndf(0.1, 0.4): And let the disk have Some thickness like a sponge
Select Case y
Case <=0.00005
TBGL_Point(x,y1, z)
TBGL_Color(50,255,0)
Case <=0.001
TBGL_Point(x,y1, z)
TBGL_Color(255,200,0) 'orange
Case <=0.01
TBGL_Point(x,y1, z)
TBGL_Color(255,20,0) 'red
Case <=0.8
TBGL_Point(x,y1, z)
TBGL_Color(0,160,255) 'bluesh
Case >0.8
TBGL_Point(x,y1, z)
TBGL_Color(255,255,255) 'white
End Select
End If
x+0.01
Wend
x = -4
z+0.01
Wend
'================================================
TBGL_EndPoly
TBGL_EndList
End Sub
from Gbuffer: needs the file "GBufferEntity.tBasicU" inside GBufferAsEntity.zip by Petr posted above
'adapted from:
' The entity skeleton for TBGL
' Petr Schreiber, started on 10-25-2014
'
#Include Once "%APP_INCLUDEPATH%\thinbasic_gl.inc"
#Include Once "%APP_INCLUDEPATH%\thinbasic_glu.inc"
Uses "TBGL" , "Console"
#Include "GBufferEntity.tBasicU"
Begin Const
' -- Scene IDs
%sScene = 1
' -- Entity IDs
%eCamera = 1
'%eLight
%eGBuffer
End Const
Function TBMain()
Local hWnd As DWord
Local FrameRate As Long 'Double
Global i As Long ' number of points
' -- Create and show window
hWnd = TBGL_CreateWindowEx("TBGL script - press ESC to quit", 640, 480, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX)
TBGL_ShowWindow
' -- Create scene
TBGL_SceneCreate(%sScene)
' -- Create basic entities
' -- Create camera to look from 15, 15, 15 to 0, 0, 0
TBGL_EntityCreateCamera(%sScene, %eCamera)
TBGL_EntitySetPos(%sScene, %eCamera, 0, 3, 8)
TBGL_EntitySetTargetPos(%sScene, %eCamera, 0, 0, 0)
TBGL_EntitySetPos(%sScene, %eGbuffer, 0, 0, 0)
%eGbuffer = GbufferEntity_Create(%sScene, %TBGL_POINTS, %TBGL_3D)
Global NumOfPoints = 641601
' -- Define data for it
Global VertexA(NumOfPoints) As TBGL_TVECTOR3F
Global ColorA(NumOfPoints) As TBGL_TRGB
GBufferEntity_DefineFromArray(%sScene, %eGbuffer, %TBGL_DYNAMIC, NumOfPoints, VertexA(1), ColorA(1))
' -- Define data for it
DrawPoints()
' -- Resets status of all keys
TBGL_ResetKeyState()
'TBGL_PointSize 2
'glEnable(%GL_POINT_SMOOTH)
TBGL_UseLighting %FALSE
' -- Main loop
While TBGL_IsWindow(hWnd)
FrameRate = TBGL_GetFrameRate
TBGL_SetWindowTitle( hWnd, "FPS = "+Str$(FrameRate)+" points = "+Str$(i))
TBGL_EntityTurn(%sScene, %eGbuffer, 0,30/FrameRate, 0)
TBGL_ClearFrame
TBGL_SceneRender(%sScene)
TBGL_DrawFrame
' -- ESCAPE key to exit application
If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While
If TBGL_GetWindowKeyState(hWnd, %VK_LEFT) Then
TBGL_EntityTurn(%sScene, %eGbuffer, 0,-90/FrameRate, 0)
ElseIf TBGL_GetWindowKeyState(hWnd, %VK_RIGHT) Then
TBGL_EntityTurn(%sScene, %eGbuffer, 0, 90/FrameRate, 0)
End If
Wend
TBGL_DestroyWindow
End Function
Sub DrawPoints()
Dim e As Single
Dim x, y, z, y1 As Single
Dim rand, indx As Long
e = 2.718281828459
x=-4: z=-4
While z<= 4
'Randomize
While x<=4
'Randomize
i = i + 1
If x*x+z*z<=13 Then
y = Pow(e,(0.1-x*x-z*z)) ' the formula
'Repeat
rand = Rnd(-1,1)'Rnd(-2,2)
'Until rand <> 0 ' To Get rid of Value zero
y1 = y * rand + Rndf(0.1, 0.4)' y * rand: let the point go up And down the galaxy disk, Rndf(0.1, 0.4): And let the disk have Some thickness like a sponge
Select Case y
Case <=0.00005
VertexA(i).x = x: VertexA(i).y = y1: VertexA(i).z = z
ColorA(i).r=50: ColorA(i).g=255: ColorA(i).b=0
Case <=0.001
VertexA(i).x = x: VertexA(i).y = y1: VertexA(i).z = z
ColorA(i).r=255: ColorA(i).g=200: ColorA(i).b=0 'orange
Case <=0.01
VertexA(i).x = x: VertexA(i).y = y1: VertexA(i).z = z
ColorA(i).r=255: ColorA(i).g=20: ColorA(i).b=0 'red
Case <=0.8
VertexA(i).x = x: VertexA(i).y = y1: VertexA(i).z = z
ColorA(i).r=0: ColorA(i).g=160: ColorA(i).b=255 'bluesh
Case >0.8
VertexA(i).x = x: VertexA(i).y = y1: VertexA(i).z = z
ColorA(i).r=255: ColorA(i).g=255: ColorA(i).b=255 'white
End Select
End If
x+0.01
Wend
x = -4
z+0.01
Wend
'================================================
End Sub
suggestion 2: powerBasic lacks a good 3D graphics engine, we can't consider OpenGL an engine for the home users. also the available xors3d and N3xtD depends on DirectX9, the xors3d is abandoned and the N3xtD depends on the DX9. most users of windows 10 usualy don't like to install DX9 on their machines even for psychological reasons only. while Opengl is backward compatible . so the door is open to provide especialy the Petr entity system friendly and easy to use to the powerbasic users. you can sell the engine in windows store for 29$.
https://www.microsoft.com/store/apps
when you do this i will buy powerbasic v10 immediately.
Bookmarks