David
01-11-2013, 20:18
Hi all,
I'm trying to understand how to TBGL works.
I had join two samples in one program. this is the result:
'=============================================================================
'= Font from texture =
'= =
'= Petr Schreiber, 2007 =
'=============================================================================
Uses "TBGL"
randomize timer
type TSphere
x as single
y as single
radius as single
cR as long
cG as long
cB as long
end type
Dim hWnd As Dword
dim NumSphere as long = 8
dim mySphere(NumSphere) as TSphere
DIM runText As Single
dim FrameRate as double
local i as long
Local SphereHeld, SphereHeldR, SphereHeldW as long
local x,y,z as double
hWnd = TBGL_CreateWindowex("Left Click: Drag / Right Click: Info", 640, 480, 32, %TBGL_WS_WINDOWED or %tbgl_WS_CLOSEBOX) ' Creates OpenGL window, it returns handle
TBGL_ShowWindow ' Shows the window
Tbgl_LoadBMPFont App_SourcePath+"Textures\TBGL_Font.bmp" ' Loads texture for font
for i = 1 to NumSphere
mySphere(i).x = rnd(-5,5)
mySphere(i).y = rnd(-3,3)
mySphere(i).radius = rndf(0.2, 1)
mySphere(i).cR = rnd(128,255)
mySphere(i).cG = rnd(128,255)
mySphere(i).cB = rnd(128,255)
next
runText = 50
TBGL_ResetKeyState() ' Resets key status before keypress checking
while TBGL_IsWindow(hWnd)
'---Script will run on different PCs so we must assure
'---constant speed of movement by scaling movement relative to framerate
FrameRate = tbgl_GetFrameRate
TBGL_ClearFrame ' Prepares clear frame
tbgl_UseLighting %TRUE
tbgl_UseLightSource %GL_LIGHT0, %TRUE
TBGL_Camera 0,0,10,0,0,0 ' Setups camera to look from 0,0,5 to 0,0,0
for i = 1 to NumSphere
tbgl_Pushmatrix
tbgl_Translate mySphere(i).x, mySphere(i).y, 0
tbgl_Color mySphere(i).cR, mySphere(i).cG, mySphere(i).cB
tbgl_Sphere mySphere(i).radius
tbgl_Popmatrix
next
if tbgl_MouseGetLButton then
if SphereHeld = 0 then SphereHeld = GetSphereID( tbgl_MouseGetPosX, tbgl_MouseGetPosY )
elseif tbgl_MouseGetLButton = 0 then
SphereHeld = 0
end if
if tbgl_MouseGetRButton then
if SphereHeldR = 0 then SphereHeldR = GetSphereID( tbgl_MouseGetPosX, tbgl_MouseGetPosY )
elseif tbgl_MouseGetRButton = 0 then
SphereHeldR = 0
end if
if SphereHeld then
TBGL_GetPixelInfo tbgl_MouseGetPosX, tbgl_MouseGetPosY, %TBGL_PINFO_XYZ, x,y,z
mySphere(SphereHeld).x = x
mySphere(SphereHeld).y = y
end if
if SphereHeldR then
TBGL_GetPixelInfo tbgl_MouseGetPosX, tbgl_MouseGetPosY, %TBGL_PINFO_XYZ, x,y,z
mySphere(SphereHeldR).x = x
mySphere(SphereHeldR).y = y
msgbox (0, "Selected Sphere:" & str$(SphereHeldR))
end if
TBGL_DrawFrame
TBGL_ClearFrame
tbgl_UseLighting %False
tbgl_UseLightSource %GL_LIGHT0, %False
TBGL_Camera 0,0,0.2,0,0,0
TBGL_Color 255,128,0
tbgl_printBMP "THIN",14,6
TBGL_Color 0,0,255
tbgl_printBMP "BASIC",18,6
TBGL_UseBlend %TRUE
TBGL_Color 255,255,0
tbgl_printBMP "- using TBGL module -",8,8+sin(timer)
TBGL_UseBlend %FALSE
runText -= 10 / FrameRate
if runText < -100 then runText = 50
TBGL_Color 255,255,255
tbgl_printBMP "thinBasic - interpreted language with no limits", runText, 25
TBGL_DrawFrame ' Swaps the buffers - displays rendered image
if TBGL_GetWindowKeyState( hWnd, %VK_ESCAPE) then EXIT WHILE
wend
TBGL_DestroyWindow ' Closes OpenGL window
function GetSphereID( mouseX as long, mouseY as long )
local cX, cY, cz as single
local i as long
TBGL_GetPixelInfo ( mouseX, mouseY, %TBGL_PINFO_XYZ, cx, cy, cz )
function = 0
for i = 1 to NumSphere
if cx >< mySphere(i).x-mySphere(i).radius, mySphere(i).x+mySphere(i).radius and _
cy >< mySphere(i).y-mySphere(i).radius, mySphere(i).y+mySphere(i).radius then
function = i
end if
next
end function
Sample works, but not really fine...
I had detected the TBGL_Camera changes from 0,0,10,0,0,0 to 0,0,0.2,0,0,0
the difference between 10 and 0.2 is very significative.
I'm trying to understand what means the TBGL_Camera values, in order to normalize with only one value.
Sometimes TBGL_Camera values appairs as Zoom of the scene and changes the logic of the x,y choords of the sphere (-5 to 5) instead (0 to 640)
Sometimes, the text appairs toooo small, almost invisible...
I can't understand this logic.
Could any tell me about the logic of TBGL_Camera, and it relation with the x,y choords ?
Thanks in advance,
David
I'm trying to understand how to TBGL works.
I had join two samples in one program. this is the result:
'=============================================================================
'= Font from texture =
'= =
'= Petr Schreiber, 2007 =
'=============================================================================
Uses "TBGL"
randomize timer
type TSphere
x as single
y as single
radius as single
cR as long
cG as long
cB as long
end type
Dim hWnd As Dword
dim NumSphere as long = 8
dim mySphere(NumSphere) as TSphere
DIM runText As Single
dim FrameRate as double
local i as long
Local SphereHeld, SphereHeldR, SphereHeldW as long
local x,y,z as double
hWnd = TBGL_CreateWindowex("Left Click: Drag / Right Click: Info", 640, 480, 32, %TBGL_WS_WINDOWED or %tbgl_WS_CLOSEBOX) ' Creates OpenGL window, it returns handle
TBGL_ShowWindow ' Shows the window
Tbgl_LoadBMPFont App_SourcePath+"Textures\TBGL_Font.bmp" ' Loads texture for font
for i = 1 to NumSphere
mySphere(i).x = rnd(-5,5)
mySphere(i).y = rnd(-3,3)
mySphere(i).radius = rndf(0.2, 1)
mySphere(i).cR = rnd(128,255)
mySphere(i).cG = rnd(128,255)
mySphere(i).cB = rnd(128,255)
next
runText = 50
TBGL_ResetKeyState() ' Resets key status before keypress checking
while TBGL_IsWindow(hWnd)
'---Script will run on different PCs so we must assure
'---constant speed of movement by scaling movement relative to framerate
FrameRate = tbgl_GetFrameRate
TBGL_ClearFrame ' Prepares clear frame
tbgl_UseLighting %TRUE
tbgl_UseLightSource %GL_LIGHT0, %TRUE
TBGL_Camera 0,0,10,0,0,0 ' Setups camera to look from 0,0,5 to 0,0,0
for i = 1 to NumSphere
tbgl_Pushmatrix
tbgl_Translate mySphere(i).x, mySphere(i).y, 0
tbgl_Color mySphere(i).cR, mySphere(i).cG, mySphere(i).cB
tbgl_Sphere mySphere(i).radius
tbgl_Popmatrix
next
if tbgl_MouseGetLButton then
if SphereHeld = 0 then SphereHeld = GetSphereID( tbgl_MouseGetPosX, tbgl_MouseGetPosY )
elseif tbgl_MouseGetLButton = 0 then
SphereHeld = 0
end if
if tbgl_MouseGetRButton then
if SphereHeldR = 0 then SphereHeldR = GetSphereID( tbgl_MouseGetPosX, tbgl_MouseGetPosY )
elseif tbgl_MouseGetRButton = 0 then
SphereHeldR = 0
end if
if SphereHeld then
TBGL_GetPixelInfo tbgl_MouseGetPosX, tbgl_MouseGetPosY, %TBGL_PINFO_XYZ, x,y,z
mySphere(SphereHeld).x = x
mySphere(SphereHeld).y = y
end if
if SphereHeldR then
TBGL_GetPixelInfo tbgl_MouseGetPosX, tbgl_MouseGetPosY, %TBGL_PINFO_XYZ, x,y,z
mySphere(SphereHeldR).x = x
mySphere(SphereHeldR).y = y
msgbox (0, "Selected Sphere:" & str$(SphereHeldR))
end if
TBGL_DrawFrame
TBGL_ClearFrame
tbgl_UseLighting %False
tbgl_UseLightSource %GL_LIGHT0, %False
TBGL_Camera 0,0,0.2,0,0,0
TBGL_Color 255,128,0
tbgl_printBMP "THIN",14,6
TBGL_Color 0,0,255
tbgl_printBMP "BASIC",18,6
TBGL_UseBlend %TRUE
TBGL_Color 255,255,0
tbgl_printBMP "- using TBGL module -",8,8+sin(timer)
TBGL_UseBlend %FALSE
runText -= 10 / FrameRate
if runText < -100 then runText = 50
TBGL_Color 255,255,255
tbgl_printBMP "thinBasic - interpreted language with no limits", runText, 25
TBGL_DrawFrame ' Swaps the buffers - displays rendered image
if TBGL_GetWindowKeyState( hWnd, %VK_ESCAPE) then EXIT WHILE
wend
TBGL_DestroyWindow ' Closes OpenGL window
function GetSphereID( mouseX as long, mouseY as long )
local cX, cY, cz as single
local i as long
TBGL_GetPixelInfo ( mouseX, mouseY, %TBGL_PINFO_XYZ, cx, cy, cz )
function = 0
for i = 1 to NumSphere
if cx >< mySphere(i).x-mySphere(i).radius, mySphere(i).x+mySphere(i).radius and _
cy >< mySphere(i).y-mySphere(i).radius, mySphere(i).y+mySphere(i).radius then
function = i
end if
next
end function
Sample works, but not really fine...
I had detected the TBGL_Camera changes from 0,0,10,0,0,0 to 0,0,0.2,0,0,0
the difference between 10 and 0.2 is very significative.
I'm trying to understand what means the TBGL_Camera values, in order to normalize with only one value.
Sometimes TBGL_Camera values appairs as Zoom of the scene and changes the logic of the x,y choords of the sphere (-5 to 5) instead (0 to 640)
Sometimes, the text appairs toooo small, almost invisible...
I can't understand this logic.
Could any tell me about the logic of TBGL_Camera, and it relation with the x,y choords ?
Thanks in advance,
David