Whenever I make the window bigger the canvas doesn't update or something.
M3DCanvas.bmx
SuperStrict
Framework BRL.GLGraphics
Import BRL.Win32MaxGUI
Import BRL.Timer
Import BRL.EventQueue
Import sidesign.minib3d
SetGraphicsDriver GLGraphicsDriver(), GRAPHICS_BACKBUFFER | GRAPHICS_DEPTHBUFFER
Global Wnd_Main:TGadget = CreateWindow("3d Canvas Test", 0, 0, 800, 600, Desktop(), WINDOW_TITLEBAR | WINDOW_RESIZABLE)
'MaximizeWindow Wnd_Main
Global Cnv_G3D:TGadget = CreateCanvas(0, 0, ClientWidth(Wnd_Main), ClientHeight(Wnd_Main), Wnd_Main)
SetGadgetLayout Cnv_G3D, 1, 1, 1, 1
TGlobal.width = ClientWidth(Cnv_G3D)
TGlobal.height = ClientHeight(Cnv_G3D)
TGlobal.depth = 32
TGlobal.mode = 0
TGlobal.rate = 60
SetGraphics CanvasGraphics(Cnv_G3D)
TGlobal.GraphicsInit()
Global cam:TCamera = CreateCamera()
PositionEntity cam, 0, 0, -15
Global light:TLight = CreateLight()
RotateEntity light, 45, 0, 0
Global marker:TMesh = CreateSphere()
ScaleEntity marker, 0.15, 0.15, 0.15
EntityColor marker, 255, 0, 0
Local sphere:TMesh = CreateSphere()
EntityRadius sphere, 1
EntityPickMode sphere, 1
PositionEntity sphere, -10, 0, 0
Local box:TMesh = CreateCube()
FitMesh box, -2, -1, -1, 4, 2, 2
EntityBox box, -2, -1, -1, 4, 2, 2
EntityPickMode box, 3
PositionEntity box, 10, 0, 0
;' used by camera code
Global mxs#=0
Global mys#=0
Global move#=0.5
;' used by fps code
Global old_ms:Int = MilliSecs()
Global renders:Int
Global fps:Int
Global mx:Int = 0, my:Int = 0
Global MST_LEFT:Int = 0, MST_RIGHT:Int = 0
Global KST_A:Int = 0, KST_D:Int = 0, KST_W:Int = 0, KST_S:Int = 0, KST_Q:Int = 0, KST_SPACE:Int = 0
CreateTimer(60)
While Not KeyDown(key_escape)
Select WaitEvent()
Case EVENT_TIMERTICK
Cnv_G3D_Input
RedrawGadget Cnv_G3D
Case EVENT_MOUSEMOVE
mx = EventX()
my = EventY()
Case EVENT_KEYDOWN
Select EventData()
Case KEY_ESCAPE End
Case KEY_W KST_W = 1
Case KEY_S KST_S = 1
Case KEY_A KST_A = 1
Case KEY_D KST_D = 1
Case KEY_Q KST_Q = 1
Case KEY_SPACE KST_SPACE = 1
End Select
Case EVENT_KEYUP
Select EventData()
Case KEY_W KST_W = 0
Case KEY_S KST_S = 0
Case KEY_A KST_A = 0
Case KEY_D KST_D = 0
Case KEY_Q KST_Q = 0
Case KEY_SPACE KST_SPACE = 0
End Select
Case EVENT_MOUSEDOWN
Select EventData()
Case 1
EntityColor box, 255, 255, 255
EntityColor sphere, 255, 255, 255
Local pick:TEntity = CameraPick(cam, mx, my)
'Local pe:TEntity = PickedEntity()
'Local ps:TSurface = PickedSurface()
If pick
DebugLog "Picked!"
'DebugLog "PickedX(): " + PickedX()
'DebugLog "PickedY(): " + PickedY()
'DebugLog "PickedZ(): " + PickedZ()
'DebugLog "PickedNX(): " + PickedNX()
'DebugLog "PickedNY(): " + PickedNY()
'DebugLog "PickedNZ(): " + PickedNZ()
'DebugLog "PickedTime(): " + PickedTime()
'DebugLog "PickedEntity(): " + PickedEntity()
'DebugLog "PickedSurface(): " + PickedSurface()
'DebugLog "PickedTriangle(): " + PickedTriangle()
EntityColor PickedEntity(), 255, 255, 0
PositionEntity marker, PickedX(), PickedY(), PickedZ()
Else
DebugLog "Not Picked"
EndIf
Case 2
MST_LEFT = 1
End Select
Case EVENT_MOUSEUP
Select EventData()
Case 2
MST_LEFT = 0
End Select
Case EVENT_WINDOWSIZE
'SetGadgetShape Cnv_G3D, 0, 0, ClientWidth(Wnd_Main), ClientHeight(Wnd_Main)
TGlobal.width = ClientWidth(Cnv_G3D)
TGlobal.height = ClientHeight(Cnv_G3D)
Case EVENT_WINDOWCLOSE
End
Case EVENT_GADGETPAINT
'SetGraphics CanvasGraphics(Cnv_G3D)
MouseXSpeed2()
MouseYSpeed2()
RenderWorld
renders = renders + 1
If MilliSecs() - old_ms >= 1000
old_ms = MilliSecs()
fps = renders
renders = 0
EndIf
Text 0, 0, "FPS: " + fps
Flip
End Select
Wend
End
Function Cnv_G3D_Input()
If KST_W MoveEntity cam, 0, 0, move#
If KST_S MoveEntity cam, 0, 0, -move#
If KST_A MoveEntity cam, -move#, 0, 0
If KST_D MoveEntity cam, move#, 0, 0
If KST_SPACE PositionEntity cam, 0, 0, -15
If MST_LEFT
mxs# :+ MouseXSpeed2() / 5.0
mys# :+ MouseYSpeed2() / 5.0
If KST_Q
MoveEntity cam, mxs# / 50.0, -mys# / 50.0, 0
Else
RotateEntity cam, mys#, -mxs#, 0
EndIf
EndIf
End Function
Function MouseXSpeed2:Int()
Global oldmx:Int
Local mxs:Int = mx - oldmx
oldmx = mx
Return mxs
End Function
Function MouseYSpeed2:Int()
Global oldmy:Int
Local mys:Int = my - oldmy
oldmy = my
Return mys
End Function
|