Thanks for a great v.0.45 release.
I'm trying to hack together a working example of max2d on a resizable canvas with minib3d.
I can't seem to make max2D resize to fit the canvas.
I was thinking SetViewport 0,0, TGlobal.width, TGlobal.height in the EVENT_WINDOWSIZE event should do it, but it doesn't seem to work.
Can somebody help?
(resize window larger and hit spacebar to see clipping of fireworks)
I'm trying to hack together a working example of max2d on a resizable canvas with minib3d.
I can't seem to make max2D resize to fit the canvas.
I was thinking SetViewport 0,0, TGlobal.width, TGlobal.height in the EVENT_WINDOWSIZE event should do it, but it doesn't seem to work.
Can somebody help?
(resize window larger and hit spacebar to see clipping of fireworks)
'Import "../minib3d.bmx" Strict Import sidesign.minib3d Import maxgui.win32maxguiex Global width ,height SetGraphicsDriver GLMax2DDriver(),GRAPHICS_BACKBUFFER|GRAPHICS_DEPTHBUFFER Local win:TGadget=CreateWindow("MiniB3D with Max 2d in a GUI window", 10, 10, 512, 512 ) Local can:TGadget=CreateCanvas(0,0,ClientWidth(win),ClientHeight(win),win,0) SetGadgetLayout can,1,1,1,1 TGlobal.width=ClientWidth(win) TGlobal.height=ClientHeight(win) TGlobal.depth=16 TGlobal.mode=0 TGlobal.rate=60 SetGraphics CanvasGraphics(can) TGlobal.GraphicsInit() Local cam:TCamera=CreateCamera() PositionEntity cam,0,0,-10 Local light:TLight=CreateLight(1) Local tex:TTexture=LoadTexture("media/test.png") Local cube:TMesh=CreateCube() Local sphere:TMesh=CreateSphere() Local cylinder:TMesh=CreateCylinder() Local cone:TMesh=CreateCone() PositionEntity cube,-6,0,0 PositionEntity sphere,-2,0,0 PositionEntity cylinder,2,0,0 PositionEntity cone,6,0,0 EntityTexture cube,tex EntityTexture sphere,tex EntityTexture cylinder,tex EntityTexture cone,tex Local cx#=0 Local cy#=0 Local cz#=0 Local pitch#=0 Local yaw#=0 Local roll#=0 ' used by fps code Local old_ms:Int=MilliSecs() Local renders:Int Local fps:Int Local up_key:Int Local down_key:Int Local left_key:Int Local right_key:Int CreateTimer( 60 ) ' Create a spark type Type spark Field x#,y#,z#,vy#,xd#,yd#,zd#,r#,g#,b#,alpha# End Type ' Load spark image Global sparki:TImage=LoadImage("media/spark.png") ' Set no. of sparks to be created per firework Global no_sparks=500 ' Create spark list Global spark_list:TList=New TList ' Load and set font Global font:TImageFont=LoadImageFont("Arial.ttf",1) SetImageFont font While True WaitEvent() Select EventID() Case EVENT_KEYDOWN Select EventData() Case KEY_SPACE AddFireWork() Case KEY_ESCAPE End Case KEY_UP up_key=True Case KEY_DOWN down_key=True Case KEY_LEFT left_key=True Case KEY_RIGHT right_key=True EndSelect Case EVENT_KEYUP Select EventData() Case KEY_UP up_key=False Case KEY_DOWN down_key=False Case KEY_LEFT left_key=False Case KEY_RIGHT right_key=False EndSelect Case EVENT_WINDOWCLOSE End Case EVENT_WINDOWSIZE TGlobal.width=ClientWidth(win) TGlobal.height=ClientHeight(win) cam.CameraViewport(0,0,TGlobal.width,TGlobal.height) width=ClientWidth(win) height=ClientHeight(win) ' alas no effect ? SetViewport 0,0, TGlobal.width, TGlobal.height DebugLog "EVENT_WINDOWSIZE" Case EVENT_TIMERTICK If up_key Then cz#=cz#+1.0 If left_key Then cx#=cx#-1.0 If right_key Then cx#=cx#+1.0 If down_key Then cz#=cz#-1.0 MoveEntity cam,cx#*0.5,cy#*0.5,cz#*0.5 RotateEntity cam,pitch#,yaw#,roll# cx#=0 cy#=0 cz#=0 RedrawGadget can Case EVENT_GADGETPAINT SetGraphics CanvasGraphics(can) TurnEntity cube,0,1,0 RenderWorld BeginMax2D() ' MiniB3D function UpdateMax2D() ' your function EndMax2D() ' MiniB3D function Flip 0 'SetClsColor 200,0,0 'Cls EndSelect Wend End Function AddFireWork() ' If space key pressed then create new set of sparks (new firework) 'If KeyHit(KEY_SPACE) 'Or 2=2 Local x#=Rand(-100,100) Local y#=Rand(-100,100) Local z#=200 Local r#=Rand(255) Local g#=Rand(255) Local b#=Rand(255) For Local i=1 To no_sparks Local speed# = 0.1 Local ang1# = Rnd!(360) Local ang2# = Rnd!(360) Local sp:spark=New Spark spark_list.AddLast sp sp.x=x# sp.y=y# sp.z=z# sp.xd=Cos(ang1#)*Cos(ang2#)*speed# sp.yd=Cos(ang1#)*Sin(ang2#)*speed# sp.zd=Sin(ang1#)*speed# sp.r=r sp.g=g sp.b=b sp.alpha=1 Next ' EndIf End Function Function UpdateMax2D() ' Draw all sparks For Local sp:spark=EachIn spark_list ' If spark alpha is above 0 then draw it... If sp.alpha>0 sp.x=sp.x+sp.xd*10.0 sp.y=sp.y+sp.yd*10.0 sp.z=sp.z+sp.zd*10.0 sp.y=sp.y+sp.vy# sp.vy=sp.vy+0.02 ' Calculate x and y draw values based on x,y,z co-ordinates Local x#=(width/2.0)+((sp.x/sp.z)*500) Local y#=(height/2.0)+((sp.y/sp.z)*500) sp.alpha=sp.alpha-0.01 SetColor sp.r#,sp.g#,sp.b# SetBlend LIGHTBLEND SetAlpha sp.alpha SetScale 20/sp.z,20/sp.z DrawImage sparki,x#,y# '...else remove spark from spark list Else spark_list.Remove sp EndIf Next SetBlend SOLIDBLEND SetScale 1,1 SetColor 255,255,255 DrawText "Press space to ignite firework",0,20 End Function