Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Want to make a textured semi-transparent sphere in Qt 3D. Neither correct texture mapping, nor alpha channel...
Forum Update on Monday, May 27th 2025

Want to make a textured semi-transparent sphere in Qt 3D. Neither correct texture mapping, nor alpha channel...

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 727 Views
  • 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.
  • kitekatK Offline
    kitekatK Offline
    kitekat
    wrote on last edited by
    #1

    Hi all! I want to draw a semi-transparent textured sphere in Qt 3D (to plot some kind of colormap on it).

    I'm trying to draw a sphere and add a texture. The texture fits good on some regions of the sphere, but on the poligons near its poles it becomes sizzled.

    Can you tell me, what's my mistake?

    Here's my code that tries to draw a sphere:

    #include <QApplication>
    
    #include <Qt3DExtras/Qt3DWindow>
    #include <Qt3DCore/QEntity>
    #include <Qt3DExtras/QSphereMesh>
    #include <Qt3DExtras/QTextureMaterial>
    #include <Qt3DExtras/QOrbitCameraController>
    #include <Qt3DRender/QTexture>
    #include <QPhongAlphaMaterial>
    #include <qt3dwindow.h>
    #include <QtWidgets/QWidget>
    
    #include <qcamera.h>
    #include <qforwardrenderer.h>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
    
        Qt3DExtras::Qt3DWindow* m_view = new Qt3DExtras::Qt3DWindow();
        QWidget* container = QWidget::createWindowContainer(m_view);
        container->show();
    
        Qt3DCore::QEntity* m_rootEntity = new Qt3DCore::QEntity();
        m_view->setRootEntity(m_rootEntity);
        m_view->defaultFrameGraph()->setClearColor(QColor(QRgb(0x4d4d4f)));
    
        // let's make a sphere
        Qt3DCore::QEntity* m_sphereEntity = new Qt3DCore::QEntity(m_rootEntity);
        Qt3DExtras::QSphereMesh* m_sphereMesh = new Qt3DExtras::QSphereMesh();
        m_sphereMesh->setRadius(12.);
        m_sphereEntity->addComponent(m_sphereMesh);
    
        // and glue some texture onto our sphere
        Qt3DRender::QTextureLoader *loader = new Qt3DRender::QTextureLoader(m_sphereEntity);
        Qt3DExtras::QTextureMaterial *material = new Qt3DExtras::QTextureMaterial(m_sphereEntity);
        loader->setSource(QUrl::fromLocalFile(a.applicationDirPath() + QStringLiteral("/temp1.png")));
        material->setTexture(loader);
        m_sphereEntity->addComponent(material);
    
    
        // initialise camera
    
        Qt3DRender::QCamera *camera = m_view->camera();
        camera->lens()->setPerspectiveProjection(45.0, 16.0 / 9.0, 0.1, 1000.0);
        camera->setPosition(QVector3D(0.0, 0.0, 40.0));
        camera->setViewCenter(QVector3D(0.0, 0.0, 0.0));
    
        // For camera controls.
        Qt3DExtras::QOrbitCameraController *camController = new Qt3DExtras::QOrbitCameraController(m_rootEntity);
        camController->setLinearSpeed(50.0);
        camController->setLookSpeed(180.0);
        camController->setCamera(camera);
    
    
        return a.exec();
    }
    

    Here's the temp1.png (the texture of colormap):
    0_1524001087326_temp1.png

    And here's the screenshot of my badly textured sphere:

    0_1524001227642_2018-04-18_00-39-03.png

    P.S. Also, can you tell me, is there a way to add an alpha channel to my textured material? It can be extremely useful for me.

    1 Reply Last reply
    0
    • ademmlerA Offline
      ademmlerA Offline
      ademmler
      wrote on last edited by
      #2

      @kitekat I try to run your example - but my texture stays dark.
      I have applied my own image. Have you ever git it working?

      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