Hi Petr, DirectuX
i remember Petr said that GBuffer is created using glDrawArrays, but it is not known that its coupled with glVertexPointer/glColorPointer/... without VBO context, or created with VBO Context and buffered to GPU with glBufferData, something like that. it is said glInterleavedArrays can speed the execution.
but there is a problem :
the arrays presented to Gbuffer is either VertexArray() [, ColorArray(), NormalArray(), TexCoordArray() ])
but i can't use the data type like this
Type Point3D
x As Single
y As Single
z As Single
r As Byte
g As Byte
b As Byte
End Type
i am restricted to something like :
Type PointPosition
x As Single
y As Single
z As Single
End Type
Type PointColor
r As Byte
g As Byte
b As Byte
End Type
this works while the later does not work
Uses "TBGL"
Uses "math"
Type PointPosition
x As Single
y As Single
z As Single
End Type
Type PointColor
r As Byte
g As Byte
b As Byte
End Type
Function TBMain()
Local hWnd As DWord
Local FrameRate As Double
' -- Create and show window
hWnd = TBGL_CreateWindowEx("Plotting 3D Data in an array using GBuffers - press ESC to quit", 600, 600, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX)
TBGL_ShowWindow
TBGL_BackColor 255,255,255
TBGL_SetDrawDistance 250
' -- Create 3D points buffer
'Dim gbPoints As DWord = TBGL_GBufferCreate(%TBGL_POINTS, %TBGL_3D)
Dim gbPoints As DWord = TBGL_GBufferCreate(%TBGL_TRIANGLES, %TBGL_3D)
Global Nb As DWord = 3
' -- Define data for it
Global VertexA(Nb) As PointPosition 'TBGL_TVECTOR3F
Global ColorA(Nb) As PointColor 'TBGL_TRGB
VertexA(1).x = 0: VertexA(1).y = 1: VertexA(1).z = 0
VertexA(2).x = -1: VertexA(2).y = -1: VertexA(2).z = 0
VertexA(3).x = 1: VertexA(3).y = -1: VertexA(3).z = 0
ColorA(1).r = 255: ColorA(1).g = 0: ColorA(1).b=0
ColorA(2).r = 0: ColorA(2).g = 255: ColorA(2).b=0
ColorA(3).r = 0: ColorA(3).g = 0: ColorA(3).b=255
' -- Create buffer dynamically linked to the arrays above
TBGL_GBufferDefineFromArray(gbPoints, %TBGL_DYNAMIC, CountOf(VertexA), VertexA(1), ColorA(1))
' -- Resets status of all keys
TBGL_ResetKeyState()
'TBGL_PointSize 2
' -- Main loop
While TBGL_IsWindow(hWnd)
'init
FrameRate = TBGL_GetFrameRate
TBGL_ClearFrame
TBGL_Camera(0, 0, 5, 0, 0, 0)
' -- Turn triangle
TBGL_Rotate GetTickCount/50, 0, 1, 0
'TBGL_Scale 0.6, 0.6, 0.6
' -- Render it
TBGL_GBufferRender(gbPoints)
TBGL_DrawFrame
' -- ESCAPE key to exit application
If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While
Wend
' -- Destroying the buffer is not necessary,
' -- the garbage collector will take care of it
' -- Destroy window
TBGL_DestroyWindow
End Function
this does not work:
Uses "TBGL"
Uses "math"
Type Point3D
x As Single
y As Single
z As Single
r As Byte
g As Byte
b As Byte
End Type
Function TBMain()
Local hWnd As DWord
Local FrameRate As Double
' -- Create and show window
hWnd = TBGL_CreateWindowEx("Plotting 3D Data in an array using GBuffers - press ESC to quit", 600, 600, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX)
TBGL_ShowWindow
TBGL_BackColor 255,255,255
TBGL_SetDrawDistance 250
' -- Create 3D points buffer
'Dim gbPoints As DWord = TBGL_GBufferCreate(%TBGL_POINTS, %TBGL_3D)
Dim gbPoints As DWord = TBGL_GBufferCreate(%TBGL_TRIANGLES, %TBGL_3D)
Global Nb As DWord = 3
' -- Define data for it
Global data(Nb) As Point3D 'TBGL_TVECTOR3F
'Global ColorA(Nb) As PointColor 'TBGL_TRGB
data(1).x = 0: data(1).y = 1: data(1).z = 0
data(2).x = -1: data(2).y = -1: data(2).z = 0
data(3).x = 1: data(3).y = -1: data(3).z = 0
data(1).r = 255: data(1).g = 0: data(1).b=0
data(2).r = 0: data(2).g = 255: data(2).b=0
data(3).r = 0: data(3).g = 0: data(3).b=255
'MsgBox(0, Str$(CountOf(data)))
' -- Create buffer dynamically linked to the arrays above
TBGL_GBufferDefineFromArray(gbPoints, %TBGL_DYNAMIC, CountOf(data), data(1).x, data(1).r)
' -- Resets status of all keys
TBGL_ResetKeyState()
'TBGL_PointSize 2
' -- Main loop
While TBGL_IsWindow(hWnd)
'init
FrameRate = TBGL_GetFrameRate
TBGL_ClearFrame
TBGL_Camera(0, 0, 5, 0, 0, 0)
' -- Turn triangle
TBGL_Rotate GetTickCount/50, 0, 1, 0
'TBGL_Scale 0.6, 0.6, 0.6
' -- Render it
TBGL_GBufferRender(gbPoints)
TBGL_DrawFrame
' -- ESCAPE key to exit application
If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While
Wend
' -- Destroying the buffer is not necessary,
' -- the garbage collector will take care of it
' -- Destroy window
TBGL_DestroyWindow
End Function
also i suggest to let the color type Single , since it is hard coded as byte.
Bookmarks