PDA

View Full Version : tbgl cityfog project, new direction



christianssen
11-03-2010, 13:07
yep! thanks again petr.

A) I am thinking my first part of "CityFog" is ready now. for me one good result for some exercises with tbgl. that's good feeling how I can notice to get scene I have in my mind.

B) I have placed camera some areas below top plane. you can start for walking and looking with left/right arrow and up/down for moving forward/backward keys.

ba) if you like to move up you use PageUp/PageDown.
bb) interesting: if you use up/down arrows and go closer to the wall the images brighten
up, I like that.;)
bc) interesting: the framerate of this example increases if you're going upstairs.

cityfog example part one:

'-denis tbgl learning edition two ;)

'---Load needed modules
Uses "TBGL"

Begin Const
' -- Our world will have two entities
%ENT_CAMERA = 1
%ENT_GRIDLIST
%ENT_CreateCity
%ENT_CreateBlockCity
%ENT_BLOX
%ENT_LIGHT
End Const

' -- Display lists
Begin Const
%LST_GRID = 1
%LST_BOX
%LST_CITY
%LST_BLOCKCITY
%LST_BLOX
End Const

Randomize Timer
Global nFrames As Quad
Global T0 As Double = Timer
Global T1 As Double

Dim FrameRate As Double
Dim ThisTime, LastTime, TimeDelta As DWord
Dim hWnd As Dword
Dim i As Long
Dim slowmotion As Long = 1
Dim FPSCount As Quad = 1
Dim width, height As Long
Dim x, y, z As Double


'---Creates OpenGL window and returns handle
hWnd = TBGL_CreateWindowEx("CityFog: Moving in 3D, CityEntityBoxed 2d - press ESC to quit", 800, 600, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX Or %TBGL_WS_MINIMIZEBOX Or %TBGL_WS_MAXIMIZEBOX)
'---Shows TBGL window
TBGL_ShowWindow

TBGL_GetWindowClient(hWnd, width, height)
Dim aspectRatio As Single = width/height


TBGL_LoadTexture APP_SourcePath+"stevenson2.bmp", 1, %TBGL_TEX_MIPMAP

'-FONT --------------------------BUILD FONT ------------------------
Dim hFont As DWord = TBGL_FontHandle("Courier New", 9)
TBGL_BuildFont( hFont )
'-FONT -------------------------BUILD FONT ------------------------

TBGL_SetupFog 0,0,128,128,5
TBGL_BackColor 0,0,128
TBGL_UseFog %TRUE

' -- First we will create world as place to contain entities
%MY_WORLD = 1
TBGL_SceneCreate(%MY_WORLD)

' .. Camera
tbgl_EntityCreateCamera( %MY_WORLD, %ENT_CAMERA)
TBGL_EntitySetPos ( %MY_WORLD, %ENT_CAMERA, 4.0, 6.0, -30.0 ) '4.0, 22.0, -30.0

TBGL_EntityCreateLight( %MY_WORLD, %ENT_LIGHT,0,%TBGL_LIGHTTYPE_DIRECTIONAL )
TBGL_EntitySetPos ( %MY_WORLD, %ENT_LIGHT, 2.0, 25.0, -1.0 )
TBGL_EntitySetColor( %MY_WORLD, %ENT_LIGHT, 255, 128, 55 )

' .. Grid
tbgl_EntityCreateDLSlot( %MY_WORLD, %ENT_GRIDLIST, 0, CreateGridAsDList() )

CreateBloxAsDList()
'1)------------------------------------------------------------
TBGL_EntityCreateDLSlot( %MY_WORLD, %ENT_BLOX, 0, %LST_BLOX)
TBGL_EntitySetPos ( %MY_WORLD, %ENT_BLOX, 2.0, 0.25, -25.0 )

'---------------------------------------------------------------

Dim Sheeps As Long

'---Resets key status before checking
TBGL_ResetKeyState()
T0 = GetTickCount

'---Main script loop
While TBGL_IsWindow(hWnd)
T1 = GetTickCount
Incr nFrames

'---constant speed of movement by scaling movements relative to frame rate
FrameRate = TBGL_getFrameRate
FPSCount = help_CalcFramerate

'---Prepares clear frame
TBGL_ClearFrame
' -- Render3D scene
TBGL_RenderMatrix3D
TBGL_EntityGetPos(%MY_WORLD, %ENT_CAMERA, x, y, z)

'TBGL_EntitySetPos(%MY_WORLD, %ENT_CAMERA, x, 24.0+Sin(GetTickCount/1000/SlowMotion)/10, z )
TBGL_EntityPush(%MY_WORLD, %ENT_CAMERA, 0, Sin(GetTickCount/1000/SlowMotion)/1000, 0 )
TBGL_SceneRender(%MY_WORLD)

' -- Render2D scene overlay, with 0,0 in the center of the screen
TBGL_RenderMatrix2D(-aspectRatio/2, -0.5, aspectRatio/2, 0.5)
TBGL_Color 55,55,255

' -- Disable some states in section of code
TBGL_PushStateProtect %TBGL_LIGHTING Or %TBGL_TEXTURING Or %TBGL_DEPTH
' Cross created to navigate weapons, it has size of +/- 5% => 0.05
TBGL_Line -0.05, 0, 0.05, 0
TBGL_Line 0,-0.05, 0, 0.05

' Print font at pixels
TBGL_PrintFont "Framerate: " , 0.1, 0.00, 0
TBGL_PrintFont "Actual " & Format$(FPSCount/SlowMotion, "000") , 0.1,-0.025, 0
TBGL_PrintFont "Average " & Format$(nFrames/((T1-T0+1)/1000),"000") , 0.1,-0.05, 0

If SlowMotion = 10 Then TBGL_PrintFont "SlowMotion", 0.025,-0.035,-0.1

TBGL_PopStateProtect

TBGL_DrawFrame

If TBGL_GetWindowKeyState( hWnd, %VK_UP) Then TBGL_EntityPush(%MY_WORLD, %ENT_CAMERA, 0, 0, 5/FrameRate) ' 5 meters/second
if TBGL_GetwindowKeyState( hWnd, %VK_DOWN) then tbgl_EntityPush(%MY_WORLD, %ENT_CAMERA, 0, 0, -5/FrameRate)

'If TBGL_GetWindowKeyState( hWnd, %VK_UP) Then TBGL_EntityPush(%MY_WORLD, %ENT_CREATECITY, 0, 0, 5/FrameRate) ' 5 meters/second
'If TBGL_GetWindowKeyState( hWnd, %VK_DOWN) Then TBGL_EntityPush(%MY_WORLD, %ENT_CREATECITY, 0, 0, -5/FrameRate)

'If TBGL_GetWindowKeyState( hWnd, %VK_UP) Then TBGL_EntityPush(%MY_WORLD, %ENT_BLOX, 0, 0, 5/FrameRate) ' 5 meters/second
'If TBGL_GetWindowKeyState( hWnd, %VK_DOWN) Then TBGL_EntityPush(%MY_WORLD, %ENT_BLOX, 0, 0, -5/FrameRate)

If TBGL_GetWindowKeyState( hWnd, %VK_PGUP) Then TBGL_EntityPush(%MY_WORLD, %ENT_CAMERA, 0, 5/FrameRate, 0 )
If TBGL_GetWindowKeyState( hWnd, %VK_PGDN) Then TBGL_EntityPush(%MY_WORLD, %ENT_CAMERA, 0, -5/FrameRate, 0 )

If TBGL_GetWindowKeyState( hWnd, %VK_LEFT) Then TBGL_EntityTurn(%MY_WORLD, %ENT_CAMERA, 0, 60/FrameRate, 0)
if TBGL_GetwindowKeyState( hWnd, %VK_RIGHT) then tbgl_EntityTurn(%MY_WORLD, %ENT_CAMERA, 0, -60/FrameRate, 0) ' 60°/second

if TBGL_GetwindowKeyState( hWnd, %VK_ESCAPE) then EXIT WHILE

WEND

'---Closes OpenGL window
TBGL_DestroyWindow

Function CreateGridAsDList() As Long ' Returns to which display list we save
local i, j as long

TBGL_NewList %LST_GRID
'---Let's build a grid
TBGL_BeginPoly %GL_LINES
TBGL_Color 0,255,255

For i = -20 To 20
For j = -20 To 20
TBGL_Vertex -20, 0, j
TBGL_Vertex 20, 0, j
TBGL_Vertex i, 0, -20
TBGL_Vertex i, 0, 20
Next
Next
TBGL_EndPoly
tbgl_EndList

function = 1
End Function

' ----- Create new city BLOX with tbgl_box ---------------------------------------------
Function CreateBloxAsDList() As Long ' Returns to which display list we save
'---------------------------------------------------------------------------------------
Local i, j, width As Long

TBGL_NewList %LST_BLOX
TBGL_UseTexturing %TRUE
TBGL_BindTexture 1
TBGL_Color Rnd(128,255),Rnd(128,255),Rnd(128,255)

For i = -40 To 40 Step 8
TBGL_Box 10+i,20+i,10+i
For j = -30 To 30 Step 6
width = Rnd(4, 14)
TBGL_Box 6+j,6+j,6+j
Next
Next
TBGL_EndList
TBGL_UseTexturing %FALSE
Function = 1

End Function

'---------------------------------frameRate FPS
Function help_CalcFramerate() As Single

Local ThisTime As DWord
Local FPS As Long
ThisTime = QueryPerformanceCounter

FPS = QueryPerformanceFrequency * SlowMotion / (ThisTime - LastTime + 1)
If FPS = 0 Then FPS = 1
LastTime = ThisTime

Function = (FPSCount + FPS) / 2

End Function

2) favour: it's possible to add this post before all ? or split topic in two threads ?

a) one for "cityfog" work in progress with current examples
b) for "cityfog complete" part one, two, three for ready examples
(only code pure and zip files for downloading) ? ;)

would be nice.

bye, denis

Lionheart008
11-03-2010, 20:35
good work denis :occasion:
I like this little dungeon scene and blue fog atmosphere. the idea of crosshair and framerate/average display. now you are looking for enemies or hiding treasures? ;)
it's always a good feeling if you're seeing good tbgl progress for yourself in short time!

nevertheless: Good luck for more good progress, thanks, frank