结果预览:

Qt中OpenGL的初步使用

一.代码5个文件

//glwidget.h
#ifndef GLWIDGET_H
#define GLWIDGET_H
#include <QGLWidget>


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

    int xRotation() const { return xRot; }
    int yRotation() const { return yRot; }
    int zRotation() const { return zRot; }

signals:
    void xRotationChanged( int angle);
    void yRotationChanged( int angle);
    void zRotationChanged( int angle);
    public slots:
        void setXRotation(int angle);
        void setYRotation(int angle);
        void setZRotation(int angle);
protected:
    void initializeGL();
    void paintGL();
    void resizeGL(int w, int h);
    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);

    private slots:
        void alwaysRotate();
        void drawTriangle();

private:
    void normalizeAngle(int &angle);
    int xRot;
    int yRot;
    int zRot;
    QColor faceColors[4];
    QPoint lastPos;
    QColor qtGreen,    qtPurple;
};

#endif
View Code

相关文章:

  • 2022-12-23
  • 2021-09-30
  • 2022-01-16
  • 2022-12-23
  • 2021-08-12
  • 2021-05-31
  • 2022-02-03
  • 2021-10-20
猜你喜欢
  • 2021-04-10
  • 2021-12-23
  • 2022-01-15
  • 2022-12-23
  • 2021-12-27
  • 2022-01-15
相关资源
相似解决方案