本文主要是介绍Qt OpenGL 绘制支持矩阵变化立方体,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一、效果图
二、代码
#ifndef ROTATEGL_H
#define ROTATEGL_H#include <QObject>
#include <QOpenGLWidget>
#include <QOpenGLFunctions>
#include <QOpenGLBuffer>
#include <QOpenGLTexture>
#include <QOpenGLShaderProgram>
#include <QKeyEvent>
#include <QEvent>
#include <QDebug>
class rotateGl:public QOpenGLWidget,protected QOpenGLFunctions
{Q_OBJECT
public:rotateGl(QWidget* parent = nullptr);
protected:void initializeGL();void paintGL();void resizeGL(int w, int h);void keyPressEvent(QKeyEvent *evnet);
private://The QOpenGLShaderProgram class allows OpenGL shader programs to be linked and usedQOpenGLShaderProgram *program;//provides functions for creating and managing OpenGL buffer objects.QOpenGLBuffer vbo;//encapsulates an OpenGL texture objectQOpenGLTexture *textures[6];GLfloat translate,xRot,yRot,zRot;
};#endif // ROTATEGL_H
#include "rotategl.h"rotateGl::rotateGl(QWidget *parent):QOpenGLWidget(parent)
{translate = -6.0;xRot = zRot = 0.0;yRot = -30.0;setFocusPolicy(Qt::StrongFocus);
}void rotateGl::initializeGL()
{initializeOpenGLFunctions();glEnable(GL_DEPTH_TEST);for(int i=0; i<6; ++i){textures[i] = new QOpenGLTexture(QImage(QString(":/img/side%1.png").arg(i+1)).mirrored());}//顶点着色器QOpenGLShader *vshader = new QOpenGLShader(QOpenGLShader::Vertex,this);con
这篇关于Qt OpenGL 绘制支持矩阵变化立方体的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!