OpenB3DMax + CEGUI


Job Open: Blitz3D/C++ DLL RPLidar Programming. View Job Posting
(Posted 11 months ago) RonTek

OpenB3DMax with CEGUI (bah.mod)

OpenB3D with CEGUI

issues with CEGUI mod building on NG so this is just plain vanilla white chocolate only.

Example openb3dcegui.bmx

Strict

Import BaH.CEGUIOpenGL
Import Openb3dmax.B3dglgraphics

AppTitle$ = "OpenB3DMax CEGUI Integration"

Local width%=DesktopWidth(),height%=DesktopHeight(),depth%=0,Mode%=2

Graphics3D 800,600,depth,Mode

Local cam:TCamera=CreateCamera()
PositionEntity cam,0,8,-10

' create separate camera for updating cube map - this allows us to avoid any confusion
Local cube_cam:TCamera=CreateCamera()
HideEntity cube_cam

Local Light:TLight=CreateLight(2)
RotateEntity Light,45,45,0
PositionEntity Light,10,10,0
LightRange Light,10

' load object we will apply cubemap to - the classic teapot
Local teapot:TMesh=LoadMesh("../media/teapot.b3d")
ScaleEntity teapot,5,5,5
PositionEntity teapot,0,6,10

' sky
Local sky:TMesh=CreateSphere(24)
ScaleEntity sky,500,500,500
FlipMesh sky
EntityFX sky,1
Local sky_tex:TTexture=LoadTexture("../media/sky.bmp")
EntityTexture sky,sky_tex

' create texture with color + cubic environment map
Local tex:TTexture=CreateTexture(256,256,1+128)

' apply cubic environment map to teapot
EntityTexture teapot,tex

Local blendmode%, cubemode%=1

' fps code
Local old_ms%=MilliSecs()
Local renders%, fps%

' Setup CEGUI

HideMouse

Init_CEGUI(New TCEOpenGLRenderer)

TCELogger.GetLogger().setLoggingLevel(LOG_INSANE)
TCELogger.GetLogger().setLogFilename("test.log")

initialiseDefaultResourceGroups()
initialiseResourceGroupDirectories()

TCESchemeManager.createScheme("WindowsLook.scheme")

    TCEFontManager.createFont("DejaVuSans-10.font")

        '  Font defaulting
        If TCEFontManager.isDefined("DejaVuSans-10") Then
            TCESystem.setDefaultFont("DejaVuSans-10")
        End If

TCESystem.setDefaultMouseCursor("WindowsLook", "MouseArrow")

Local Root:TCEWindow = TCEWindowManager.loadWindowLayout("test_01.layout")
TCESystem.setGUISheet(Root)

' coded button
Local button:TCEWindow = TCEWindowManager.CreateWindow("WindowsLook/Button", "button")
Root.addChild(button)

button.setText("Show")
button.setPosition(40, 100)
button.setSize(90, 20)
button.subscribeEvent(TCEPushButton.EventClicked, clicked)

' coded editbox
Local eb:TCEWindow = TCEWindowManager.CreateWindow("WindowsLook/Editbox", "editbox")
Root.addChild(eb)

eb.setText("Type here")
eb.setPosition(40, 130)
eb.setSize(180, 30)

' loaded window
Local window:TCEWindow = TCEWindowManager.getWindow("HelloWorldWindow")
window.subscribeEvent(TCEFrameWindow.EventCloseClicked, closed)
window.activate()

While Not KeyDown(KEY_ESCAPE)

    ' control camera
    MoveEntity cam,KeyDown(KEY_D)-KeyDown(KEY_A),0,KeyDown(KEY_W)-KeyDown(KEY_S)
    TurnEntity cam,KeyDown(KEY_DOWN)-KeyDown(KEY_UP),KeyDown(KEY_LEFT)-KeyDown(KEY_RIGHT),0

    ' change cube mode: specular, diffuse
    If KeyHit(KEY_M)
        cubemode=cubemode+1
        If cubemode=3 Then cubemode=1
        SetCubeMode tex,cubemode
    EndIf

    ' alpha blending
    If KeyHit(KEY_B) Then blendmode=Not blendmode
    If blendmode=0 Then EntityAlpha teapot,1.0
    If blendmode=1 Then EntityAlpha teapot,0.7

        TurnEntity teapot,0,0.5,-0.1

    ' hide main camera before updating cube map - we don't need to render it when cube_cam is rendered
    HideEntity cam

    UpdateCubemap(tex,cube_cam,teapot)

    ' show main camera again
    ShowEntity cam

    RenderWorld

    ' calculate fps
    renders=renders+1
    If MilliSecs()-old_ms>=1000
        old_ms=MilliSecs()
        fps=renders
        renders=0
    EndIf

    ' Max2D/CEGUI stuff
    BeginMax2D()    
    TCEEvent.mouseEvents(MouseX(), MouseY(), MouseZ())
    TCESystem.renderGUI()
    EndMax2D()

    Flip

Wend
End

Function UpdateCubemap(tex:TTexture,Camera:TCamera,Entity:TEntity)

    Local tex_sz%=TextureWidth(tex)

    ' show the camera we have specifically created for updating the cubemap
    ShowEntity Camera

    ' hide entity that will have cubemap applied to it.
    ' This is so we can get cubemap from its position, without it blocking the view
    HideEntity Entity

    ' position camera where the entity is - this is where we will be rendering views from for cubemap
    PositionEntity Camera,EntityX#(Entity),EntityY#(Entity),EntityZ#(Entity)

    CameraClsMode Camera,False,True

    ' set the camera's viewport so it is the same size as our texture
    ' - so we can fit entire screen contents into texture
    CameraViewport Camera,0,0,tex_sz,tex_sz

    ' update cubemap - Blitz3D uses CopyRect 0,0,tex_sz,tex_sz,0,0,BackBuffer(),TextureBuffer(tex)

    ' do left view  
    SetCubeFace tex,0
    RotateEntity Camera,0,90,0
    RenderWorld
    BackBufferToTex tex

    ' do forward view
    SetCubeFace tex,1
    RotateEntity Camera,0,0,0
    RenderWorld
    BackBufferToTex tex

    ' do right view 
    SetCubeFace tex,2
    RotateEntity Camera,0,-90,0
    RenderWorld
    BackBufferToTex tex

    ' do backward view
    SetCubeFace tex,3
    RotateEntity Camera,0,180,0
    RenderWorld
    BackBufferToTex tex

    ' do up view
    SetCubeFace tex,4
    RotateEntity Camera,-90,0,0
    RenderWorld
    BackBufferToTex tex

    ' do down view
    SetCubeFace tex,5
    RotateEntity Camera,90,0,0
    RenderWorld
    BackBufferToTex tex

    ' show entity again
    ShowEntity Entity

    ' hide the cubemap camera
    HideEntity Camera

End Function

' CEGUI Functions

Function closed:Int(args:TCEEventArgs)
    TCEWindow(args.owner).hide()
    Return True
End Function

Function clicked:Int(args:TCEEventArgs)
    Local window:TCEWindow = TCEWindowManager.getWindow("HelloWorldWindow")
    window.show()
    Return True
End Function

' a custom logger
Type CustomLogger Extends TCECustomLogger

    ' does nothing - we are outputting to the debuglog
    Method setLogFilename(filename:String, append:Int = False)
    End Method

    ' called for *every* event
    Method logEvent(message:String, level:Int = LOG_STANDARD)   
        If getLoggingLevel() >= level Then
            DebugLog "EVENT : " + message
        End If
    End Method

End Type

Function getDataPathPrefix:String()
    Return "../datafiles"
End Function

Function initialiseResourceGroupDirectories()
    ' initialise the required dirs for the DefaultResourceProvider
    Local rp:TCEDefaultResourceProvider = TCEDefaultResourceProvider(TCESystem.getResourceProvider())

    Local dataPathPrefix:String = getDataPathPrefix()

    ' for each resource type, set a resource group directory
    rp.setResourceGroupDirectory("schemes", dataPathPrefix + "/schemes/")
    rp.setResourceGroupDirectory("imagesets", dataPathPrefix + "/imagesets/")
    rp.setResourceGroupDirectory("fonts", dataPathPrefix + "/fonts/")
    rp.setResourceGroupDirectory("layouts", dataPathPrefix + "/layouts/")
    rp.setResourceGroupDirectory("looknfeels", dataPathPrefix + "/looknfeel/")
    rp.setResourceGroupDirectory("lua_scripts", dataPathPrefix + "/lua_scripts/")
    rp.setResourceGroupDirectory("schemas", dataPathPrefix + "/xml_schemas/")
End Function

Function initialiseDefaultResourceGroups()
    ' set the default resource groups to be used
    TCEImageset.setDefaultResourceGroup("imagesets")
    TCEFont.setDefaultResourceGroup("fonts")
    TCEScheme.setDefaultResourceGroup("schemes")
    TCEWidgetLookManager.setDefaultResourceGroup("looknfeels")
    TCEWindowManager.setDefaultResourceGroup("layouts")
    'TCEScriptModule.setDefaultResourceGroup("lua_scripts")
End Function
3d blitzmax gui
(Posted 11 months ago)

Wow, nice! So this looks like an easy way to get a Windows skin, as IfsoGUI is lacking that.

I didn't realize CEGUI was in working order.

(Posted 11 months ago)

Thanks Mark! Yes, did some test back then with vanilla and fortunately it does work without issues so far. For OpenB3D integration, you just need to render it between Begin/EndMax2D method that's all.

(Posted 11 months ago)

posted an entry on CEGUI User Projects.

http://cegui.org.uk/forum/viewtopic.php?f=4&t=7458

(Posted 11 months ago)

Ah thanks, can I ask you for the example code to this pic?

I always felt CEGUI was a bit cumbersome, like too big and complex, but how do you find it?

Cheers.

(Posted 11 months ago)

Sure thing Mark, just updated the post now with the example source. CEGUI feels a bit like that from the start, but once you get a hang of it, it's actually easy (kudos to Brucey's mod work) and really an awesome gui kit that has been around along with early 3D engine and stuff. Also a popular choice among indie devs.. just found out recently that TorchLight (Ogre3D) and Life Is Feudal (Torque3D) uses this nifty library.

(Posted 11 months ago)

Great, thanks for the code Ron! I'll definitely be adding a CEGUI sample to Openb3dmax now. Good to have another GUI option. Yes, thanks to Brucey.

(Posted 11 months ago)

that's awesome Mark!.Yes and it would be nice if CEGUI works with NG as well, but vanilla build should be fine for now.

Reply To Topic

Please log in to reply