Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. Using qt widgets as texture in 3D
Forum Updated to NodeBB v4.3 + New Features

Using qt widgets as texture in 3D

Scheduled Pinned Locked Moved Game Development
3 Posts 3 Posters 4.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    belab
    wrote on last edited by
    #1

    Inspired by the wolfenqt demo with the browser walls I wanted to embed widgets into a game with min. effort using qt for the game ui to prevent from writing an own ui framework and getting all the comfort of qt. Here are my essentials so far:

    • design ui (of course with qtdesigner)
    • create 3d geometries for in game ui, planes, spheres, whatever...
    • render widgets to geometry textures
    • pass input events (mouse, key) to 3d widgets and ray picking using mapped texture coords
      Code:
      @
      widget = new Form(0, this); // ui from designer
      this->setMouseTracking(true);
      scene = new QGraphicsScene;
      scene->addWidget(widget);
      // connect to ui updates
      connect( scene, SIGNAL(changed(const QList<QRectF>&)), this, SLOT( updateTexture(const QList<QRectF>&)) );
      .
      .
      void GlWidget::updateTexture( const QList<QRectF>& )
      {
      QPainter painter( &(cube.pixmap) );
      scene->render( &painter ); // render ui updates to texture
      cube.texture = bindTexture(cube.pixmap);
      updateGL();
      }
      void GlWidget::mouseMoveEvent(QMouseEvent *event)
      {
      QVector3D rayOrg;
      QVector3D rayDir;
      getMousePickRay(event->localPos(), rayOrg, rayDir);
      QVector2D texCoords;
      if( cube.intersect(rayOrg, rayDir, texCoords))
      {
      QPointF scenePos(texCoords.x()*widget->width(), texCoords.y()*widget->height());
      QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseMove);
      mouseEvent.setWidget(this);
      mouseEvent.setScenePos(scenePos);
      mouseEvent.setLastScenePos(scenePos);
      mouseEvent.setAccepted(false);
      QApplication::sendEvent( scene, &mouseEvent );
      }
      .
      .
      .
      @
      I wrote a small demo on top of the simple qt opengl texture mapping example with putting it all together while keeping it small.
      https://github.com/belab/widgetTo3dTexture
      !https://raw.github.com/belab/widgetTo3dTexture/master/snapshot1.png(Snapshot)!
    1 Reply Last reply
    0
    • S Offline
      S Offline
      sl.sy.ifm
      wrote on last edited by
      #2

      btw. OpenSceneGraph offers some similar integration, but I'm not sure how good it really works ... I only played around with some of there demos/examples about qtwidgets in 3d ...
      ... but as OSG isn't really small (and has some "special" concepts), it's probably a nice idea to have something more lightweight like you did ...

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jiangcaiyang
        wrote on last edited by
        #3

        Great work! Thank you for sharing. This inspires me with an interesting idea.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved