Guest User

Untitled

a guest
Jun 23rd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.68 KB | None | 0 0
  1.  
  2.  
  3. #include <QtGui/QGuiApplication>
  4. #include <QtGui/QImage>
  5. #include <QtDeclarative/QtDeclarative>
  6. #include <QtQuick/QtQuick>
  7.  
  8. int main(int argc, char *argv[])
  9. {
  10.     QGuiApplication a(argc, argv);
  11.  
  12.     QImage logo;
  13.     if (!logo.load("logo.png")) {
  14.         qFatal("Unable to load logo.png.");
  15.     }
  16.  
  17.     QQuickView *view = new QQuickView();
  18.     view->show();
  19.  
  20.     view->setClearBeforeRendering(false);
  21.     view->setResizeMode(QQuickView::SizeRootObjectToView);
  22.     view->setSource(QUrl("Test.qml"));
  23.  
  24.     QObject::connect(view, &QQuickView::beforeRendering, [=]() {
  25.  
  26.             QOpenGLContext *ctx = QOpenGLContext::currentContext();
  27.             ctx->functions()->glUseProgram(0);
  28.  
  29.             glClearColor(1, 0, 0, 1);
  30.             glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  31.  
  32.             glDisable(GL_DEPTH_TEST);
  33.             glDisable(GL_LIGHTING);
  34.             glEnable(GL_TEXTURE_2D);
  35.  
  36.             glMatrixMode(GL_PROJECTION);
  37.             glPushMatrix();
  38.             glLoadIdentity();
  39.             glMatrixMode(GL_MODELVIEW);
  40.             glPushMatrix();
  41.             glLoadIdentity();
  42.  
  43.             QSGTexture *tex = view->createTextureFromImage(logo);
  44.             tex->bind();
  45.             glBegin(GL_QUADS);
  46.             glTexCoord2i(0, 0);
  47.             glVertex2i(-1, 1);
  48.             glTexCoord2i(0, 1);
  49.             glVertex2i(-1, -1);
  50.             glTexCoord2i(1, 1);
  51.             glVertex2i(1, -1);
  52.             glTexCoord2i(1, 0);
  53.             glVertex2i(1, 1);
  54.             glEnd();
  55.  
  56.             glMatrixMode(GL_PROJECTION);
  57.             glPopMatrix();
  58.             glMatrixMode(GL_MODELVIEW);
  59.             glPopMatrix();
  60.     });
  61.  
  62.     return a.exec();
  63. }
Add Comment
Please, Sign In to add comment