efly2020
03-04-2009, 00:28
I ammaking a program which begins as a menu to
various games which use different window sizes.
I wanted to ask the resident experts if this demo uses
the best way to change window sizes when using TBGL?
Thanks
Ralph Flye
Updated with version 2, 2009-04-05
Petr Schreiber
03-04-2009, 08:13
Hi,
thank you a lot for very nice demo! I like the hypnotic look, use of display lists ... hmmm :)
It was correct, only few possible problems.
I think 2 while loops were not necessary, and to change resolution you also do not need to kill and rebuild the window, it is enough to change its size in windowed mode using TBGL_SetWindowed.
User sometimes resizes the window "manually" - this is handled by putting TBGL_RenderMatrix in the inner loop.
Here is changed version:
'*-------------------------------------------------------*
'* *
'* TBGL Window Resizing Demo version 1 2009-04-02 *
'* *
'* code by Ralph Flye *
'* *
'* Disclaimer: Use at your own risk. *
'* *
'*-------------------------------------------------------*
Uses "TBGL"
%DL_Circle = 100
%DEG2RAD = M_Pi / 180 as double
%Radius = 200
%PointsMax = 15
dim PointsX(%PointsMax) as long
dim PointsY(%PointsMax) as long
dim stopping as long
dim changing as long
dim jk, jv, jr as long
dim Radius, r, g, b as long
dim CenterX, CenterY as long
dim StepAngle,Radians as double
dim time_now as double
dim time_frame_next as double
dim time_frame_delta as double
dim window_w as long = 800
dim window_h as long = 600
dim hWnd as dword = tbgl_CreateWindowex("press Space to resize window", window_w, window_h, 32, _
%tbgl_WS_WINDOWED or %tbgl_WS_MINIMIZEBOX or %tbgl_WS_CLOSEBOX )
tbgl_ShowWindow ' -- Use TBGL_ShowWindow right after creation of window
Randomize GetTickcount
changing = %FALSE
stopping = %FALSE
time_frame_delta = 140 ' -> 1 Frame Per 1.4 Seconds
time_frame_next = GetTickcount
CenterX = window_w \ 2
CenterY = window_h \ 2
tbgl_NewList %DL_Circle ' save circle drawing instructions, DL -> display list
tbgl_PushMatrix
tbgl_BeginPoly %GL_LINE_LOOP
for jk = 0 to 359 step 4
Radians = jk * %DEG2RAD
tbgl_Color 192,192,192
tbgl_Vertex Cos(Radians)*%Radius, Sin(Radians)*%Radius
next
tbgl_EndPoly
tbgl_PopMatrix
tbgl_EndList
tbgl_LineWidth 2
StepAngle = 360 / %PointsMax
for jk = 1 to %PointsMax ' calculate points on a circle
Radians = (StepAngle * jk) * %DEG2RAD
PointsX(jk) = Ceil(Cos(Radians) * %Radius + 0.5)
PointsY(jk) = Ceil(Sin(Radians) * %Radius + 0.5)
next
tbgl_ResetKeyState()
while tbgl_IsWindow(hWnd) ' (*)(*)(*) MAIN LOOP (*)(*)(*)
time_now = GetTickcount
if time_now > time_frame_next + time_frame_delta * 2 then
time_frame_next = time_now ' keep in sync
end if
if time_now < time_frame_next then
Sleep(3) ' so as to not use 100% of CPU
else
time_frame_next += time_frame_delta
' -- Good to force it here - kind of virtual vector resolution
tbgl_RenderMatrix2D( 0, window_H, window_w, 0 )
tbgl_ClearFrame
tbgl_Translate CenterX, CenterY
tbgl_CallList %DL_Circle ' using display list to boost performance
tbgl_BeginPoly %GL_Lines
for jk = 1 to %PointsMax
for jv = jk to %PointsMax
jr = RND(1,3)
if jr = 1 then:r = RND(140,180):else r = RND(40,90):end if
if jr = 2 then:g = RND(140,170):else g = RND(40,80):end if
if jr = 3 then:b = RND(140,180):else b = RND(40,90):end if
tbgl_Color r,g,b
tbgl_Vertex PointsX(jk), PointsY(jk) ' MoveTo
jr = RND(1,3)
if jr = 1 then:r = RND(190,240):else r = RND(110,180):end if
if jr = 2 then:g = RND(190,230):else g = RND(110,170):end if
if jr = 3 then:b = RND(190,240):else b = RND(110,180):end if
tbgl_Color r,g,b
tbgl_Vertex PointsX(jv), PointsY(jv) ' LineTo
next
next
tbgl_EndPoly
tbgl_DrawFrame
end if
if tbgl_GetWindowKeyOnce(hWnd,%VK_SPACE) then
changing = %TRUE
end if
if tbgl_GetWindowKeyOnce(hWnd,%VK_ESCAPE) then
stopping = %TRUE : Exit While
end if
if changing = %TRUE then ' window close button can also stop the program
changing = %FALSE
time_frame_next = time_now
window_w = RND(416,800) : window_h = RND(416,600)
CenterX = window_w \ 2
CenterY = window_h \ 2
' -- Set new windowed mode
TBGL_SetWindowed(hWnd, window_w, window_h)
end if
wend
tbgl_DestroyWindow ' stop program
Thanks,
Petr