本帖最后由 woshijiameizhou 于 2012-10-25 09:47 AM 编辑
抓图一般在一帧渲染完之后进行,可以从vsChannel::Subscriber派生一个类,比如常见的可以这样- class myApp : public vpApp, public vsChannel::Subscriber {... ...}
复制代码 通过以下这句添加一帧完成后的事件回调- channel->addSubscriber(vsChannel::EVENT_POST_DRAW, /*new出来的myApp*/);
复制代码 重写下面方法- virtual void notify(vsChannel::Event, const vsChannel *channel,vrDrawContext *context)
复制代码 实际上要精确控制时间间隔可能很难,可以通过帧索引来间接控制时间(比如间10帧抓图), notify里面大概可以这样写:
static long long index=0;
static vuField<vuImageFactory*> m_imageFactory = new vuImageFactory();
static vuField<uchar*,vuFieldTraitBinary> m_data=NULL;
if((index++)%10 == 0) {
int originX, originY, width, height;
channel->getVrChannel()->getViewport(&originX, &originY,&width, &height);
int numPixels = 3 * width * height;
if (m_data == NULL)
m_data = vuAllocArray<uchar>::malloc(numPixels);
else if (vuAllocArray<uchar>::getSize(m_data.get()) != numPixels)
m_data = vuAllocArray<uchar>::malloc(numPixels);
glReadPixels(originX, originY, width, height, GL_RGB,GL_UNSIGNED_BYTE, m_data.get());
vuImageUserBuffer image(m_data.get());
image.setDimensions(width, height);
image.setPixelType(vuImageBase::PixelType(vuImageBase::TYPE_UNSIGNED_BYTE,8,8,8,0));
char buf[256]; sprintf_s(buf, "%lld.rgb",index);
m_imageFactory->write(buf, &image);
}
我也是vp新手,代码也没有经过测试,仅供参考。
|