当前位置:网站首页>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);
}

边栏推荐
- 【数学建模】基于matlab船舶三自由度MMG模型【含Matlab源码 1925期】
- Common text labels
- High concurrency Architecture - separate databases and tables
- I study database at station B (4): DQL
- Day_ 18 IO stream system
- Flutter network and data storage framework construction-b1
- 2020 intermediate financial management (escort class)
- Using the visualization results, click to appear the corresponding sentence
- Ego planner code parsing Bspline_ Optimizer section (1)
- Record: writing MySQL commands
猜你喜欢

为什么要做特征的归一化/标准化?

What does a really excellent CTO look like in my eyes

Day_ 18 IO stream system

Free year-end report summary template Welfare Collection

【光学】基于matlab介电常数计算【含Matlab源码 1926期】

Using the visualization results, click to appear the corresponding sentence

Summary of composition materials for 2020 high-frequency examination center of educational resources
![[optics] dielectric constant calculation based on MATLAB [including Matlab source code 1926]](/img/cb/ee696d5a7d6bef96fe0db89e8478ed.jpg)
[optics] dielectric constant calculation based on MATLAB [including Matlab source code 1926]
![[disease identification] machine vision lung cancer detection system based on Matlab GUI [including Matlab source code 1922]](/img/fc/00835b95537cf889588502a3d13bc9.png)
[disease identification] machine vision lung cancer detection system based on Matlab GUI [including Matlab source code 1922]

QT -- qfileinfo file information reading
随机推荐
第二章:求长方体数组,指定区间内的完全数,改进指定区间内的完全数
Using the visualization results, click to appear the corresponding sentence
记录在模拟器中运行flutter时报的错
Integrated easy to pay secondary domain name distribution system
Comments on flowable source code (37) asynchronous job processor
The necessity of lean production and management in sheet metal industry
[free sharing] kotalog diary2022 plan electronic manual ledger
东数西算拉动千亿产业,敢啃“硬骨头”的存储厂商才更有机会
Luogu-p1107 [bjwc2008] Lei Tao's kitten
__ Weak and__ The difference between blocks
我们做了一个智能零售结算平台
Flask generates swagger documents
第一章:递归求n的阶乘n!
【光学】基于matlab涡旋光产生【含Matlab源码 1927期】
EGO Planner代碼解析bspline_optimizer部分(1)
Summary of composition materials for 2020 high-frequency examination center of educational resources
The online customer service system developed by PHP is fully open source without encryption, and supports wechat customer service docking
Record: writing MySQL commands
01. Preparation for automated office (free guidance, only three steps)
Pecan — Overview