Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Flip or rotate viewport within QOpenGLWidget in Qt 5.8
Forum Updated to NodeBB v4.3 + New Features

Flip or rotate viewport within QOpenGLWidget in Qt 5.8

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CamelFrog
    wrote on last edited by
    #1

    Hi,

    In Qt 5.8.0 (and msvc 2015), I'm using a subclass of QOpenGLWidget with opengl 3.3 core profile to display images as textures and sometimes I need to rotate the image by multiples of 90 degrees.
    I read that we can use either glPixelZoom or glScalef or other things to rotate, although it's not clear to me to which openGL version that applies. I tried both of them but the app does not compile.

    This compiles and works fine when I do not try to rotate:

    QOpenGLWidget::resizeGL(int w, int h) :
    {
       glViewport( 0, 0, w, h );
    }
    

    But this does not work, i get a LNK2019 unresolved external symbol:

    QOpenGLWidget::resizeGL(int w, int h) :
    {
       glScalef(1, -1, 1); // Or glPixelZoom(1, -1) 
       glViewport( 0, 0, w, h );
    }
    

    Maybe glScalef() and glPixelZoom() are not for openGL 3.3? If that's true, how may I simply display a rotated or flipped texture in resizeGL() with OpenGL 3.3 core profile? In addition, should I setup the flip / rotation in paintGL() in addition to / instead of resizeGL()?

    If that's relevant, here's my list of includes:

    #include <QApplication>
    #include <QOpenGLWidget>
    #include <QtGui/QWindow>
    #include <QtGui/QOpenGLFunctions>
    #include <QtGui/QOpenGLShaderProgram>
    #include <QOpenGLVertexArrayObject>
    #include <QOpenGLBuffer>
    #include <QOpenGLTexture>
    #include <QScreen>
    

    Thank you

    1 Reply Last reply
    0
    • johngodJ Offline
      johngodJ Offline
      johngod
      wrote on last edited by johngod
      #2

      Hi there

      You cannot use glScalef() in the core profile. You now rotate the images using a rotation matrix in the paintGL() method (not in resizeGL(...) ) and then pass it to the vertex shader where the rotation is applied. Something like this:

      void MyGL::paintGL()
      {
          glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
          glUseProgram(program);
      
          QMatrix4x4 view;
          view.setToIdentity();
          view.rotate(90, 1.0f, 0.0f, 0.0f ); //90 degree around x axis
          view.scale(scaleX, scaleY, scaleZ);// also do some scaling if you want
      
          glUniformMatrix4fv(glGetUniformLocation(program , "matrixRotation"), 1, false, view.constData());// send the matrix to the shader
      .....
      

      Now in the vertex shader:

      uniform mat4 matrixRotation;
      layout (location = 0) in vec4 position;
      
      void main()
      {
          gl_Position = matrixRotation * position;
          ...
      
      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved