Qt Forum

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

    OpenGL extension doesn't work

    General and Desktop
    1
    1
    1733
    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.
    • P
      pbartosz last edited by

      I'm trying to uses GL_NV_Path_rendering OpenGL extension in my Qt 4.8.4 application. To render OpenGL i'm using QGLWidget class.
      My graphics card is recognised correctly:
      @OpenGL Versions Supported: QFlags(0x1|0x2|0x4|0x8|0x10|0x20|0x40|0x1000|0x2000|0x4000|0x8000|0x10000)
      Driver Version String: "4.2.0"
      Current Context: QGLFormat(options QFlags(0x1|0x2|0x4|0x10|0x20|0x80|0x400) , plane 0 , depthBufferSize 24 , accumBufferSize 64 , stencilBufferSize 8 , redBufferSize 8 , greenBufferSize 8 , blueBufferSize 8 , alphaBufferSize -1 , samples -1 , swapInterval 1 , majorVersion 4 , minorVersion 2 , profile 2 ) @

      I'm using QGLContext::getProcAddress() method to get GL_NV_Path_rendering extension functions adresses and they are also returned correctly. But when I try to use them (basing in NVIDIA example) in paintGL() method, nothing is rendered.
      Could someone look at my source code and tell me what's wrong?

      @
      #include "glwidget.h"
      #include <stdio.h>

      #include "glextensions.h"

      int hasPathRendering = 1;
      int hasDirectStateAccess = 1;
      const char *programName = "nvpr_basic";
      GLuint pathObj = 42;
      int path_specification_mode = 0;
      int filling = 1;
      int stroking = 1;
      int even_odd = 0;

      GLWidget::GLWidget(QWidget *parent) :
      QGLWidget(parent)
      {
      }

      void GLWidget::initializeGL()
      {
      qDebug() << "OpenGL Versions Supported: " << QGLFormat::openGLVersionFlags();
      QString versionString(QLatin1String(reinterpret_cast<const char*>(glGetString(GL_VERSION))));
      qDebug() << "Driver Version String:" << versionString;
      qDebug() << "Current Context:" << format();

      if (!getGLExtensionFunctions().resolve(context())) {
            QMessageBox::critical(0, "OpenGL features missing",
                "Failed to resolve OpenGL functions required to run this demo.\n"
                "The program will now exit.");
            delete this;
            return;
        }
      
      initGraphics();
      
      glViewport(0, 0, width(), height());
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      //glOrtho(-50, 50, -50, 50, -50, 50);
      glMatrixMode(GL_MODELVIEW);
      
      glClearColor(0.2, 0.2, 0.2, 1);
      

      }

      void initGraphics()
      {
      initPathFromSVG();

      glPathParameteriNV(pathObj, GL_PATH_JOIN_STYLE_NV, GL_ROUND_NV);
      glPathParameterfNV(pathObj, GL_PATH_STROKE_WIDTH_NV, 6.5);
      

      }

      void
      initPathFromSVG()
      {
      const char *svgPathString =
      //star
      "M100,180 L40,10 L190,120 L10,120 L160,10 z";
      // heart
      "M300 300 C 100 400,100 200,300 100,500 200,500 400,300 300Z";
      glPathStringNV(pathObj, GL_PATH_FORMAT_SVG_NV,
      (GLsizei)strlen(svgPathString), svgPathString);
      }

      void GLWidget::paintGL()
      {
      glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
      doGraphics();
      //swapBuffers();
      }

      void
      doGraphics(void)
      {
      glClearStencil(0);
      glClearColor(0,0,0,0);
      glStencilMask(~0);
      glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

      glMatrixLoadIdentityEXT(GL_PROJECTION);
      glMatrixLoadIdentityEXT(GL_MODELVIEW);
      glMatrixOrthoEXT(GL_MODELVIEW, 0, 500, 0, 400, -1, 1);
      
      filling = true;
      stroking = true;
      
      if (filling) {
          qDebug("filling");
      
          glStencilFillPathNV(pathObj, GL_COUNT_UP_NV, 0x1F);
      
          glEnable(GL_STENCIL_TEST);
          int even_odd = 0;
          if (even_odd) {
              glStencilFunc(GL_NOTEQUAL, 0, 0x1);
          } else {
              glStencilFunc(GL_NOTEQUAL, 0, 0x1F); // make viewport black !?
          }
          glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO);
          glColor3f(0,1,0); // green
          glCoverFillPathNV(pathObj, GL_BOUNDING_BOX_NV);
      
          glBegin(GL_TRIANGLES); //this renders correctly !
          glVertex3f(0.8,0.9,0);
          glVertex3f(0.9,0.9,0);
          glVertex3f(0,0.4,0);
          glEnd();
      }
      
      if (stroking) {
          qDebug("stroking");
          glStencilStrokePathNV(pathObj, 0x1, ~0);
          glColor3f(1,1,0); // yellow
          glCoverStrokePathNV(pathObj, GL_CONVEX_HULL_NV);
      }
      

      }

      void GLWidget::resizeGL()
      {
      }
      @

      Complete source code with comments: http://www.sendspace.com/file/jdrjsx

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