wasm: hellogl2 screen is black

We need to reset the OpenGL state in paintGL for the drawing
to work,

Also, disable the dock/add window functionality as it does not
work on webassembly.

Change-Id: I480d944bc2029a07d5d49f0a85c3754fbc8cd53c
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
This commit is contained in:
Even Oscar Andersen 2024-06-25 11:51:47 +02:00
parent 04b8b61ce5
commit e40fdf19ab
4 changed files with 10 additions and 2 deletions

View File

@ -7,6 +7,7 @@
#include <QCoreApplication> #include <QCoreApplication>
#include <math.h> #include <math.h>
// Set from main
bool GLWidget::m_transparent = false; bool GLWidget::m_transparent = false;
GLWidget::GLWidget(QWidget *parent) GLWidget::GLWidget(QWidget *parent)
@ -209,9 +210,11 @@ void GLWidget::setupVertexAttribs()
void GLWidget::paintGL() void GLWidget::paintGL()
{ {
glClearColor(0, 0, 0, m_transparent ? 0 : 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
setupVertexAttribs();
m_world.setToIdentity(); m_world.setToIdentity();
m_world.rotate(180.0f - (m_xRot / 16.0f), 1, 0, 0); m_world.rotate(180.0f - (m_xRot / 16.0f), 1, 0, 0);

View File

@ -42,6 +42,7 @@ int main(int argc, char *argv[])
MainWindow mainWindow; MainWindow mainWindow;
// Note: Transparency does not work for wasm
GLWidget::setTransparent(parser.isSet(transparentOption)); GLWidget::setTransparent(parser.isSet(transparentOption));
if (GLWidget::isTransparent()) { if (GLWidget::isTransparent()) {
mainWindow.setAttribute(Qt::WA_TranslucentBackground); mainWindow.setAttribute(Qt::WA_TranslucentBackground);

View File

@ -11,12 +11,13 @@
MainWindow::MainWindow() MainWindow::MainWindow()
{ {
#ifndef Q_OS_WASM
QMenu *menuWindow = menuBar()->addMenu(tr("&Window")); QMenu *menuWindow = menuBar()->addMenu(tr("&Window"));
menuWindow->addAction(tr("Add new"), QKeySequence(Qt::CTRL | Qt::Key_N), menuWindow->addAction(tr("Add new"), QKeySequence(Qt::CTRL | Qt::Key_N),
this, &MainWindow::onAddNew); this, &MainWindow::onAddNew);
menuWindow->addAction(tr("Quit"), QKeySequence(Qt::CTRL | Qt::Key_Q), menuWindow->addAction(tr("Quit"), QKeySequence(Qt::CTRL | Qt::Key_Q),
qApp, QApplication::closeAllWindows); qApp, QApplication::closeAllWindows);
#endif
onAddNew(); onAddNew();
} }

View File

@ -45,10 +45,13 @@ Window::Window()
container->addWidget(zSlider); container->addWidget(zSlider);
mainLayout->addWidget(w); mainLayout->addWidget(w);
dockBtn = nullptr;
#ifndef Q_OS_WASM
dockBtn = new QPushButton(tr("Undock"), this); dockBtn = new QPushButton(tr("Undock"), this);
connect(dockBtn, &QPushButton::clicked, this, &Window::dockUndock); connect(dockBtn, &QPushButton::clicked, this, &Window::dockUndock);
mainLayout->addWidget(dockBtn); mainLayout->addWidget(dockBtn);
#endif
xSlider->setValue(15 * 16); xSlider->setValue(15 * 16);
ySlider->setValue(345 * 16); ySlider->setValue(345 * 16);
zSlider->setValue(0 * 16); zSlider->setValue(0 * 16);