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. QT paintgl does not show anything on the screen
Forum Updated to NodeBB v4.3 + New Features

QT paintgl does not show anything on the screen

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 646 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.
  • mhsgoudM Offline
    mhsgoudM Offline
    mhsgoud
    wrote on last edited by mhsgoud
    #1

    I am trying to draw some basic shapes using OpenGL.

    void GLWidget::initializeGL()
    {
        glClearColor(0.5, 0.5, 0.5, 1.0);
    
    }
    
    void GLWidget::paintGL()
    {
        glClear(GL_COLOR_BUFFER_BIT);
    
        // draw a red triangle
        glColor3f(1,0,0);
        glBegin(GL_POLYGON);
        glVertex2f(1,1);
        glVertex2f(1,6);
        glVertex2f(1,1);
        glEnd();
    
    }
    
    

    nothing shows on the window. also can not link glut, unfortunately!
    3f021168-a9f2-449d-877c-d9c9e27f8a73-image.png

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You don't seem to set the projection nor the modelview matrix so you are likely not looking in the right direction and maybe painting something that is too small to be seen.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • mhsgoudM Offline
        mhsgoudM Offline
        mhsgoud
        wrote on last edited by mhsgoud
        #3

        @SGaist said in QT paintgl does not show anything on the screen:

        modelview matrix

        Thanks! I have now modified the code:
        Now trying to plot a tetrahedron, which I got from an old textbook (qt4).

        void Tetrahedron::draw()
        {
            static const GLfloat P1[3] = { 0.0, -1.0, +2.0 };
            static const GLfloat P2[3] = { +1.73205081, -1.0, -1.0 };
            static const GLfloat P3[3] = { -1.73205081, -1.0, -1.0 };
            static const GLfloat P4[3] = { 0.0, +2.0, 0.0 };
            static const GLfloat * const coords[4][3] = {
            { P1, P2, P3 }, { P1, P3, P4 }, { P1, P4, P2 }, { P2, P4, P3 }
            };
            glMatrixMode(GL_MODELVIEW);
            glLoadIdentity();
            glTranslatef(0.0, 0.0, -10.0);
            glRotatef(rotationX, 1.0, 0.0, 0.0);
            glRotatef(rotationY, 0.0, 1.0, 0.0);
            glRotatef(rotationZ, 0.0, 0.0, 1.0);
            for (int i = 0; i < 4; ++i) {
            glLoadName(i);
            glBegin(GL_TRIANGLES);
        //    qglColor (faceColors[i]);
        
        
            glColor3f(1,0.3,1);
        
            for (int j = 0; j < 3; ++j) {
            glVertex3f(coords[i][j][0], coords[i][j][1],
            coords[i][j][2]);
            }
            glEnd();
            }
        
        
        }
        

        the problem is qglColor (faceColors[I]); does not work anymore with the new qt version! I could not find out how this should be changed?

        Also, almost every opengl code I (as a beginner) find on the internet is unusable with changes made in QT6, which brings me to the question what is the point of all the changes...

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          What do you mean by does not work anymore ?

          As of the changes, OpenGL itself has seen quite a few versions since the Qt 4 times hence Qt has provided new interfaces that allow you to still use the old fixed pipeline but easily take advantage of the new one.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • mhsgoudM Offline
            mhsgoudM Offline
            mhsgoud
            wrote on last edited by
            #5

            Thank you for your reply. sorry I am super new to these. I mean it does not compile,
            error: use of undeclared identifier 'qglColor'

            1 Reply Last reply
            0
            • JoeCFDJ Offline
              JoeCFDJ Offline
              JoeCFD
              wrote on last edited by JoeCFD
              #6

              Check out the examples in your installation of any qt version. I have 5.15.2.
              qt-examples/Qt-5.15.2/opengl

              1 Reply Last reply
              1
              • JoeCFDJ Offline
                JoeCFDJ Offline
                JoeCFD
                wrote on last edited by
                #7

                You can simply use VTK(open source) to display meshes unless you have to do it by yourself.

                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