Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

    QGLWidget won't draw (but context is set up correctly)

    General and Desktop
    2
    5
    1843
    Loading More Posts
    • 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.
    • Q
      Qixx last edited by

      Trying to get something (anything) to draw on a QGLWidget is proving to be harder that I thought it'd be. However, the below quad just isn't drawing.

      Here are the GL-parts of the code I am testing with right now. Note that a LOT of it is in there just to try to get something to work. I went so far as to copy and paste the code from the guides directly, but to no avail. There are no other methods in the class that have anything to do with drawing, setting up the widget, or anything else. This is the only widget in the entire program, and the QApplication has been set up correctly.

      The lines marked with 'Didn't help' were lines I added in later to see if it would change anything. It didn't. The mult/frames variables are there to make the background color pulse from black to purple. I did this to confirm gl calls were working within the paint method. Sure enough, the clear color fades in and out as expected, showing that the context seems to be set up correctly.

      All other log calls are displayed as expected as well.

      @// TODO DEBUG
      static float mult = 0.0f;
      static long frames = 0;

      void QTWindow::initializeGL()
      {
      // TODO DEBUG
      debug("Init'ing GL");
      //this->makeCurrent(); ///< Didn't help
      this->resizeGL(0, 0); ///< Didn't help
      glDisable(GL_CULL_FACE); ///< Didn't help
      glEnable(GL_DEPTH_TEST); ///< Didn't help
      glClearColor(1, 0, 1, 1);
      }

      void QTWindow::paintGL()
      {
      // TODO DEBUG
      debug("Painting GL");
      //this->makeCurrent(); ///< Didn't help
      //glViewport(0, 0, this->width(), this->height()); ///< Didn't help
      glLoadIdentity();
      glMatrixMode(GL_MODELVIEW); ///< Didn't help
      glClearColor(mult, 0, mult, 1); ///< Put here to confirm the frames were being drawn
      glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
      mult = abs(sin((double)frames/4.0));
      ++frames;
      glColor3f(0,1,1);
      glTranslatef(frames, frames, 0);
      glBegin(GL_QUADS);
      glVertex3f(-500,-500,0);
      glVertex3f(500,-500,0);
      glVertex3f(500,500,0);
      glVertex3f(-500,500,0);
      glEnd();
      glFinish(); ///< Didn't help
      this->swapBuffers(); ///< Didn't help
      }

      void QTWindow::resizeGL(int width, int height)
      {
      // TODO DEBUG
      debug("Resizing GL");
      //this->makeCurrent(); ///< Didn't help
      glViewport(0, 0, width, height); ///< Didn't help
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      glOrtho(0, 1000, 0, 1000, -1, 1);
      glMatrixMode(GL_MODELVIEW);
      glLoadIdentity();
      }@

      There were a few suggestions on StackOverflow but none of them have worked.

      Is there anyone who can shed some light? I've been stuck on this for a week now.

      1 Reply Last reply Reply Quote 0
      • Q
        Qixx last edited by

        Forgive me, but bump. Two sites and nobody can shed any light on this at all. I'm sitting here twiddling my thumbs.

        1 Reply Last reply Reply Quote 0
        • T
          tilsitt last edited by

          Hi,

          What are the parameters in your constructor?

          Have you tried to use glGetError()?

          What is returned by glGetString(GL_VERSION)?

          1 Reply Last reply Reply Quote 0
          • Q
            Qixx last edited by

            Hello,

            I'm using the default constructor.

            gDEBugger showed no errors. However, just to make sure, I did go ahead and put in a glGetError check after every call in the above example. None of them produced errors.

            glGetString(GL_VERSION) returns 4.2.11991 Compatibility Profile Context.

            EDIT: After giving what I just posted a little thought, I decided to look up exactly what a compatibility profile context was. It says that all deprecation warnings would be silenced. Since most of the functions (including the actual drawing functions - that aren't working) were removed in 3.1 iirc, this is more than likely my issue.

            I'll update once I set the default format to 3.0.

            EDIT2: So after setting the version to 3.0 (which did change the version string), it still didn't draw. Then I realized I needed to go down to version 1.1. I set the version, but the version string popped back up to 4.2. What gives? I use OpenGL 1.1 all the time in other applications. How come it wont work this time?

            EDIT3: I did check the supported version flags. It shows that version 1.1 is supported and detected. Why, then, can I not set it as the default version?

            1 Reply Last reply Reply Quote 0
            • T
              tilsitt last edited by

              I wanted to know if you contructed your OpenGL context with all the needed flags. If you used default constructor, then you're using "default QGLFormat":http://qt-project.org/doc/qt-4.8/qglformat.html#defaultFormat. If you didn't define it, it's like using "QGLFormat's default constructor":http://qt-project.org/doc/qt-4.8/qglformat.html#QGLFormat. So you should have double buffering and depth test enabbled. Just to be sure, can you make a qDebug() of the widget's format and post the result?

              I had some issues with my last driver update, which gave me OpenGL 4.3 (I was in 4.1 before): the context didn't really support deprecated functions, so glVertex and co weren't supported. But if it was the problem here, glGetError() should return errors.

              Qt needs OpenGL 2.0 functions, so I think that's the reason you can't get a lower version.

              In your initializeGL(), remove "this->resizeGL(0, 0)". In the better case, it is useless. In fact, you're making a null viewport, and if you're not going again in resizeGL(), you will never have a valid viewport. Check you're going through resizeGL() with width and height greater than 0.

              Remove your "glTranslatef(frames, frames, 0)": you're always incrementing frames, so your quads will of course disappear after a few refresh.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post