'
' The entity skeleton for TBGL
' Suitable for developing editor apps
' , started on 12-08-2011
'
' paul.w.floyd first attempt
Uses "UI", "TBGL"
' -- ID numbers of controls
Begin ControlID
%lCanvas
%bClose
%myTimer
End ControlID
' -- Global equates
Begin Const
%MAIN_WIDTH = 640
%MAIN_HEIGHT = 480
%timeOut = 20 ' -- Determines graphics refresh rate in milliseconds
End Const
' -- Scene-Entity related ids
Begin Const
' -- Scene IDs
%sScene = 1
' -- Entity IDs
%eCamera = 1
%eLight
%eBox
%bAnima
End Const
Function TBMain()
Local hDlg As DWord
Dialog New Pixels, 0, "Dialog with TBGL",-1,-1, %MAIN_WIDTH, %MAIN_HEIGHT, _
%WS_POPUP Or %WS_VISIBLE Or _
%WS_CLIPCHILDREN Or %WS_CAPTION Or _
%WS_SYSMENU Or %WS_MINIMIZEBOX Or %WS_MAXIMIZEBOX Or %WS_THICKFRAME, 0 To hDlg
' -- Place controls here
Control Add Label, hDlg, %lCanvas, "", 5, 5, %MAIN_WIDTH-10, %MAIN_HEIGHT-40
Control Set Color hDlg, %lCanvas, %BLACK, %BLACK
Control Set Resize hDlg, %lCanvas, 1, 1, 1, 1
Control Add Button, hDlg, %bClose, "Close", %MAIN_WIDTH-105, %MAIN_HEIGHT-30, 100, 25
Control Add Button, hDlg, %bAnima, "Anima", %MAIN_WIDTH-245, %MAIN_HEIGHT-30, 100, 25
Control Set Resize hDlg, %bAnima, 0, 1, 0, 1
Control Set Resize hDlg, %bClose, 0, 1, 0, 1
Dialog Set Minsize hDlg, 320, 230
Dialog Show Modal hDlg, Call dlgCallback
End Function
CallBack Function dlgCallback()
Static hCtrl As DWord
Select Case CBMSG
Case %WM_INITDIALOG
Dialog Set Timer CBHNDL, %myTimer, %timeOut, %NULL
Control Handle CBHNDL, %lCanvas To hCtrl
' -- Init OpenGL
TBGL_BindCanvas(hCtrl)
' -- Create scene
TBGL_SceneCreate(%sScene)
' -- Create basic entities
' -- Create camera to look from 5, 5, 5 to 0, 0, 0
TBGL_EntityCreateCamera(%sScene, %eCamera)
TBGL_EntitySetPos(%sScene, %eCamera, 5, 5, 5)
TBGL_EntitySetTargetPos(%sScene, %eCamera, 0, 0, 0)
' -- Create point light
TBGL_EntityCreateLight(%sScene, %eLight)
TBGL_EntitySetPos(%sScene, %eLight, 15, 10, 5)
' -- Create something to look at
TBGL_EntityCreateBox(%sScene, %eBox, 0, 1, 1, 1, 0, 255, 255, 255)
TBGL_EntitySetPos(%sScene, %eBox, 0, 0, 0)
Case %WM_SIZE, %WM_SIZING
TBGL_UpdateCanvasProportions(hCtrl)
RenderMyImage(hCtrl)
Case %WM_TIMER
RenderMyImage(hCtrl)
Case %WM_CLOSE
TBGL_ReleaseCanvas(hCtrl)
Dialog Kill Timer CBHNDL, %myTimer
Case %WM_COMMAND
Select Case CBCTL
Case %bClose
If CBCTLMSG = %BN_CLICKED Then Dialog End CBHNDL
End Select
End Select
End Function
Function RenderMyImage( hCtrl As DWord )
Static FrameRate As Double
' Load Texture, Apply it.
TBGL_LoadTexture APP_SourcePath + "asterix2.bmp" , 1, %TBGL_TEX_MIPMAP
TBGL_LoadTexture APP_SourcePath + "illus.bmp", 2, %TBGL_TEX_MIPMAP
TBGL_LoadTexture APP_SourcePath + "simpsons.bmp" , 3, %TBGL_TEX_MIPMAP
TBGL_LoadTexture APP_SourcePath + "robotguy.bmp" , 4, %TBGL_TEX_MIPMAP
TBGL_LoadTexture APP_SourcePath + "schultz.bmp" , 5, %TBGL_TEX_MIPMAP
TBGL_LoadTexture APP_SourcePath + "charly.bmp" , 6, %TBGL_TEX_MIPMAP
If TBGL_CanvasBound(hCtrl) Then
FrameRate = TBGL_GetFrameRate
TBGL_ClearFrame
TBGL_SceneRender(%sScene)
CubesTextures()
TBGL_DrawFrame
TBGL_EntityTurn(%sScene, %eBOx, 0, 20/FrameRate, 0)
End If
End Function
Sub CubesTextures()
Dim xRot, yRot, zRot As Single
Dim frameRate As Double
FrameRate = TBGL_GetFrameRate
TBGL_Translate 0.0, 0.0, -5.0 ' Move Into Screen -5 Units
TBGL_Rotate Xrot, 1.0, 0.0, 0.0 ' Rotate on X-Axis
TBGL_Rotate Yrot, 0.0, 1.0, 0.0 ' Rotate on Y-Axis
TBGL_Rotate Zrot, 0.0, 0.0, 1.0 ' Rotate on Z-Axis
TBGL_UseTexturing %TRUE
TBGL_Color 200,155,0
TBGL_BindTexture 1
TBGL_BeginPoly %GL_QUADS
' Bottom Face
TBGL_TexCoord2D 1.0, 1.0 : TBGL_Vertex -1.5, -1.5, -1.5 ' Top Right of Texture and Quad
TBGL_TexCoord2D 0.0, 1.0 : TBGL_Vertex 1.5, -1.5, -1.5 ' Top Left
TBGL_TexCoord2D 0.0, 0.0 : TBGL_Vertex 1.5, -1.5, 1.5 ' Bottom Left
TBGL_TexCoord2D 1.0, 0.0 : TBGL_Vertex -1.5, -1.5, 1.5 ' Bottom Right
TBGL_EndPoly
TBGL_BindTexture 2
TBGL_BeginPoly %GL_QUADS
' Right Face
TBGL_TexCoord2D 1.0, 0.0 : TBGL_Vertex 1.5, -1.5, -1.5 ' Bottom Right of Texture and Quad
TBGL_TexCoord2D 1.0, 1.0 : TBGL_Vertex 1.5, 1.5, -1.5 ' Top Right
TBGL_TexCoord2D 0.0, 1.0 : TBGL_Vertex 1.5, 1.5, 1.5 ' Top Left
TBGL_TexCoord2D 0.0, 0.0 : TBGL_Vertex 1.5, -1.5, 1.5 ' Bottom Left
TBGL_EndPoly
TBGL_BindTexture 3
TBGL_BeginPoly %GL_QUADS ' Drawing using Quads
' Front Face
TBGL_TexCoord2D 0.0, 0.0 : TBGL_Vertex -1.5, -1.5, 1.5 ' Bottom Left of Texture and Quad
TBGL_TexCoord2D 1.0, 0.0 : TBGL_Vertex 1.5, -1.5, 1.5 ' Bottom Right
TBGL_TexCoord2D 1.0, 1.0 : TBGL_Vertex 1.5, 1.5, 1.5 ' Top Right
TBGL_TexCoord2D 0.0, 1.0 : TBGL_Vertex -1.5, 1.5, 1.5 ' Top Left
TBGL_EndPoly
TBGL_BindTexture 4
TBGL_BeginPoly %GL_QUADS ' Drawing using Quads
' Top Face
TBGL_TexCoord2D 0.0, 1.0 : TBGL_Vertex -1.5, 1.5, -1.5 ' Top Left of Texture and Quad
TBGL_TexCoord2D 0.0, 0.0 : TBGL_Vertex -1.5, 1.5, 1.5 ' Bottom Left
TBGL_TexCoord2D 1.0, 0.0 : TBGL_Vertex 1.5, 1.5, 1.5 ' Bottom Right
TBGL_TexCoord2D 1.0, 1.0 : TBGL_Vertex 1.5, 1.5, -1.5 ' Top Right
TBGL_EndPoly
TBGL_BindTexture 5
TBGL_BeginPoly %GL_QUADS
' Back Face
TBGL_TexCoord2D 1.0, 0.0 : TBGL_Vertex -1.5, -1.5, -1.5 ' Bottom Right of Texture and Quad
TBGL_TexCoord2D 1.0, 1.0 : TBGL_Vertex -1.5, 1.5, -1.5 ' Top Right
TBGL_TexCoord2D 0.0, 1.0 : TBGL_Vertex 1.5, 1.5, -1.5 ' Top Left
TBGL_TexCoord2D 0.0, 0.0 : TBGL_Vertex 1.5, -1.5, -1.5 ' Bottom Left
TBGL_EndPoly
TBGL_BindTexture 6
TBGL_BeginPoly %GL_QUADS
' Left Face
TBGL_TexCoord2D 0.0, 0.0 : TBGL_Vertex -1.5, -1.5, -1.5 ' Bottom Left of Texture and Quad
TBGL_TexCoord2D 1.0, 0.0 : TBGL_Vertex -1.5, -1.5, 1.5 ' Bottom Right
TBGL_TexCoord2D 1.0, 1.0 : TBGL_Vertex -1.5, 1.5, 1.5 ' Top Right
TBGL_TexCoord2D 0.0, 1.0 : TBGL_Vertex -1.5, 1.5, -1.5 ' Top Left
TBGL_EndPoly
Xrot += ( 54.0 / frameRate ) ' X-Axis Rotation
Yrot += ( 26.0 / frameRate ) ' Y-Axis Rotation
Zrot += ( 72.0 / frameRate ) ' Z-Axis Rotation
End Sub
my cube was displayed well, but too dark, different colors are missing. and I wanted to self rotate them, dont work with my cube sub, I suggest the entity had no id number for that. help to fix the problem I am glad to see. there was a lot to study. my mind is rotating in a tbgl mess. but the tbgl tool is very exciting, thank you guys!
Bookmarks