Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Rotating 2 objects Qt and openGL.



  • Hi, There is a program:
    @
    Widget::Widget(QWidget *parent) :
    QGLWidget(parent),
    ui(new Ui::Widget)
    {

    ui->setupUi(this);
    tm = new QTimer(this);
    

    }

    Widget::~Widget()
    {
    delete ui;
    delete tm;
    }

    void Widget::initializeGL()
    {
    connect(tm, SIGNAL(timeout()),this, SLOT(update()));
    tm->start(10);
    }

    void Widget::resizeGL(int n_width, int n_height)
    {

    glViewport(0, 0, (GLint)n_width, (GLint)n_height);
    }

    void Widget::paintGL()
    {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    draw();
    draw2();
    }
    void Widget::update()
    {
    updateGL();
    }

    void Widget::draw()
    {
    glLoadIdentity();
    glTranslatef(-0.35f, 0.0f, -0.20f);
    glRotatef(65.0f/4.0f, 1.0f, 0.0f, 1.0f);
    glBegin(GL_QUADS);
    glColor3f(1.0f,0.0f,0.0f);
    glVertex3f(-0.5f, 0.5f, 0.0f);
    glColor3f(0.0f,1.0f,0.0f);
    glVertex3f(-0.5f, -0.5f, 0.0f);
    glColor3f(1.0f,0.0f,1.0f);
    glVertex3f(0.5f,-0.5f,0.0);
    glColor3f(1.0f,1.0f,1.0f);
    glVertex3f(0.5f,0.5f,0.0);
    glEnd();
    }
    void Widget::draw2()
    {
    glLoadIdentity();
    glTranslatef(0.45f, 0.0f, 0.50f);
    glRotatef(65.0f/4.0f, 0.0f, 1.0f, 1.0f);
    glBegin(GL_QUADS);
    glColor3f(1.0f,0.0f,0.0f);
    glVertex3f(-0.5f, 0.5f, 0.0f);
    glColor3f(0.0f,1.0f,0.0f);
    glVertex3f(-0.5f, -0.5f, 0.0f);
    glColor3f(1.0f,0.0f,1.0f);
    glVertex3f(0.5f,-0.5f,0.0);
    glColor3f(1.0f,1.0f,1.0f);
    glVertex3f(0.5f,0.5f,0.0);
    glEnd();
    }
    @

    After starting the program, a square defined functions Drava () drev2 () remain nepodvizhny.Pri window is resized so the rotation does not occur.
    Prompt in what could be the problem? Version Qt 4.8. OpenGL 3.3


Log in to reply