Topic: iB3D and MaxGui Improved Sample !

Hey guys!

I finally found a way to resize the GUI instantly inside the canvas !
It's incredible, but it really works !

Here's how to do, gman didn't included the IDriver.OnResize(size) function, that one was needed to resize the 3d view without having to restart...

Open C:\Program Files\blitzmax\mod\irrlicht.mod\core.mod\video\ivideodriver_wrap.h

After :

    IImage* IrrVideo_IVideoDriver_createImageFromStream(IVideoDriver* driver,IReadFile* file)
    {
        if (driver)
            return driver->createImageFromFile(file);
        else
            return 0;
    }

Add the following :

    void IrrVideo_IVideoDriver_OnResize(IVideoDriver* driver, s32 width, s32 height)
    {
        if (driver) {
            dimension2d<s32> size(width, height);
            driver->OnResize(size);
        }
    }

Save And Close.

Open C:\Program Files\blitzmax\mod\irrlicht.mod\core.mod\video\ivideodriver_wrap.bmx

After :

Function IrrVideo_IVideoDriver_createImageFromFile:Int(pIVideoDriver:Int, filename$z) ' returns IImage*

Add the following :

Function IrrVideo_IVideoDriver_OnResize(pIVideoDriver:Int, width:Int, height:Int)

Save And Close

Open C:\Program Files\blitzmax\mod\irrlicht.mod\core.mod\video\ivideodriver.bmx

After :

    Method createImageFromFile:IImage(filename:String)
        Return IImage.createFromHandle(IrrVideo_IVideoDriver_createImageFromFile(handle,filename))
    EndMethod

Add the following :

    Method OnResize(width:Int, height:Int)
        IrrVideo_IVideoDriver_OnResize(handle, width, height) ' returns IImage*
    End Method

Compile the modules.
Here's the full code to test :

' this is an example showing how to display Irrlicht in a panel on a MaxGUI form.  i have modified it a bit
' by adding an eventreceiver to the Irrlicht instance to show how MaxGUI and Irrlicht events can coexist.
' it is important to note that there still is probably some issues to work out, but for now this works.
'
' NOTE: press the 'w' key to toggle wireframe

SuperStrict 
Framework Irrlicht.B3D

Import BRL.Basic
Import BRL.Win32MaxGUI
Import BRL.EventQueue

Local window:TGadget' Author: robobimbo

Local windowWidth:Int = 800
Local windowHeight:Int = 600

window = CreateWindow("MyApp", 100, 100,  ..
    windowWidth, windowHeight, Null)',WINDOW_TITLEBAR | WINDOW_CLIENTCOORDS | WINDOW_HIDDEN)

' create window To put irrlicht in
Global hIrrlichtWindow:TGadget = CreatePanel(0, 0, 800, 600, window, PANEL_ACTIVE | PANEL_BORDER)

Global param:SIrrlichtCreationParameters = SIrrlichtCreationParameters.Create()
param.setWindowId(QueryGadget(hIrrlichtWindow,QUERY_HWND))
param.setDriverType(EDT_OPENGL)

' create the device from the params object and initialize iB3D
ib3d_Graphics3DParams(param)

' setup a simple 3d scene

Local cam:CAMERA = ib3d_CreateCamera()
Local LIGHT1:LIGHT = ib3d_CreateLight()
ib3d_LightColor(LIGHT1, 255, 255, 255)
ib3d_LightRange(LIGHT1, 60)
ib3d_LightCastShadows(LIGHT1,True)
ib3d_PositionEntity(LIGHT1, 30, 0, 0)
ib3d_LightAmbientColor(LIGHT1,0,0,0)
Local plane:MESH = ib3d_CreatePlane(100, 100, 1, 1)
ib3d_PositionEntity(plane, 30, - 10, 30)
ib3d_PointEntity cam, plane
Local cube:PRIMITIVE = ib3d_CreateCube()
ib3d_PositionEntity(cube, 30, - 5, 30)
ib3d_NameEntity(cube, "CUBE")
ib3d_MoveEntity(cam, 0, 5, 0)

' show And execute dialog
ShowGadget(window)

' do message queue

Local bWireFrame:Int = False

While (True)

    ib3d_TurnEntity cube, 0, 2, 0
    ib3d_UpdateWorld()
    ib3d_RenderWorld()

    If PeekEvent() Then 
        PollEvent()
        Select EventID()
            Case EVENT_WINDOWSIZE
                Local devce:ib3d_engine = _g_ib3d_engine
                Local driver:IVideoDriver = devce.Driver
                SetGadgetShape(hIrrlichtWindow, 0, 0, ClientWidth(window), ClientHeight(window))
                ib3d_CameraViewport(cam, 0, 0, ClientWidth(window), ClientHeight(window))
                driver.OnResize(ClientWidth(window),ClientHeight(window))
                If ClientWidth(hIrrlichtWindow) > ClientHeight(hIrrlichtWindow)
                    ib3d_CameraAspectRatio(cam, 1.0 * (ClientWidth(hIrrlichtWindow) / ClientHeight(hIrrlichtWindow)))
                Else
                    ib3d_CameraAspectRatio(cam, 1.0 * (ClientHeight(hIrrlichtWindow) / ClientWidth(hIrrlichtWindow)))
                EndIf
                SetGadgetText(window,ClientWidth(window) + " x " + ClientHeight(window))
            Case EVENT_WINDOWCLOSE
                Exit
            Case EVENT_GADGETACTION
            Default
                ActivateGadget(hIrrlichtWindow)
                If EventID()=EVENT_KEYDOWN And EventData()=KEY_W
                    bWireFrame = Not bWireFrame
                    'ib3d_EntityFX(cube,EMF_WIREFRAME,bWireFrame)                    
                EndIf
        End Select
    End If
    
Wend

Now, launch the program and resize... WOOT WOOT ! IT WORKS !

That's it guys, ENJOY ! big_smile