How does Qt3D support 2D overlay?
-
Qt3D, the next inspiring module in Qt, will be incorporated in incoming Qt5.3.
I try it in advance, and want to know anything about how 2D overlay's support over Qt3D. -
I did not find a way to create a 2D overlay over a OpenGL view so i had to create my own. It's fairly simple to do with a textured quad. I setup a quad and then create a GL texture map from the image created via a QPainter.
To create the texture from the painter use something along these lines...
@QPainter painter;
QImage the_image( 100, 100, QImage::Format_ARGB32 );
QRect dest_rect( 0, 0, 100, 100 );painter.begin( &the_image );
painter.setRenderHints( QPainter::Antialiasing | QPainter::HighQualityAntialiasing );
painter.fillRect( dest_rect, QColor( 162, 190, 255) );
painter.setPen( QPen( Qt::black, 0 ) );
painter.drawText( dest_rect, Qt::AlignCenter, "Hello" );
painter.end();QImage overlay_image = QGLWidget::convertToGLFormat( the_image );
glGenTextures( 1, &tid );
glBindTexture( GL_TEXTURE_2D, tid );
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA,
overlay_image.width(), overlay_image.height(), 0,
GL_RGBA, GL_UNSIGNED_BYTE, overlay_image.bits() );
@ -
怎么得到这个模块?
-
Well, I am exploring through source code to find its internal mechanism inside Qt3D. Progress has been quite slow because of my current work. But I believe that some day in the future, this problem will be resolved.
As for you scoobydoo, your code shows an easy example of using QPainter against raw OpenGL functionality. But a more advanced integration would be that we can do overlays using Qt Graphics-View framework and Qt OpenGL module, moreover, shaders or something like that are supported. "A blog":http://blog.csdn.net/gamesdev/article/details/12073065 shows my progress a few months ago.
[quote author="ecitjiaojiao" date="1387336385"]怎么得到这个模块?[/quote][quote author="scoobydoo" date="1387332041"]I did not find a way to create a 2D overlay over a OpenGL view so i had to create my own. It's fairly simple to do with a textured quad. I setup a quad and then create a GL texture map from the image created via a QPainter.
To create the texture from the painter use something along these lines...
@QPainter painter;
QImage the_image( 100, 100, QImage::Format_ARGB32 );
QRect dest_rect( 0, 0, 100, 100 );painter.begin( &the_image );
painter.setRenderHints( QPainter::Antialiasing | QPainter::HighQualityAntialiasing );
painter.fillRect( dest_rect, QColor( 162, 190, 255) );
painter.setPen( QPen( Qt::black, 0 ) );
painter.drawText( dest_rect, Qt::AlignCenter, "Hello" );
painter.end();QImage overlay_image = QGLWidget::convertToGLFormat( the_image );
glGenTextures( 1, &tid );
glBindTexture( GL_TEXTURE_2D, tid );
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA,
overlay_image.width(), overlay_image.height(), 0,
GL_RGBA, GL_UNSIGNED_BYTE, overlay_image.bits() );
@
[/quote]