a template for using ogre and cegui
Posted: Mon Mar 02, 2009 12:25 am
I am a newbie who has struggled for sometime to use 3d in purebasic.
At last i have started to get things working. To help others I have put together this little rough template of code in the hope it will help other newbies.( it has been put together by copying snips of code from all over these forums, and from the game "contact", many thanks to that author whose name I do not know)
This code works in fullscreen and windowed mode.
It loads a mesh and allows the display of on screen text.
At last i have started to get things working. To help others I have put together this little rough template of code in the hope it will help other newbies.( it has been put together by copying snips of code from all over these forums, and from the game "contact", many thanks to that author whose name I do not know)
This code works in fullscreen and windowed mode.
It loads a mesh and allows the display of on screen text.
Code: Select all
; purebasic 4.30(x86)
;- Initialization
Global FullScreen.b
Result = MessageRequester("find screen requirements!","Full Screen ?",#PB_MessageRequester_YesNo)
If Result = #PB_MessageRequester_Yes
FullScreen=#True
Else
FullScreen=#False
EndIf
If InitEngine3D() = 0
MessageRequester( "Error" , "Can't initialize 3D, check if engine3D.dll is available" , 0 )
End
ElseIf InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
MessageRequester( "Error" , "Can't find DirectX 7.0 or above" , 0 )
End
EndIf
;cegui stuff
Add3DArchive("GUI\", #PB_3DArchive_FileSystem)
Add3DArchive("GUI\schemes", #PB_3DArchive_FileSystem)
Add3DArchive("GUI\imagesets", #PB_3DArchive_FileSystem)
Add3DArchive("GUI\fonts", #PB_3DArchive_FileSystem)
Add3DArchive("GUI\looknfeel", #PB_3DArchive_FileSystem)
Add3DArchive("GUI\layouts", #PB_3DArchive_FileSystem)
;meshstuff
Add3DArchive("mesh", #PB_3DArchive_FileSystem)
Add3DArchive("Cube", #PB_3DArchive_FileSystem)
If Fullscreen = #True
OpenScreen(800,600,32,"a sort of 3d template!")
Else
OpenWindow(0,0, 0, 800 , 600 ,"a sort of 3d template!",#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0),0,0, 640 , 480,0,0,0)
EndIf
Enumeration 2
#Window3D
#Score
#Camera
#thing
EndEnumeration
; Initialization
Global mouseHidden.b
Global mousePosX.l,movex.l,mousePosY.l,moveY.l,moveZ.l
Global score.l, oldScore.l, bestScore.l
Global selectedEntity.l,selectedCylinder.l,oldSelected.l
Global num.l, i.l
EnableExplicit
;- ------ Main code ------
CreateCamera(1, 0 , 0, 100 , 100) ; note you have to create a camera so you can even see gui
CameraLocate(1, 0, 200, -1300)
CameraLookAt(1, 0, 0, 0)
;- Light
AmbientColor(RGB(255,255,255))
CreateLight(0,RGB(255,255,255),0,0,0)
;-Window3D
OpenWindow3D(#Window3D, 0, 0, 600, 50, "Infos",#PB_Window_BorderLess)
TextGadget3D(#Score, 1, 30, 600, 25, "Score : 0")
ShowGUI(220,#True)
;Parse3DScripts()
; load a mesh here if we wished
LoadMesh(0, "newcube.mesh")
CreateMaterial(1, LoadTexture(1, "tv1.JPG"))
CreateEntity(#thing, MeshID(0), MaterialID(1))
EntityLocate(#thing, 0, 0, 0)
ResizeEntity(#thing, 60, 60, 60)
HideEntity(#thing, 0)
RenderWorld()
; show bounding box
WorldDebug(#PB_World_DebugEntity)
;particle system
LoadTexture(0, "Flare.png")
CreateMaterial(0, TextureID(0))
DisableMaterialLighting(0, 1)
MaterialBlendingMode (0, 2)
;
CreateParticleEmitter(1, 10, 1, 1, 0)
ParticleMaterial (1, MaterialID(0))
ParticleTimeToLive (1, 2, 2)
ParticleEmissionRate(1, 20)
ParticleSize (1, 30, 30)
ParticleColorRange (1, RGB(255,255,0), RGB(0,255,0))
MoveParticleEmitter(1, -50, 0, 0)
;create a second camera
CreateCamera(#Camera, 75, 75, 25, 25) ; Front camera
CameraLocate(#Camera, 0, 200, -1300)
CameraLookAt(#Camera, 0, 0, 0)
;- Main loop
Repeat
score = score + 1
If FullScreen = #False
;this is only needed for the windowed app
While WindowEvent()
Delay(2)
Wend
EndIf
;- Get mouse movements
If ExamineMouse()
movex=MouseDeltaX():movey=MouseDeltaY()
mousePosX+movex:mousePosY+moveY
EndIf
; If mouse was hidden, show it and update text
InputEvent3D(mousePosX, mousePosY, 0, "")
If mouseHidden=#True
mouseHidden=#False
ShowGUI(220,#True)
SetGadgetText3D(#Score,"my Score: "+Str(score) + " (Record: "+Str(bestScore)+")")
EndIf
;- Keyboard
If ExamineKeyboard()
; what ever keyboard stuff here
EndIf
; rotate the mesh
RotateEntity(#thing,0,0,0.1,#PB_Relative)
If score > oldscore
oldscore+1
SetGadgetText3D(#Score,"Score is : "+Str(oldScore))
EndIf
; information
SetWindowTitle3D(#Window3D, "text with 3d! ("+Str(CountRenderedTriangles()) + " polys, " + Str(Engine3DFrameRate(#PB_Engine3D_Average)) + " FPS)")
; Show it all
RenderWorld()
; Flip buffers to avoid tearing
FlipBuffers()
;
Until KeyboardPushed(#PB_Key_Escape)
End