aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src-qt5/src-glwidgets/gltest/main.cpp16
-rwxr-xr-xsrc-qt5/src-glwidgets/gltest/testbin58021 -> 59456 bytes
-rw-r--r--src-qt5/src-glwidgets/glw-base.cpp55
-rw-r--r--src-qt5/src-glwidgets/glw-base.h4
-rw-r--r--src-qt5/src-glwidgets/glw-widget.cpp12
-rw-r--r--src-qt5/src-glwidgets/glw-widget.h4
6 files changed, 63 insertions, 28 deletions
diff --git a/src-qt5/src-glwidgets/gltest/main.cpp b/src-qt5/src-glwidgets/gltest/main.cpp
index 972c4225..b303cb6b 100644
--- a/src-qt5/src-glwidgets/gltest/main.cpp
+++ b/src-qt5/src-glwidgets/gltest/main.cpp
@@ -2,7 +2,6 @@
#include <QApplication>
#include <QTimer>
#include <QColor>
-#include <QPushButton>
#include <QPropertyAnimation>
#include "../glw-base.h"
#include "../glw-widget.h"
@@ -10,11 +9,18 @@
#include "colorchange.h"
int main(int argc, char** argv){
+
+ QSurfaceFormat fmt;
+ fmt.setRenderableType(QSurfaceFormat::OpenGL); //OpenGL, OpenGLES, OpenVG
+ fmt.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
+ QSurfaceFormat::setDefaultFormat(fmt);
+
QApplication A(argc,argv);
+
qDebug() << "Creating base widget";
GLW_Base base;
qDebug() << "Resize base widget";
- base.resize(200,200);
+ base.resize(1024,768);
qDebug() << "Create Other widgets";
GLW_Widget wgt1(&base);
wgt1.setGLBase(&base);
@@ -28,11 +34,11 @@ int main(int argc, char** argv){
anim.setPropertyName("geometry");
//anim.setStartValue(QRect(-50,-50,50,50));
//anim.setEndValue(QRect(200,200,50,50));
- anim.setStartValue(QRect(100,100,0,0));
- anim.setEndValue(QRect(0,0,200,200));
+ anim.setStartValue(QRect(base.width()/2,base.height()/2,0,0));
+ anim.setEndValue(QRect(0,0,base.width(),base.height()));
anim.setDuration(1500);
anim.setLoopCount(-1);
- //anim.start();
+ anim.start();
/*QPushButton but(&base);
but.setText("button");
but.setGeometry(100,100,50,50);
diff --git a/src-qt5/src-glwidgets/gltest/test b/src-qt5/src-glwidgets/gltest/test
index cf9d2c31..85760654 100755
--- a/src-qt5/src-glwidgets/gltest/test
+++ b/src-qt5/src-glwidgets/gltest/test
Binary files differ
diff --git a/src-qt5/src-glwidgets/glw-base.cpp b/src-qt5/src-glwidgets/glw-base.cpp
index d4279c61..ef54606b 100644
--- a/src-qt5/src-glwidgets/glw-base.cpp
+++ b/src-qt5/src-glwidgets/glw-base.cpp
@@ -6,10 +6,17 @@
//===========================================
#include "glw-base.h"
#include "glw-widget.h"
+#include <QPaintEngine>
+#include <QDebug>
+#include <QOpenGLContext>
+#include <QOpenGLFunctions>
+#include <QOpenGLPaintDevice>
GLW_Base::GLW_Base(QWidget *parent, Qt::WindowFlags f) : QOpenGLWidget(parent,f){
bg_color = QColor(Qt::black);
mouse_over_child = 0;
+ qDebug() << "Canvas supports threaded OpenGL:" << this->context()->supportsThreadedOpenGL();
+ qDebug() << " - globally:" << QOpenGLContext::globalShareContext()->supportsThreadedOpenGL();
}
GLW_Base::~GLW_Base(){
@@ -30,11 +37,11 @@ void GLW_Base::setBackgroundColor(QColor color){
void GLW_Base::setBackground(QRect geom, QImage img){
QPainter P(&bg_img);
P.drawImage(geom, img);
- this->update();
+ this->update(geom);
}
void GLW_Base::repaintArea(QRect rect){
- paintEvent(new QPaintEvent(rect));
+ this->update(rect);
}
void GLW_Base::setMouseOverWidget(QWidget *child){
@@ -55,26 +62,46 @@ void GLW_Base::resizeEvent(QResizeEvent *ev){
emit BaseResized();
}
-void GLW_Base::paintEvent(QPaintEvent *ev){
- QStylePainter painter(this);
- painter.setClipRegion(ev->rect());
+/*void GLW_Base::paintEvent(QPaintEvent *ev){
+ QOpenGLWidget::paintEvent(ev);
+}*/
+
+void GLW_Base::paintGL(){
+ //Setup the OpenGL stuff
+ QRect rect = QRect(QPoint(0,0), this->size());
+ //Prepare the image to be painted
+ QImage img(this->size(), QImage::Format_RGBA8888);
+ QPainter painter;
+ painter.begin(&img);
+ painter.fillRect(rect, bg_color);
+ painter.end();
+ QOpenGLFunctions *f = this->context()->functions();
+ //f->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ //do native OpenGL commands here
+ glDrawPixels(bg_img.width(), bg_img.height(), GL_RGBA, GL_UNSIGNED_BYTE, bg_img.bits());
+
+ //Now do any QPainter drawing
+ /*QOpenGLPaintDevice device(rect.size());
+ QStylePainter painter;
+ painter.begin(&device, this);
+ //qDebug() << "Paint Engine type:" << painter.paintEngine()->type();
+ painter.setClipRegion(rect);
//Fill in the background color first
- painter.fillRect(ev->rect(), bg_color);
+ painter.fillRect(rect, bg_color);
//Now paint any background image over that
- painter.drawImage(ev->rect(), bg_img, ev->rect(), Qt::AutoColor | Qt::PreferDither | Qt::NoOpaqueDetection);
+ painter.drawImage(rect, bg_img, rect, Qt::AutoColor | Qt::PreferDither | Qt::NoOpaqueDetection);
//Now find any children widgets and paint them if they are in that area
QObjectList child = this->children(); //Note: This is returned in stacking order (lowest -> highest)
for(int i=0; i<child.length(); i++){
if( !child[i]->isWidgetType() ){ continue; } //not a widget
GLW_Widget *glww = qobject_cast<GLW_Widget*>(child[i]);
if(glww!=0){
- if(!ev->rect().intersected(glww->widgetRect()).isNull()){
- glww->paintYourself(&painter, ev);
- glww->paintChildren(&painter,ev);
+ if(!rect.intersected(glww->widgetRect()).isNull()){
+ glww->paintYourself(&painter, &rect);
+ glww->paintChildren(&painter,&rect);
}
- }/*else{
- QWidget *widg = qobject_cast<QWidget*>(child[i]);
- widg->render(&painter, widg->geometry().topLeft());
- }*/
+ }
}
+ painter.end();
+ update();*/
}
diff --git a/src-qt5/src-glwidgets/glw-base.h b/src-qt5/src-glwidgets/glw-base.h
index 3c3d1d4e..ecc5bc3a 100644
--- a/src-qt5/src-glwidgets/glw-base.h
+++ b/src-qt5/src-glwidgets/glw-base.h
@@ -41,7 +41,9 @@ signals:
protected:
void mouseMoveEvent(QMouseEvent *ev);
void resizeEvent(QResizeEvent *ev);
- void paintEvent(QPaintEvent *ev);
+ //void paintEvent(QPaintEvent *ev);
+ //void initializeGL();
+ void paintGL();
};
#endif
diff --git a/src-qt5/src-glwidgets/glw-widget.cpp b/src-qt5/src-glwidgets/glw-widget.cpp
index e6c98d74..e8d255b9 100644
--- a/src-qt5/src-glwidgets/glw-widget.cpp
+++ b/src-qt5/src-glwidgets/glw-widget.cpp
@@ -33,9 +33,9 @@ void GLW_Widget::setGLBase(GLW_Base *base){
connect(this, SIGNAL(repaintArea(QRect)), glw_base, SLOT(repaintArea(QRect)) );
}
-void GLW_Widget::paintYourself(QStylePainter *painter, QPaintEvent *ev){
+void GLW_Widget::paintYourself(QStylePainter *painter, const QRect *prect){
QRect rect = widgetRect();
- rect = rect.intersected(ev->rect());
+ rect = prect->intersected(rect);
QColor color( mouseOverWidget() ? Qt::gray : Qt::yellow);
//if(this->windowOpacity()!=1.0){ qDebug() << "Opacity:" << this->windowOpacity(); }
//color.setAlpha( qRound(this->windowOpacity()*255) );
@@ -43,15 +43,15 @@ void GLW_Widget::paintYourself(QStylePainter *painter, QPaintEvent *ev){
painter->fillRect(rect, color);
}
-void GLW_Widget::paintChildren(QStylePainter *painter, QPaintEvent *ev){
+void GLW_Widget::paintChildren(QStylePainter *painter, const QRect *prect){
QObjectList child = this->children(); //Note: This is returned in stacking order (lowest -> highest)
for(int i=0; i<child.length(); i++){
if( !child[i]->isWidgetType() ){ continue; } //not a widget
GLW_Widget *glww = qobject_cast<GLW_Widget*>(child[i]);
if(glww!=0){
- if(ev->rect().contains(glww->widgetRect())){
- glww->paintYourself(painter, ev);
- glww->paintChildren(painter,ev);
+ if( !prect->intersected(glww->widgetRect()).isNull() ){
+ glww->paintYourself(painter, prect);
+ glww->paintChildren(painter,prect);
}
}
}
diff --git a/src-qt5/src-glwidgets/glw-widget.h b/src-qt5/src-glwidgets/glw-widget.h
index e4d7aa37..69d3515d 100644
--- a/src-qt5/src-glwidgets/glw-widget.h
+++ b/src-qt5/src-glwidgets/glw-widget.h
@@ -31,8 +31,8 @@ public:
void setGLBase(GLW_Base *base);
- virtual void paintYourself(QStylePainter *painter, QPaintEvent *ev);
- void paintChildren(QStylePainter *painter, QPaintEvent *ev);
+ virtual void paintYourself(QStylePainter *painter, const QRect *prect);
+ void paintChildren(QStylePainter *painter, const QRect *prect);
//Properties
bool isDraggable(){ return draggable; }
bgstack15