简体   繁体   English

如何设计Qwidget中心的三角形(在QT中使用OpenGl)

[英]How design a Triangle in center of Qwidget ( with OpenGl in QT )

i have Ubuntu 14.04 , i will to design a Triangle with opengl in QT , in this video : [this video][1] he designed a triangle like this : 我有Ubuntu 14.04 ,我将在QT使用opengl设计一个Triangle,在此视频中:[this video] [1]他设计了一个三角形,如下所示:

picture1 ( the triangle in the center of screen ) But me , the triangle Painted on the left , like this : picture 2 图片1 (屏幕中心的三角形)但是我,画在左边的三角形,像这样: 图片2

what is the problem ? 问题是什么 ? and How design a Triangle in center ? 以及如何在中心设计一个三角形?
my code : 我的代码:

#include<brm.h>
#include<qgl.h>
brm::brm(QWidget *parent )
    : QGLWidget( parent)
{


}




void
brm::initializeGL(){

    glClearColor(0.2,0.2,0.2,1);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);

}

void brm::paintGL(){

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
    glBegin(GL_TRIANGLES);
    glVertex2f(-1.f ,0.f );
    glVertex2f(1.f,0.f);
     glVertex2f(0.f,1.f);
    glEnd();

}

void brm::resize(int width , int height ){
    glViewport(
    0
    ,
    0
    , width, height);

}

and the header : 和标题:

#ifndef BRM_H
#define BRM_H

#include <QGLWidget>

#include<qwidget.h>
class brm : public QGLWidget
{
    Q_OBJECT

public:

    explicit brm(QWidget *parent = 0);

    void initializeGL();
    void paintGL();
    void resize(int x , int y );


};

#endif // BRM_H

Try to replace 尝试更换

glPushMatrix();

by 通过

glMatrixMode(GL_PROJECTION);
glLoadIdentity()
glMatrixMode(GL_MODELVIEW);
glLoadIdentity()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM