Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. [Solved]OpenGL clarification.

[Solved]OpenGL clarification.

Scheduled Pinned Locked Moved Mobile and Embedded
3 Posts 2 Posters 1.7k 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.
  • V Offline
    V Offline
    Vijaeendra
    wrote on last edited by
    #1

    I m trying to build the following simple example (A white rectangle on a black background) But I m not able to see the same.

    @#ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QPushButton>
    #include <QGridLayout>
    #include <QtOpenGL>
    #include <QDialog>

    class OGLPort : public QGLWidget
    {
    Q_OBJECT

    public:
    OGLPort(QWidget *parent = 0);
    void paintEvent(QPaintEvent *);
    void draw();
    private:
    QPushButton *button;
    QGLFramebufferObject *render_fbo;
    QGLFramebufferObject *texture_fbo;
    };

    #endif // MAINWINDOW_H
    @

    @#include "mainwindow.h"

    OGLPort::OGLPort(QWidget *parent) :
    QGLWidget(parent)
    {
    setWindowTitle("My OpenGL Trial");
    }

    void OGLPort::paintEvent(QPaintEvent *)
    {
    QPainter p(this);
    p.setPen(QColor(197, 197, 197, 157));
    p.setBrush(QColor(197, 197, 197, 127));
    p.drawRect(QRect(0, 0, width(), 50));
    p.setPen(Qt::blue);
    p.setBrush(Qt::NoBrush);
    const QString str1(tr("This is painted"));
    const QString str2(tr("This is also painted"));
    QFontMetrics fm(p.font());
    p.drawText(width()/2 - fm.width(str1)/2, 20, str1);
    p.drawText(width()/2 - fm.width(str2)/2, 20 + fm.lineSpacing(), str2);
    draw();
    }

    void OGLPort::draw()
    {
    glClearColor (0.0, 0.0, 0.0, 0.0);
    //glClear (GL_COLOR_BUFFER_BIT);
    glColor3f (0.0, 0.0, 0.0);
    glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
    glViewport(0, 0, width(), height());
    glBegin(GL_POLYGON);
    glVertex3f (0.25, 0.25, 0.0);
    glVertex3f (0.75, 0.25, 0.0);
    glVertex3f (0.75, 0.75, 0.0);
    glVertex3f (0.25, 0.75, 0.0);
    glEnd();
    glFlush();
    }
    @

    @#include <QtOpenGL/qgl.h>
    #include <QtCore/qvector.h>
    #include <QtGui/qmatrix4x4.h>
    #include <QtGui/qvector3d.h>
    #include <QtGui/qvector2d.h>
    #include <QApplication>

    #include "mainwindow.h"

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    OGLPort w;
    w.show();

    return a.exec(&#41;;
    

    }
    @

    Please help.

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      ZapB
      wrote on last edited by
      #2

      Please read the docs for QGLWidget. It tells you to override the initializeGL(), resizeGL() and paintGL() functions. You should not override paintEvent() to do OpenGL drawing. Also worth checking out the OpenGL examples that ship with Qt.

      Nokia Certified Qt Specialist
      Interested in hearing about Qt related work

      1 Reply Last reply
      0
      • V Offline
        V Offline
        Vijaeendra
        wrote on last edited by
        #3

        Thankyou. I got it right.

        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