[QGIS-Developer] 3D Map Canvas Window is black
Aman Jaiswal
aj371923 at gmail.com
Thu Feb 27 00:31:57 PST 2025
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
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20250227/fb126522/attachment.htm>
More information about the QGIS-Developer
mailing list