Posted on 2012-03-15 19:42
buf 阅读(412)
评论(0) 编辑 收藏 引用 所属分类:
Graphics
vega prime / vsg采用了Observer模式实现事件通知机制,以下是一个简单的例子:
#include <vsgu.h>
#include <vp.h>
#include <vpApp.h>
#include "vuAllocTracer.h"
vuAllocTracer tracer(true, true);
class EventViewer : public vpKernel::Subscriber
{
public:
~EventViewer() {}
void notify(vpKernel::Event evt, const vpKernel*)
{
if (evt == vpKernel::EVENT_ON_FIRST_FRAME)
{
printf("got first frame event from kernel\n");
}
}
};
int main(int argc, char *argv[])
{
// initialize vega prime
vp::initialize(argc, argv);
// initialize addition modules here
//vpModule::initializeModule(modulename);
// create a vpApp instance
vpApp *app = new vpApp;
EventViewer viewer;
app->getKernel()->addSubscriber(vpKernel::Event::EVENT_ON_FIRST_FRAME, &viewer);
// load acf file
if (argc <= 1)
app->define("vp_simple.acf");
else
app->define(argv[1]);
// configure my app
app->configure();
// runtime loop
app->run();
// unref my app instance
app->unref();
// shutdown vega prime
vp::shutdown();
return 0;
}