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. QPainter drawRect does not work with GL_CULL_FACE
Forum Updated to NodeBB v4.3 + New Features

QPainter drawRect does not work with GL_CULL_FACE

Scheduled Pinned Locked Moved Unsolved General and Desktop
openglqopenglwidgetqpainter
2 Posts 2 Posters 964 Views 2 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.
  • D Offline
    D Offline
    dalishi
    wrote on last edited by dalishi
    #1

    Hi guys, I am using QOpenGLWidget as my main widget and drawing objects using both raw OpenGL command and QPainter (I use QPainter to draw texts and some basic shapes like rectangle.). In my raw OpenGL, I have GL_CULL_FACE enabled but I realized GL_CULL_FACE does not work with QPainter::drawRect().

    I have glEnable(GL_CULL_FACE); in my initializeGL() and in paintGL() use the following to draw text and rectangle.

    
        // Render text
        m_test_painter->begin(this);
        m_test_painter->setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
        m_test_painter->setPen(textColor);
        m_test_painter->setFont(QFont("Arial", 30));
    
        m_test_painter->drawText(textPos, Qt::AlignCenter, text); // worked
        m_test_painter->setBrush(QColor(0, 0, 255, 127));
        m_test_painter->drawRect(0, 0, width(), height()/2);  // with GL_CULL_FACE enabled, this does not work. The rect does not show up. 
        // Comment out glEnable(GL_CULL_FACE), the rect shows up perfectly.
        m_test_painter->end();
    
    K 1 Reply Last reply
    0
    • D dalishi

      Hi guys, I am using QOpenGLWidget as my main widget and drawing objects using both raw OpenGL command and QPainter (I use QPainter to draw texts and some basic shapes like rectangle.). In my raw OpenGL, I have GL_CULL_FACE enabled but I realized GL_CULL_FACE does not work with QPainter::drawRect().

      I have glEnable(GL_CULL_FACE); in my initializeGL() and in paintGL() use the following to draw text and rectangle.

      
          // Render text
          m_test_painter->begin(this);
          m_test_painter->setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
          m_test_painter->setPen(textColor);
          m_test_painter->setFont(QFont("Arial", 30));
      
          m_test_painter->drawText(textPos, Qt::AlignCenter, text); // worked
          m_test_painter->setBrush(QColor(0, 0, 255, 127));
          m_test_painter->drawRect(0, 0, width(), height()/2);  // with GL_CULL_FACE enabled, this does not work. The rect does not show up. 
          // Comment out glEnable(GL_CULL_FACE), the rect shows up perfectly.
          m_test_painter->end();
      
      K Offline
      K Offline
      kenchan
      wrote on last edited by kenchan
      #2

      @dalishi
      You should not mix painter and gl calls like that. You should put gl calls between calls to beginNativePainting() and endNativePainting(), which are painter functions. It might also help to save the painter state before and restore it after depending on how it messes up your gl stuff.
      the docs here tell you what the painter does to the states.

      1 Reply Last reply
      2

      • Login

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