[QGIS-Developer] 3D Map Canvas Window is black
Martin Dobias
wonder.sk at gmail.com
Mon Mar 3 02:23:45 PST 2025
Hi Aman
I would suggest that you try running the 3D sandbox first - it is a small
test app that takes a QGIS project and shows it in a 3D canvas:
https://github.com/qgis/QGIS/blob/master/tests/src/3d/sandbox/qgis_3d_sandbox.cpp
It is small amount of code, so it should be easy to study, and hopefully it
will help you to identify issues in your code...
Cheers
Martin
On Thu, Feb 27, 2025 at 9:32 AM Aman Jaiswal via QGIS-Developer <
qgis-developer at lists.osgeo.org> wrote:
> Hello,
> I am using QGIS 3.42 with Qt5 cpp.
> While loading qgs3dmapcanvas i got black screen. Can you suggest to
> resolve.
> Here is the code
> MainWindow::MainWindow(QWidget *parent)
> : QMainWindow(parent)
> {
> // Set up the main window
> setWindowTitle("QGIS 3D Map Example");
> resize(800, 600);
>
> // Set OpenGL version to 4.2 (or higher)
> QSurfaceFormat format;
> format.setVersion(4, 2); // Request OpenGL 4.2
> format.setProfile(QSurfaceFormat::CoreProfile);
> format.setOption(QSurfaceFormat::DebugContext);
> QSurfaceFormat::setDefaultFormat(format);
>
> qDebug() << "OpenGL Version:" << format.version();
>
> // Load the TIFF file
> QString tiffFilePath =
> "/home/aman/Downloads/Data_Developing3d/Data_Developing3d/DEM.tif";
> rasterLayer = new QgsRasterLayer(tiffFilePath, "TIFF Layer");
> if (!rasterLayer->isValid()) {
> QMessageBox::warning(this, tr("Warning"), tr("Failed to load TIFF
> file."));
> return;
> } else {
> qDebug() << "TIFF file loaded successfully.";
> }
>
> // Set up 2D map canvas
> mapCanvas = new QgsMapCanvas(this);
> mapCanvas->setExtent(rasterLayer->extent());
> mapCanvas->setLayers(QList<QgsMapLayer *>() << rasterLayer);
> setCentralWidget(mapCanvas);
>
> // Set up 3D map settings
> map3DSettings = new Qgs3DMapSettings;
> map3DSettings->setLayers(QList<QgsMapLayer *>() << rasterLayer);
> map3DSettings->setCrs(QgsCoordinateReferenceSystem("EPSG:4326"));
> map3DSettings->setExtent(rasterLayer->extent());
>
> // Set up 3D map canvas
> map3DCanvas = new Qgs3DMapCanvas();
> map3DCanvas->setMapSettings(map3DSettings);
> map3DCanvas->resize(800, 600);
> // map3DCanvas->setParent(this); // Ensure the canvas has a parent
> map3DCanvas->show();
> // Add the 3D canvas to a container widget
> }
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20250303/da10ff67/attachment.htm>
More information about the QGIS-Developer
mailing list