Intio
08-12-2008, 22:04
Here is a listing of the "tilesforplatformer.tbasic" file from the 1.6 bonus pack:
'
' Simple grid rotation, v2
'
Uses "TBGL"
' -- Create and show window
Dim hWnd As Dword = TBGL_CreateWindowEx("2D tiles, randomly enabling and disabling - press ESC to quit", 640, 480, 32, %TBGL_WS_WINDOWED or %TBGL_WS_MAXIMIZEBOX or %TBGL_WS_CLOSEBOX)
TBGL_ShowWindow
' -- First we need to load textures
%texOne = 1
%texTwo = 2
tbgl_LoadTexture APP_SourcePath+"Textures\Praha_Kameni1.bmp", %texOne, %TBGL_TEX_MIPMAP
tbgl_LoadTexture APP_SourcePath+"Textures\Praha_Kameni2.bmp", %texTwo, %TBGL_TEX_MIPMAP
%lTile = 1
CreateTileList(%lTile)
' -- Create scene
%SCENE1 = 1
TBGL_SceneCreate(%SCENE1)
' -- Create basic entities
%eCamera = 1
%eGridStart = 40
' -- Create camera to look from 15, 15, 15 to 0, 0, 0
TBGL_EntityCreateCamera(%SCENE1, %eCamera)
TBGL_EntitySetPos(%SCENE1, %eCamera, 6, 6, 15)
TBGL_EntitySetTargetPos(%SCENE1, %eCamera, 6, 6, 0)
' -- Here we create grid
dim x, y as long
dim Tile as long = %eGridStart
for x = 1 to 10
for y = 1 to 10
TBGL_EntityCreatedlslot(%SCENE1, Tile, 0, %lTile) ' -- Tile is child of %eGridPivot, and rendered as defined in the display list
tbgl_EntitySetTexture(%SCENE1, Tile, rnd(%texOne, %texTwo)) ' -- Random texture
tbgl_EntitySetPos(%SCENE1, Tile, x, y, 0) ' -- Set position
Tile += 1 ' -- Increment tile ID
next
next
%eGridEnd = Tile - 1
dim FrameRate as double
' -- Maxx FPS possible
tbgl_UseVSync %TRUE
' -- Resets status of all keys
TBGL_GetAsyncKeyState(-1)
' -- Main loop
While TBGL_IsWindow(hWnd)
FrameRate = TBGL_GetFrameRate
TBGL_ClearFrame
' -- Random enabling, disabling tiles
if rnd > 0.5 then tbgl_EntitySetuse(%SCENE1, rnd(%eGridStart, %eGridEnd), rnd(%FALSE, %TRUE))
' -- Render scene
TBGL_SceneRender(%SCENE1)
TBGL_DrawFrame
' -- ESCAPE key to exit application
If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While
Wend
TBGL_DestroyWindow
sub CreateTileList( listSlot as long )
tbgl_NewList listSlot
TBGL_BeginPoly %GL_QUADS ' Start polygon Building my quad based on 4 vertexes
TBGL_TexCoord2d 0,0 ' Set texture coordinate
TBGL_Vertex 0,0,0 ' Add Vertex
TBGL_TexCoord2d 1,0 ' Set texture coordinate
TBGL_Vertex 1,0,0 ' Add Vertex
TBGL_TexCoord2d 1,1 ' Set texture coordinate
TBGL_Vertex 1, 1,0 ' Add Vertex
TBGL_TexCoord2d 0,1 ' Set texture coordinate
TBGL_Vertex 0, 1,0 ' Add Vertex
TBGL_EndPoly ' Ends polygon definition tbgl_EndList
tbgl_EndList
end sub
Can someone tell me what the advantages of using the TBGL_SceneCreate command, and the various 'Entity' commands at the beginning of the program, are?
I know that there are various Entity examples within the SampleScripts folder (which I will look at if it turns out that they are efficient for what I might do), but I was wondering if they are there simply for ease of use - or do they give a genuine performance increase over what could be programmed manually? How significant is the advantage of using them compared to any potential overhead for calling them?
Also... eGridPivot?
Thanks for any enlightenment.
'
' Simple grid rotation, v2
'
Uses "TBGL"
' -- Create and show window
Dim hWnd As Dword = TBGL_CreateWindowEx("2D tiles, randomly enabling and disabling - press ESC to quit", 640, 480, 32, %TBGL_WS_WINDOWED or %TBGL_WS_MAXIMIZEBOX or %TBGL_WS_CLOSEBOX)
TBGL_ShowWindow
' -- First we need to load textures
%texOne = 1
%texTwo = 2
tbgl_LoadTexture APP_SourcePath+"Textures\Praha_Kameni1.bmp", %texOne, %TBGL_TEX_MIPMAP
tbgl_LoadTexture APP_SourcePath+"Textures\Praha_Kameni2.bmp", %texTwo, %TBGL_TEX_MIPMAP
%lTile = 1
CreateTileList(%lTile)
' -- Create scene
%SCENE1 = 1
TBGL_SceneCreate(%SCENE1)
' -- Create basic entities
%eCamera = 1
%eGridStart = 40
' -- Create camera to look from 15, 15, 15 to 0, 0, 0
TBGL_EntityCreateCamera(%SCENE1, %eCamera)
TBGL_EntitySetPos(%SCENE1, %eCamera, 6, 6, 15)
TBGL_EntitySetTargetPos(%SCENE1, %eCamera, 6, 6, 0)
' -- Here we create grid
dim x, y as long
dim Tile as long = %eGridStart
for x = 1 to 10
for y = 1 to 10
TBGL_EntityCreatedlslot(%SCENE1, Tile, 0, %lTile) ' -- Tile is child of %eGridPivot, and rendered as defined in the display list
tbgl_EntitySetTexture(%SCENE1, Tile, rnd(%texOne, %texTwo)) ' -- Random texture
tbgl_EntitySetPos(%SCENE1, Tile, x, y, 0) ' -- Set position
Tile += 1 ' -- Increment tile ID
next
next
%eGridEnd = Tile - 1
dim FrameRate as double
' -- Maxx FPS possible
tbgl_UseVSync %TRUE
' -- Resets status of all keys
TBGL_GetAsyncKeyState(-1)
' -- Main loop
While TBGL_IsWindow(hWnd)
FrameRate = TBGL_GetFrameRate
TBGL_ClearFrame
' -- Random enabling, disabling tiles
if rnd > 0.5 then tbgl_EntitySetuse(%SCENE1, rnd(%eGridStart, %eGridEnd), rnd(%FALSE, %TRUE))
' -- Render scene
TBGL_SceneRender(%SCENE1)
TBGL_DrawFrame
' -- ESCAPE key to exit application
If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While
Wend
TBGL_DestroyWindow
sub CreateTileList( listSlot as long )
tbgl_NewList listSlot
TBGL_BeginPoly %GL_QUADS ' Start polygon Building my quad based on 4 vertexes
TBGL_TexCoord2d 0,0 ' Set texture coordinate
TBGL_Vertex 0,0,0 ' Add Vertex
TBGL_TexCoord2d 1,0 ' Set texture coordinate
TBGL_Vertex 1,0,0 ' Add Vertex
TBGL_TexCoord2d 1,1 ' Set texture coordinate
TBGL_Vertex 1, 1,0 ' Add Vertex
TBGL_TexCoord2d 0,1 ' Set texture coordinate
TBGL_Vertex 0, 1,0 ' Add Vertex
TBGL_EndPoly ' Ends polygon definition tbgl_EndList
tbgl_EndList
end sub
Can someone tell me what the advantages of using the TBGL_SceneCreate command, and the various 'Entity' commands at the beginning of the program, are?
I know that there are various Entity examples within the SampleScripts folder (which I will look at if it turns out that they are efficient for what I might do), but I was wondering if they are there simply for ease of use - or do they give a genuine performance increase over what could be programmed manually? How significant is the advantage of using them compared to any potential overhead for calling them?
Also... eGridPivot?
Thanks for any enlightenment.