Introduction to - PowerPoint PPT Presentation

About This Presentation
Title:

Introduction to

Description:

Title: PowerPoint Presentation Last modified by: skwong Created Date: 1/1/1601 12:00:00 AM Document presentation format: (4:3) Other titles – PowerPoint PPT presentation

Number of Views:22
Avg rating:3.0/5.0
Slides: 33
Provided by: peopleCs4
Category:

less

Transcript and Presenter's Notes

Title: Introduction to


1
Introduction to OGRE3D Programming Main Loop
1
1
2
Major part of call graph
BaseApplicationgo()
BaseApplicationsetup()
RootstartRendering()
RootrenderOneFrame()
Root_fireFrameStarted()
Root_fireFrameEnded()
Root_updateAllRenderTargets()
2
3
Main program

int main(int argc, char argv) BaseApplicatio
n MyGameApp new BaseApplication try
MyGameApp ?go() catch( Exception e )
return 1

4
The implementation of go()
virtual void BaseApplicationgo(void) if
(!setup()) return mRoot-gtstartRendering()
// clean up destroyScene()
5
The implementation of setup()
The function setup() instantiates mRoot, setups
resources, loads plugins, creates scene and
creates frame listener. mRoot new
OgreRoot(mPluginsCfg) setupResources()
bool carryOn configure() if (!carryOn)
return false chooseSceneManager()
createCamera() createViewports() createResour
ceListener() loadResources() createScene()
createFrameListener()
6
Major functions (1/3)
RootstartRendering() assert(mActiveRenderer ! 0) mActiveRenderer-gt_initRenderTargets() clearEventTimes() // Infinite loop, until broken out of by frame listeners // or break out by calling queueEndRendering() mQueuedEnd false while( !mQueuedEnd ) //Pump messages in all registered RenderWindow windows WindowEventUtilitiesmessagePump() if ( !renderOneFrame() ) break

7
Major functions (2/3)
bool RootrenderOneFrame(void) if( !_fireFrameStarted() ) return false _updateAllRenderTargets() return _fireFrameEnded() class myFrameListener public FrameListener public bool frameStarted (const FrameEvent evt) bool frameRenderingQueued( const FrameEvent evt) bool frameEnded (const FrameEvent evt) bool myFrameListenerframeStarted( const FrameEvent evt) // cool stuff to do before a frame is rendered return true //define frameRenderingQueued here bool myFrameListenerframeEnded( const FrameEvent evt) // cool stuff to do after a frame is rendered return true


8
bool Root_fireFrameStarted(FrameEvent evt)
  • OgreProfileBeginGroup("Frame", OGREPROF_GENERAL)
  • // Remove all marked listeners
  • // Tell all listeners
  • for ( i mFrameListeners.begin() i !
    mFrameListeners.end() i )
  • if ( !(i)?frameStarted(evt) )
  • return false
  • return true

9
bool Root_updateAllRenderTargets(void)
  • // update all targets but don't swap buffers
  • mActiveRenderer-gt_updateAllRenderTargets(false)
  • // give client app opportunity to use queued GPU
    time
  • bool ret _fireFrameRenderingQueued()
  • // This belongs here, as all render targets must
    be updated
  • // before events are triggered, otherwise targets
    could be
  • // mismatched. This could produce artifacts,
    e.g. with shadows.
  • return ret

10
bool Root_fireFrameRenderingQueued(FrameEvent
evt)
  • // Increment next frame number
  • mNextFrame
  • // Remove all marked listeners
  • // Tell all listeners
  • for ( i mFrameListeners.begin() i !
    mFrameListeners.end() i )
  • if ( !(i)-gtframeRenderingQueued(
    evt ) )
  • return false
  • return true

11
bool Root_fireFrameEnded(FrameEvent evt)
  • // Remove all marked listeners
  • // Tell all listeners
  • bool ret true
  • for ( i mFrameListeners.begin() i !
    mFrameListeners.end() i )
  • if ( !(i)-gtframeEnded(evt) )
  • ret false
  • break
  • // Tell buffer manager to free temp buffers used
    this frame
  • return ret

12
Remove all marked Listener
  • setltFrameListenergttypeiterator i
  • for ( i mRemovedFrameListeners.begin()
  • i ! mRemovedFrameListeners.end()
  • i)
  • mFrameListeners.erase(i)
  • mRemovedFrameListeners.clear()

13
Major functions (3/3)
bool myFrameListenerframeStarted(const
FrameEvent evt) if(mWindow-gtisClosed())
return false ... ... //Need to
capture/update each device mKeyboard-gtcapture()
mMouse-gtcapture() if( mJoy )
mJoy-gtcapture() ... ... handleKeyEvent(evt) h
andleMouseEvent(evt) ... ... ...
... ... ... return true
code for game management and update of game state based on FrameEvent evt.
14
Major part of call graph
GameApplicationgo()
GameApplicationsetup()
RootstartRendering()
RootrenderOneFrame()
Root_fireFrameStarted()
Root_fireFrameEnded()
Root_updateAllRenderTargets()
14
15
Frame listener
Frame listeners are the only way we can invoke
your own code during the Ogre render loop when
using the startRendering() method. A frame
listener is simply a class that implements the
FrameListener interface, and is just a callback
that allows OGRE to invoke our code at the
beginning and/or end of each.

16
Demo main_loop
Use ExampleApplication and ExampleFrameListener
In the main .cpp file, we have class
GameApplication public ExampleApplication publi
c GameApplication() void createScene()
GameApplication app new
GameApplication int main(int argc, char
argv) try app-gtgo() catch(
Exception e ) .
16

17
Object-Oriented Graphics Rendering Engine ( OGRE
3D) - The Main Program
18
FrameStarted
bool myFrameListenerframeStarted(const
FrameEvent evt) if(mWindow-gtisClosed())
return false . . . . . . //Need to
capture/update each device mKeyboard-gtcapture()
mMouse-gtcapture() if( mJoy )
mJoy-gtcapture() . . . . . . handleKeyEvent(evt)
handleMouseEvent(evt) . . . . .
. moveMainChar(evt) updateCreaturesAction(evt)
. . . . . . . . . . . . . . . . . . return
true
code for game management and update of game state based on FrameEvent evt.
19
moveMainChar
void moveMainChar(const FrameEvent
evt) mCameraNode-gtyaw(mRotX) // move
the head node along the camera viewing
direction const Quaternion q
mCameraNode-gtgetOrientation() mCameraNode-gtsetO
rientation(q) SceneNode node
mHeadNode-gtgetSceneNode() node-gtsetOrientation(
q) node-gttranslate( q(-mTranslateVector)
) // maintain the distance between the camera
and mHeadNode const Vector3 v3
node-gtgetPosition() Vector3 cv v3 Vector3
hv Vector3(0.0, 0.0, -1.0) hv
qhv float d0 -mCamerViewDistanceFromMainChar
float d1 30 mCameraNode-gtsetPosition(cv-
hvd0Vector3(0.0, d1, 0.0))
20
updateCreatureActions
void updateCreaturesAction(const FrameEvent
evt) if (mRobot) mRobot-gtcheckAlive(evt)
if (mRobot mHeadNode) mRobot-gtUpdateActi
on(evt, mHeadNode)
21
FrameEvent
namespace Ogre struct FrameEvent
/ Elapsed time in seconds since the last
event. This gives you time between
frame start frame end, and between
frame end and next frame start.
_at_remarks This may not be the
elapsed time but the average
elapsed time between recently fired events.
/ Real timeSinceLastEvent /
Elapsed time in seconds since the last event of
the same type, i.e. time for a
complete frame. _at_remarks
This may not be the elapsed time but the
average elapsed time between
recently fired events of the same type.
/ Real timeSinceLastFrame
22
Introduction to dynamic-link library (DLL)
  • On Windows
  • Microsofts implementation of shared library
  • File format same as for the Windows EXE files
  • Containing
  • Code
  • Data
  • Resources,
  • or in any combination

23
Symbol resolution and binding
  • Each function exported by a DLL is identified by
    a numeric ordinal and optionally a name
  • Functions can be imported from a DLL either by
    ordinal or by a name
  • The ordinal represents the position of the
    functions address pointer in the DLL Export
    Address table

24
Symbol resolution and binding
  • Ordinal subject to change
  • Names preserved across different Windows releases

25
Load-time dynamic linking
  • Use the information the linker placed in the file
    to locate the names of the DLLs that are used by
    the process
  • Fail to locate a required DLL
  • -gt terminate the process and report the error
  • Locate successfully -gt map the DLL into the
    virtual address space of the process

25
26
Load-time dynamic linking
  • Call a DLL function explicitly.
  • The application must be linked with the import
    library myMessage.lib.
  • extern "C" int __cdecl myMessage(LPWSTR)
  • // a function from a DLL
  • int main(VOID)
  • int Ret 1
  • Ret myMessage (LMessage\n)
  • return Ret

26
27
Explicit run-time linking
  • LoadLibrary (or LoadLibraryEx) explicitly load
    at run time
  • GetProcAddress lookup exported symbols by name
  • FreeLibrary unload the DLL

28
Example creating a DLL
ifdef __cplusplus // If used by C code, extern
"C" // we need to export the C interface
endif __declspec(dllexport) void
createSceneCreator() return static_castlt
void gt (new DemoApp) ifdef __cplusplus
endif
28
29
Module definition file
(.def) file a text file that contains
statements defining an executable (.exe) file or
dynamic-link library (DLL). Some
commands LIBRARY Specify the internal name of
the DLL EXPORTS Make one or more definitions
available as exports to other applications Syntax
of an export definition entrynameinternalname
_at_ordinalNONAME
29
30
Creating a DLLSetup module definition file
Projectgtproperties-gtLinker-gt input-gtmodule
definition file Content of sceneCreator.def LIB
RARY sceneCreator EXPORTS createSceneCreator
_at_1
30
31
Explicit run-time linking DLL
HINSTANCE hdll NULL typedef void
(pvFunctv)() pvFunctv sceneCreator hdll
LoadLibrary(TEXT("./dll/sceneCreator.dll")) if
(hdll) else return sceneCreator
(pvFunctv) (GetProcAddress( hdll,
"createSceneCreator" ) ) DemoApp app
static_castlt DemoApp gt ( sceneCreator() )
31
32
Useful links for DLL
  • About DLL
  • http//msdn2.microsoft.com/en-us/library/ms686912(
    VS.85).aspx
  • Module definition file http//msdn2.microsoft.com
    /en-us/library/ms923590.aspx

32
Write a Comment
User Comments (0)
About PowerShow.com