diff --git a/main.cpp b/main.cpp index 7b77e5a..78528b5 100644 --- a/main.cpp +++ b/main.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ #include +#include class Widget : public QGraphicsWidget { @@ -61,6 +62,35 @@ public: painter->setPen(textColor); painter->drawText(boundingRect(), Qt::AlignCenter, caption); painter->restore(); + + static QGLContext * glContext = const_cast(QGLContext::currentContext()); + if (!glContext) { // I'm not sure when GLContext could setup. + glContext = const_cast(QGLContext::currentContext()); + } + qDebug() <<"bounding rect:" << boundingRect(); +#if 1 + static GLuint pixmapTexture; + + painter->beginNativePainting(); + glLoadIdentity(); + if(!glIsTexture(pixmapTexture)) { + // glContext->bindTexture(QImage(QString("./test.png")), GL_TEXTURE_2D); + glContext->bindTexture(QPixmap(QString("./test.png")), GL_TEXTURE_2D); + } + glBegin(GL_TRIANGLES); + glBindTexture(GL_TEXTURE_2D, pixmapTexture); + glColor3f( 0.8, 0.8, 1.0); + glVertex3f(0+5, glContext->device()->width()/4, 0.0); + glTexCoord2f(0.0f, 0.0f); + glVertex3f(0+5, glContext->device()->height()*3/4, 0.0); + glTexCoord2f(1.0f, 0.0f); + glVertex3f(glContext->device()->width()/2, glContext->device()->height()*3/4, 0.0); + glTexCoord2f(1.0f, 1.0f); + glEnd(); + glColor3f( 1.0, 1.0, 1.0); + painter->endNativePainting(); +#endif + } private: @@ -125,6 +155,7 @@ int main(int argc, char *argv[]) scene->addItem(w); QGraphicsView *view = new QGraphicsView(); + view->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers))); view->setScene(scene); view->setWindowTitle(QApplication::translate("simpleanchorlayout", "Simple Anchor Layout")); view->resize(360, 320); diff --git a/simpleanchorlayout.pro b/simpleanchorlayout.pro index e1c7aeb..2e3c96a 100644 --- a/simpleanchorlayout.pro +++ b/simpleanchorlayout.pro @@ -1,3 +1,4 @@ +QT += opengl SOURCES = main.cpp # install diff --git a/test.png b/test.png new file mode 100755 index 0000000..97141e4 Binary files /dev/null and b/test.png differ