Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 软件时空 > 软件相关 > 在qt中实现offscreen rendering
【标  题】:在qt中实现offscreen rendering
【关键字】:qt,offscreen,rendering
【来  源】:http://blog.chinaunix.net/article.php?articleId=48830&blogId=8650

在qt中实现offscreen rendering

Your Ad Here

1

code:

QGLFormat format;
QGLContext context(format,&pixmap);
QPainter painter;
painter.begin(context.device());
painter.setMatrix( _viewMatrix , false);
painter.drawImage(0,0,*_image,hpos,vpos);
painter.end();

cons: the context.device() returns the
pixmap so the rendering is allways done using
the software raster engine.

 Qt 4.1 will most likely have some
improvements in that area.

2.

via QGLWidget::renderPixmap().
Hardware accelerate can be achieved.

cons:

Since renderPixmap() seems to create an entirely new context each time, all
 texture IDs etc. are gone and  have to create the textures (from image
files) over and over again.

to solve :

QGLContext::create ( const QGLContext * shareContext = 0 )   [virtual]

Create the first one. Create the others, passing in the first to
create. It will share ALL resources -- textures, display lists and arrays.

Note that this is NOT guaranteed to work, because context sharing is
an extension not a baseline feature of OpenGL.

If "isSharing()" returns false, it failed.

This method will create a pixmap and a temporary QGLContext to render
on the pixmap. It will then call initializeGL(), resizeGL(), and
paintGL() on this context. Finally, the widget's original GL context is
restored.


Usually you allocate textures and display lists from within the
initializeGL() which is normally called only once.

Now when you render offscreen with renderPixmap() then initializeGL() is
called again. So you have to make sure that you don't re-create your
textures IF 'useContext' is set to TRUE (if it is set to FALSE, then you
have to, off course).

Note also that Qt TRIES to share the context, but it's not guaranteed to
work, as someone already mentioned (since it's an extension of OpenGL,
not a requirement).

The crucial thing off course here is how to find out in initializeGL()
whether the context is shared or not (that is whether renderPixmap()'s
argument 'useContext' was set to TRUE and succeeded). You may try with
QGLWidget::isSharing() if this gives meaningful results at this point.

So you would end up with something like this:

void MyGLWidget::initializeGL()
{
   ...
   if (this->isSharing() == false)
   {
     this->createMyTexturesAndDisplayLists();
   }
   ...
}

void MyGLWidget::paintGL()
{
   ...
   glCallList (mySharedListIDWhichIsValidForOnscreenAndOffscreen);
   ...
}

SwitchTower: Automating Application Deployment:【上一篇】
adore(linux.rootkit):【下一篇】
【相关文章】
  • Qt不支持菱形继承
  • Qt中的openGL overlay
  • 宽字符支持(linux,MinGW,Qt)
  • kdeQt中文显示问题
  • 第一个简单的QT程序
  • Installing Qt/Windows
  • QT Windows developing enviroment Building
  • QT 一起学(一) Hello World 全攻略
  • QT一起学(二) 基本程序框架
  • 解决make xconfig出现的QT没安装问题。
  • 【随机文章】
  • 深入了解微软个人服务器PWS之四
  • 网页签名小程序
  • [转载]总结:C++与Fortran的混合编程问题
  • c语言获取本机ip地址
  • MS SQL Server 2000 的版本
  • White Paper Cisco快速转发 (CEF)
  • 传奇源码分析-客户端(传奇2和3 文件格式分析比较)
  • 软件破解:关于时间限制---方法
  • 光+以太网:宽带城域网趋势
  • libd在HP_UX11.11上安装oracle9.2的文档
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 软讯网络 All Rigths Reserved.