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. (Help please) How to show drawing in QGLWidget on mainwindow?
Forum Updated to NodeBB v4.3 + New Features

(Help please) How to show drawing in QGLWidget on mainwindow?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 983 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.
  • F Offline
    F Offline
    Fuji
    wrote on last edited by
    #1

    Hello,
    I'm new to QT and OpenGL and need your help for my question. I have created a QT+OpenGL application. I have a mainwindow UI and have place a Widget inherited from QGLWidget on the mainwindow.

    I have write a simple OpenGL code to show points on the screen. The function is called (I had placed a messagebox there) but the app does not display the points I pained on screen. Please help what I should do to have the points display on screen.

    Here is my code in .h file.

    @#include <QGLWidget>

    class MyPanelOpenGL : public QGLWidget
    {
    Q_OBJECT
    public:
    explicit MyPanelOpenGL(QWidget *parent = 0);

    protected:
    void initializeGL();
    void resizeGL(int width, int height);
    void paintGL();
    void draw();

    signals:

    public slots:

    };@

    and here is my implementation .cpp file - in which I draw points in draw()
    @MyPanelOpenGL::MyPanelOpenGL(QWidget *parent) :
    QGLWidget(parent)
    {
    setFormat(QGLFormat(QGL::DoubleBuffer | QGL::DepthBuffer));
    }

    void MyPanelOpenGL::initializeGL()
    {
    qglClearColor(Qt::white);
    glShadeModel(GL_FLAT);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);
    }

    void MyPanelOpenGL::resizeGL(int width, int height)
    {
    glViewport(0,0,width,height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    GLfloat x = GLfloat(width)/height;
    glFrustum(-x, +x, -1.0, +1.0, 4.0, 15.0);
    glMatrixMode(GL_MODELVIEW);

    }

    void MyPanelOpenGL::paintGL()
    {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    draw();
    }

    void MyPanelOpenGL::draw()
    {
    glColor3f(1.0, 0.0, 0.0);
    glBegin(GL_POINTS);
    glVertex2i(50,100);
    glVertex2i(75,150);
    glVertex2i(100,200);
    glEnd();

    glFlush();
    //updateGL();
    

    }
    @

    Really thanks for your help ^^

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Arnaut
      wrote on last edited by
      #2

      Hi Fuji,

      My guess is that you can't see the points because they are outside the viewing frustum - try glVertex2i(0,0).

      Regards,

      1 Reply Last reply
      0
      • F Offline
        F Offline
        Fuji
        wrote on last edited by
        #3

        Hi Arnaut, Thanks for that but it still doesn't work.

        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