G
G
Gravit2015-10-01 14:56:10
Qt
Gravit, 2015-10-01 14:56:10

Why does QGLWidget refuse to build 3D objects?

QGLWidget refuses to build a cube with this code:

void Widget::paintGL()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW);
    //glLoadIdentity();
    glTranslatef(0.f,0.0f,2.0f);

    glRotatef(1.0f,1.0f,1.0f,1.0f);
    glBegin(GL_QUADS);
     glColor3f(0.0f,1.0f,0.0f);

    glVertex3f(-1.0f, 1.0f, 0.0f);
                    glVertex3f( 1.0f, 1.0f, 0.0f);
                    glVertex3f( 1.0f,-1.0f, 0.0f);
                    glVertex3f(-1.0f,-1.0f, 0.0f);

    glColor3f(0.0f,1.0f,0.0f);
          glVertex3f( 1.0f, 1.0f,-1.0f);
          glVertex3f(-1.0f, 1.0f,-1.0f);
          glVertex3f(-1.0f, 1.0f, 1.0f);
          glVertex3f( 1.0f, 1.0f, 1.0f);
          glColor3f(1.0f,0.5f,0.0f);
                  glVertex3f( 1.0f,-1.0f, 1.0f);
                  glVertex3f(-1.0f,-1.0f, 1.0f);
                  glVertex3f(-1.0f,-1.0f,-1.0f);
                  glVertex3f( 1.0f,-1.0f,-1.0f);
                  glColor3f(1.0f,0.0f,0.0f);
                         glVertex3f( 1.0f, 1.0f, 1.0f);
                         glVertex3f(-1.0f, 1.0f, 1.0f);
                         glVertex3f(-1.0f,-1.0f, 1.0f);
                         glVertex3f( 1.0f,-1.0f, 1.0f);
                         glColor3f(1.0f,1.0f,0.0f);
                                glVertex3f( 1.0f,-1.0f,-1.0f);
                                glVertex3f(-1.0f,-1.0f,-1.0f);
                                glVertex3f(-1.0f, 1.0f,-1.0f);
                                glVertex3f( 1.0f, 1.0f,-1.0f);
                                glColor3f(0.0f,0.0f,1.0f);
                                        glVertex3f(-1.0f, 1.0f, 1.0f);
                                        glVertex3f(-1.0f, 1.0f,-1.0f);
                                        glVertex3f(-1.0f,-1.0f,-1.0f);
                                        glVertex3f(-1.0f,-1.0f, 1.0f);
                                        glColor3f(1.0f,0.0f,1.0f);
                                        glVertex3f( 1.0f, 1.0f,-1.0f);
                                        glVertex3f( 1.0f, 1.0f, 1.0f);
                                        glVertex3f( 1.0f,-1.0f, 1.0f);
                                        glVertex3f( 1.0f,-1.0f,-1.0f);
                                        glEnd();
                                        glTranslatef(3.0f,0.0f,0.0f);

}

But this code is working:
void Widget::paintGL()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW);
    //glLoadIdentity();
    glTranslatef(0.f,0.0f,2.0f);

    glRotatef(1.0f,1.0f,1.0f,1.0f);
    glBegin(GL_QUADS);
    glVertex3f(0.5, 0.5, 0.5);
    glVertex3f(-0.5, 0.5, 0.5);
    glVertex3f(-0.5, -0.5, 0.5);
    glVertex3f(0.5, -0.5, 0.5);
    glEnd();

}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question