学习OpenGL中的坐标
(1) 头文件
#ifndef COPENGLWIDGETHELLOCOORDINATE_H
#define COPENGLWIDGETHELLOCOORDINATE_H
/*
* 控件名称:Hello Coordinate
*
*
* 注意:STD C++ Version >= C++11
*
* Author: hsw
*
*/
#include <QPainter>
#include <QPaintEngine>
#include <QKeyEvent>
#include <QDebug>
#include <QCoreApplication>
#include <QOpenGLWidget> // OpenGLWidget
#include <QOpenGLFunctions> // OpenGL函数
#include <QOpenGLShaderProgram>
#include <QOpenGLShader>
#include <QOpenGLBuffer>
#include <QOpenGLTexture>
#include <QMatrix4x4>
class COpenGLWidgetHelloCoordinate : public QOpenGLWidget, public QOpenGLFunctions
{
public:
COpenGLWidgetHelloCoordinate(int mode = 0, QWidget* parent = 0);
~COpenGLWidgetHelloCoordinate();
protected:
void initializeGL() override;
void resizeGL(int width, int height) override;
void paintGL() override;
protected:
bool eventFilter(QObject *obj, QEvent *event);
signals:
void m_openglCloseSgn();
private:
void m_paintCube(const QVector3D &position, const int posIndex);
private:
QWidget* m_pParent;
private:
// OpenGL
QOpenGLShader* m_pVShader; // 顶点着色器
QOpenGLShader* m_pFShader; // 片段着色器
QOpenGLShaderProgram* m_pShaderProgram; // 管理着色器
QOpenGLBuffer m_vBufferObject; // 顶点的缓冲对象
QOpenGLTexture* m_pTexture; // 纹理对象
QOpenGLTexture* m_pTexture2; //
int m_vertexAttr; // 顶点位置数据对象
int m_colorAttr; // 顶点颜色数据对象
int m_textureAttr; // 纹理数据对象
int m_mode; // 着色器中传入颜色的模式:= 0, 表示矩形示例, = 1, 表示矩形示例 + 自定义颜色
};
#endif // COPENGLWIDGETHELLOCOORDINATE_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "copenglwidgethellocoordinate.h"
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
COpenGLWidgetHelloCoordinate* m_pRSOpenGLWidgetHelloCoordinate;
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
(1) CPP文件
#include "copenglwidgethellocoordinate.h