当前位置:网站首页>02 -- QT OpenGL drawing triangle
02 -- QT OpenGL drawing triangle
2022-07-03 19:19:00 【Qingsong 0527】
qmyopenglwidget.h
#ifndef QMYOPENGLWIDGET_H
#define QMYOPENGLWIDGET_H
#include <QWidget>
#include <QOpenGLWidget>
#include <QOpenGLFunctions_3_3_Core>
#include <QOpenGLShaderProgram>
class QMyOpenglWidget : public QOpenGLWidget, QOpenGLFunctions_3_3_Core
{
Q_OBJECT
public:
explicit QMyOpenglWidget(QWidget* parent = nullptr);
protected:
virtual void initializeGL();
virtual void resizeGL(int w, int h);
virtual void paintGL();
public:
void cretaeShader();
private:
unsigned int vao1;
QOpenGLShaderProgram program;
signals:
public slots:
};
#endif // QMYOPENGLWIDGET_H
qmyopenglwidget.cpp
#include "qmyopenglwidget.h"
QMyOpenglWidget::QMyOpenglWidget(QWidget* parent):QOpenGLWidget(parent)
{
}
void QMyOpenglWidget::initializeGL()
{
initializeOpenGLFunctions();
glGenVertexArrays(1, &vao1);
unsigned int vbo1;
glGenBuffers(1, &vbo1);
glBindVertexArray(vao1);
glBindBuffer(GL_ARRAY_BUFFER, vbo1);
float vertices[] = {
-1.0, 0, 0,
1.0, 0, 0,
0, 1.0f, 0
};
// Is currently bound to target Create a new data store for the buffer object //
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
// Tell the graphics card how to parse the attribute value in the buffer
glVertexAttribPointer(0, 3, GL_FLOAT, FALSE, 3*sizeof (GL_FLOAT), nullptr);
// Turn on VAO The first attribute of Management
glEnableVertexAttribArray(0);
cretaeShader();
}
void QMyOpenglWidget::resizeGL(int w, int h)
{
}
void QMyOpenglWidget::paintGL()
{
glClearColor(0.2f, 0.2f, 0.1f, 0.1f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBindVertexArray(vao1);
glDrawArrays(GL_TRIANGLES, 0, 3);
update();
}
void QMyOpenglWidget::cretaeShader()
{
program.addShaderFromSourceFile(QOpenGLShader::Vertex, ":/shader/vertex.vert");
program.addShaderFromSourceFile(QOpenGLShader::Fragment, ":/shader/frag.frag");
program.bind();
program.link();
}
vertex.vert
#version 330 core
in vec3 pos;
out vec3 fcolors;
void main(void)
{
gl_Position = vec4(pos, 1.0f);
}
frag.frag
#version 330 core
out vec4 FragColor; // Clip shader output
void main(void)
{
FragColor = vec4(0.5, 0.8, 0.1, 1.0);
}
边栏推荐
- Verilog HDL continuous assignment statement, process assignment statement, process continuous assignment statement
- Web Security (VIII) what is CSRF attack? Why can token prevent csdf attacks?
- SSM整合-前后台协议联调(列表功能、添加功能、添加功能状态处理、修改功能、删除功能)
- Pytorch introduction to deep learning practice notes 13- advanced chapter of cyclic neural network - Classification
- Octopus online ecological chain tour Atocha protocol received near grant worth $50000
- [optics] vortex generation based on MATLAB [including Matlab source code 1927]
- Thinking about festivals
- Analyse du Code du planificateur ego bspline Section Optimizer (1)
- Pecan — @expose()
- EGO Planner代码解析bspline_optimizer部分(1)
猜你喜欢
【学术相关】顶级论文创新点怎么找?中国高校首次获CVPR最佳学生论文奖有感...
Record: install MySQL on ubuntu18.04
第二章:求长方体数组,指定区间内的完全数,改进指定区间内的完全数
Flutter网络和数据存储框架搭建 -b1
我們做了一個智能零售結算平臺
Nous avons fait une plateforme intelligente de règlement de détail
Pytorch introduction to deep learning practice notes 13- advanced chapter of cyclic neural network - Classification
Day_ 18 IO stream system
Simulation scheduling problem of SystemVerilog (1)
FBI警告:有人利用AI换脸冒充他人身份进行远程面试
随机推荐
How can I avoid "div/0!" Errors in Google Docs spreadsheet- How do I avoid the '#DIV/0!' error in Google docs spreadsheet?
论文阅读 GloDyNE Global Topology Preserving Dynamic Network Embedding
Analysis of dart JSON encoder and decoder
EGO Planner代码解析bspline_optimizer部分(1)
What does a really excellent CTO look like in my eyes
【Proteus仿真】用24C04与1602LCD设计的简易加密电子密码锁
Find the median of two positive arrays
2020 intermediate financial management (escort class)
QT -- qfile file read / write operation
Record: pymysql is used in pycharm to connect to the database
FBI warning: some people use AI to disguise themselves as others for remote interview
Verilog HDL continuous assignment statement, process assignment statement, process continuous assignment statement
Zhang Fei hardware 90 day learning notes - personal record of day 3, please see my personal profile / homepage for the complete
FBI警告:有人利用AI换脸冒充他人身份进行远程面试
我们做了一个智能零售结算平台
利用可视化结果,点击出现对应的句子
High concurrency architecture cache
Go home early today
第一章:求所有阶乘和数,大奖赛现场统分程序设计,三位阶乘和数,图形点扫描,递归求n的阶乘n!,求n的阶乘n!,舍罕王失算
Day18 - basis of interface testing