Here is a seemingly odd issue. If you drag the host Window to another monitor, the WindowedScreen loses the display...... drag it back to the original monitor and unfortunately the display does not return - close the window and the app crashes.
It probably has something to do with device context?
This test code is from ApplePi, slightly modified to make the Window smaller and the code stand-alone:
Code: Select all
Enumeration
#MESH
#LIGHT
#CAMERA_ONE
#BUTTON
#mainwin
EndEnumeration
;constants for the biomorph function
#constreal = 0.5
#constimag = 0
#screenheight = 500
#screenwidth = 500
Global.f dx, dy, x, y, z
Global wd, ht, i, count, n, iter
Global.f w, leng, tx, ty, tz, tem
Global.f cr, ci, cj, ck, wk, inc, distance
Global mand, zval
Global.f angle
Define.f red, green, blue
;zval = 1 shows entire set
;zval = 0 cuts set in half
;zval = 0 is an interesting effect
wd = 500
ht = 500
;defines the shape of the Julia Set
cr = -0.200
ci = 0.800
cj = 0.000
ck = 0.000
wk = 0.000
;mand = 0 is Julia Set
;mand = 1 is Mandelbrot 3D
mand = 1
;zval = 1 shows entire set
;zval = 0 cuts set in half
;zval = 0 is an interesting effect
zval = 1
iter = 5
inc = 5
;#quat = 1
zval = 1
iter = 5
inc = 5
Procedure.f RandF(Min.f, Max.f, Resolution.i = 10000)
ProcedureReturn (Min + (Max - Min) * Random(Resolution) / Resolution)
EndProcedure
Quit.b = #False
rot.l=1 :stopFlag = 1
xs.f = 0.3:ys.f = 0.3:zs.f = 0.3
x.f: y.f :z.f: x0.f: y0.f=1 :z0.f
rotx.f:roty.f=1:rotz.f :rotx0.f: roty0.f: rotz0.f
up.f = 2.2: depth.f=0
If OpenWindow(#mainwin, 0, 0, 800, 600, "PgUp PgD scale mesh..Arrows for rotation, space: stop/rotate, QA Up/Down, WS far/near", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(#BUTTON, 0, 600-60, 60, 30, "rotate/stop")
;Initialize environment
InitEngine3D()
InitSprite()
OpenWindowedScreen(WindowID(#mainwin), 0, 0, 800, 600-70, 0, 0, 0)
WorldShadows(#PB_Shadow_Additive)
InitKeyboard()
SetFrameRate(60)
Add3DArchive("Data/Textures", #PB_3DArchive_FileSystem)
CreateLight(0,RGB(255,255,255),-100,40,30)
AmbientColor(RGB(100,100,100))
CreateCamera(#CAMERA_ONE, 0, 0, 100, 100)
MoveCamera(#CAMERA_ONE, 0, 4, 9)
CameraLookAt(#CAMERA_ONE, 0, 2, 0)
RotateCamera(#CAMERA_ONE, -15, 0, 0)
EndIf
SetActiveGadget(#BUTTON)
;SkyDome("clouds.jpg", 100) ;for blue color background
;- Mesh Stars
CreateTexture(0,16,16)
StartDrawing(TextureOutput(0))
Box(0, 0, 16, 16,RGB(255,255,255))
StopDrawing()
CreateMaterial(0, TextureID(0))
DisableMaterialLighting(0, #True)
CreateMesh(1, #PB_Mesh_PointList, #PB_Mesh_Dynamic)
;CreateMesh(1, #PB_Mesh_PointList, #PB_Mesh_Static)
SetMeshMaterial(1, MaterialID(0))
Global Stars = CreateNode(#PB_Any)
AttachNodeObject(Stars, MeshID(1))
Procedure.f calcleng( x.f, y.f, z.f)
w.f: kr.f: ki.f: kj.f: kk.f
w = wk
n = 0
If mand = 1 ;full Mandelbrot set
kr = x
ki = y
kj = z
kk = 0
Else ;else draw Julia Set
kr = cr
ki = ci
kj = cj
kk = ck
EndIf
While n < iter
tem = x+x
x = x*x-y*y-z*z-w*w+kr
y = tem*y + ki
z = tem*z + kj
w = tem*w + kk
n+1
distance = x*x+y*y+z*z+w*w
If distance > 4
n = iter
EndIf
Wend
;Return distance
ProcedureReturn distance
EndProcedure
Procedure calcit()
zz.f
foo.l
iterations = 3000000
count = 0
If zval = 0
zz = 2.0
Else
zz = 4.0
EndIf
For foo = 0 To iterations
;x.f = RandF(0, 1)
;y.f = RandF(0, 1)
x.f = RandF(-2, 2)
y.f = RandF(-2, 2)
z.f = zz*RandF(0, 1) -2.0
;calls the quaternion calculation
leng.f = calcleng(x,y,z)
If leng < 4
MeshVertexPosition(x, y, z)
red = (x+Cos(15*leng))*255
green = (y+Sin(1-leng)*Cos(5*leng))*255
blue = (z+Sin(0.75*leng))*255
If red < 0 : red = 0 : EndIf
If green < 0 : green = 0 : EndIf
If blue < 0 : blue = 0 : EndIf
;If red > 255 : red = red-255 : EndIf
;If green > 255 : green = green-255 : EndIf
;If blue > 255 : blue = blue-255 : EndIf
;MeshVertexColor(RGBA(red,green,blue,0))
MeshVertexColor(RGB(red,green,blue))
EndIf
Next
FinishMesh(#False)
NormalizeMesh(1)
EndProcedure
calcit() ; calling the mandel 3D or julia generator function
;Main loop
Repeat
Event = WindowEvent()
If Event = #PB_Event_Gadget
Select EventGadget()
Case #BUTTON
If rot = 0
rot = 1
rotx= rotx0:roty=roty0:rotz=rotz0 ; restore rotation status
stopFlag = 1
Else
rot = 0
rotx0= rotx:roty0=roty:rotz0=rotz ;back up rotation status
rotx=0:roty=0:rotz=0
stopFlag = 0
EndIf
EndSelect
EndIf
If stopFlag=1
x + rotx
y + roty
z + rotz
EndIf
RotateNode(Stars, x, y, z)
RenderWorld()
FlipBuffers()
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Up) ; rotate left
rotx=1:roty=0:rotz=0
rotx0 = rotx: roty0 = roty :rotz0 = rotz
x + rotx
y + roty
z + rotz
stopFlag=0
rot = 0
ElseIf KeyboardPushed(#PB_Key_Down) ; rotate right
rotx=-1:roty=0:rotz=0
rotx0 = rotx: roty0 = roty :rotz0 = rotz
x + rotx
y + roty
z + rotz
stopFlag=0
rot = 0
ElseIf KeyboardPushed(#PB_Key_Right) ; rotate up
rotx=0:roty=1:rotz=0
rotx0 = rotx: roty0 = roty :rotz0 = rotz
x + rotx
y + roty
z + rotz
stopFlag=0
rot = 0
ElseIf KeyboardPushed(#PB_Key_Left) ; rotate down
rotx=0:roty=-1:rotz=0
rotx0 = rotx: roty0 = roty :rotz0 = rotz
x + rotx
y + roty
z + rotz
stopFlag=0
rot = 0
EndIf
If KeyboardPushed(#PB_Key_PageUp) ; scale up model
xs.f = 1.1:ys.f = 1.1:zs.f = 1.1
ScaleNode(Stars,xs,ys,zs)
ElseIf KeyboardPushed(#PB_Key_PageDown) ; scale down model
xs = 0.9:ys = 0.9:zs= 0.9
ScaleNode(Stars,xs,ys,zs)
EndIf
If KeyboardPushed(#PB_Key_Q) ; up move
up + 0.1
MoveNode(Stars,0,up,depth,#PB_Absolute)
ElseIf KeyboardPushed(#PB_Key_A) ; down move
up - 0.1
MoveNode(Stars,0,up,depth,#PB_Absolute)
ElseIf KeyboardPushed(#PB_Key_W) ; forward move
depth - 0.1
MoveNode(Stars,0,up,depth,#PB_Absolute)
ElseIf KeyboardPushed(#PB_Key_S) ; inward move
depth + 0.1
MoveNode(Stars,0,up,depth,#PB_Absolute)
EndIf
If KeyboardPushed(#PB_Key_Escape)
Quit = #True
EndIf
Until Quit = #True Or Event = #PB_Event_CloseWindow