Skip to content

Commit

Permalink
Compatibility with Qt6.1.1 (MinGW) under Windows 10 established.
Browse files Browse the repository at this point in the history
Version 0.8.1
  • Loading branch information
Becker-Asano committed Jun 20, 2024
1 parent 04741e0 commit 8d496f0
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 56 deletions.
7 changes: 4 additions & 3 deletions WASABIGuiQt.pro
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@
#include($$_PRO_FILE_PWD_/WASABI-qwt-clone/qwt-code/qwt/qwtconfig.pri)
#QMAKEFEATURES += $$_PRO_FILE_PWD_/WASABI-qwt-clone/qwt-code/qwt
#QMAKEFEATURES += $$_PRO_FILE_PWD_/WASABIEngine
QT += core gui opengl network xml widgets
QT += core gui opengl network xml widgets openglwidgets
CONFIG += c++11
CONFIG += static

TARGET = WASABIGuiQt
TEMPLATE = app

DEPENDPATH += . $$_PRO_FILE_PWD_/WASABIEngine
INCLUDEPATH += $$_PRO_FILE_PWD_/WASABIEngine
CONFIG(release, debug|release) {
win32-g++:LIBS += -L"$$_PRO_FILE_PWD_/build-WASABIEngine/release" -lWASABIEngine -lopengl32 -lglu32
win32-g++:LIBS += -L"$$_PRO_FILE_PWD_/build-WASABIEngine-Desktop_Qt_6_1_1_MinGW_64_bit-Release/release" -lWASABIEngine -lopengl32 -lglu32

# On Mac, the debug and release folders are not automatically created
macx:LIBS += -L"$$_PRO_FILE_PWD_/build-WASABIEngine" -lWASABIEngine -lopengl32 -lglu32
}
CONFIG(debug, debug|release) {
win32-g++:LIBS += -L"$$_PRO_FILE_PWD_/build-WASABIEngine/debug" -lWASABIEngine -lopengl32 -lglu32
win32-g++:LIBS += -L"$$_PRO_FILE_PWD_/build-WASABIEngine-Desktop_Qt_6_1_1_MinGW_64_bit-Debug\debug" -lWASABIEngine -lopengl32 -lglu32

# On Mac, the debug and release folders are not automatically created
macx:LIBS += -L"$$_PRO_FILE_PWD_/build-WASABIEngine" -lWASABIEngine -lopengl32 -lglu32
Expand Down
82 changes: 69 additions & 13 deletions glPADWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#endif

GLPADWidget::GLPADWidget(QWidget *parent, WASABIQtWindow* window)
: QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
: QOpenGLWidget(parent)
{
xRot = 0;
yRot = 0;
Expand All @@ -62,6 +62,62 @@ GLPADWidget::~GLPADWidget()
{
}


/* for Qt6+
* from: https://stackoverflow.com/questions/28216001/how-to-render-text-with-qopenglwidget
*/
static void qt_save_gl_state()
{
glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);
glPushAttrib(GL_ALL_ATTRIB_BITS);
glMatrixMode(GL_TEXTURE);
glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();

glShadeModel(GL_FLAT);
glDisable(GL_CULL_FACE);
glDisable(GL_LIGHTING);
glDisable(GL_STENCIL_TEST);
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
}
static void qt_restore_gl_state()
{
glMatrixMode(GL_TEXTURE);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glPopAttrib();
glPopClientAttrib();
}
void GLPADWidget::renderText(double x, double y, const QString text)
{
GLdouble textPosX = x, textPosY = y;
// Retrieve last OpenGL color to use as a font color
GLdouble glColor[4];
glGetDoublev(GL_CURRENT_COLOR, glColor);
QColor fontColor = QColor(glColor[0]*255, glColor[1]*255,
glColor[2]*255, glColor[3]*255);
// Render text
QPainter painter(this);
//painter.translate(float(_shiftX),float(_shiftY)); //This is for my own mouse event (scaling)

painter.setPen(fontColor);
QFont f;
f.setPixelSize(10);
painter.setFont(f);
painter.drawText(textPosX, textPosY, text);
painter.end();
}

/* end for Qt6+ */
QSize GLPADWidget::minimumSizeHint() const
{
return QSize(50, 50);
Expand All @@ -86,7 +142,7 @@ void GLPADWidget::setXRotation( int angle)
if (angle != xRot) {
xRot = angle;
emit xRotationChanged(angle);
updateGL();
//updateGL();
}
}

Expand All @@ -96,7 +152,7 @@ void GLPADWidget::setYRotation( int angle)
if (angle != yRot) {
yRot = angle;
emit yRotationChanged(angle);
updateGL();
//updateGL();
}
}

Expand All @@ -106,13 +162,13 @@ void GLPADWidget::setZRotation( int angle)
if (angle != zRot) {
zRot = angle;
emit zRotationChanged(angle);
updateGL();
//updateGL();
}
}

void GLPADWidget::initializeGL()
{
qglClearColor(qtPurple.dark());
//qglClearColor(qtPurple);

/* remove back faces */
glDisable(GL_CULL_FACE);
Expand Down Expand Up @@ -154,9 +210,9 @@ void GLPADWidget::paintGL()
if (parentWindow && !parentWindow->showXYZ()) {
glPushMatrix();
glCallList( padSpace );
QGLWidget::renderText(120,0,0,"+A");
QGLWidget::renderText(0,120,0,"+P");
QGLWidget::renderText(0,0,120,"+D");
renderText(120,0,"+A");
renderText(0,120,"+P");
renderText(0,0,"+D");
glPopMatrix();
}

Expand Down Expand Up @@ -204,15 +260,15 @@ void GLPADWidget::paintGL()

glTranslatef(0, -10, 0);
glRotatef(180, 1.0f, 0.0f, 0.0f);
QGLWidget::renderText(0,0,0,ea->getName().c_str());
renderText(0,0,ea->getName().c_str());

glPopMatrix();
}

glPushMatrix();
QGLWidget::renderText(120,0,0,"X");
QGLWidget::renderText(0,120,0,"Y");
QGLWidget::renderText(0,0,120,"Z");
renderText(120,0,"X");
renderText(0,120,"Y");
renderText(0,0,"Z");
glPopMatrix();
glScalef((float) ea->EmoConPerson->xReg,
(float) ea->EmoConPerson->yReg, 1);
Expand All @@ -234,7 +290,7 @@ void GLPADWidget::paintGL()
glColor3f(0.8, 0.8, 0.8);
glCallList(padSphere);
glTranslatef(0, -10, 0);
QGLWidget::renderText(0,0,0,ea->getName().c_str());
renderText(0,0,ea->getName().c_str());
glPopMatrix();
}
glColor4fv(color);
Expand Down
6 changes: 4 additions & 2 deletions glPADWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
********************************************************************************/
#ifndef GLPADWIDGET_H
#define GLPADWIDGET_H
#include <QGLWidget>
#include <QOpenGLWidget>
#include "WASABIEngine.h"

class WASABIQtWindow;

class GLPADWidget : public QGLWidget
class GLPADWidget : public QOpenGLWidget
{
Q_OBJECT

Expand All @@ -56,6 +56,8 @@ public slots:
void resizeGL( int width, int height);
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
/* for Qt6+ */
void renderText(double x, double y, const QString text);

private:
int xRot;
Expand Down
Loading

0 comments on commit 8d496f0

Please sign in to comment.