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

边栏推荐
- 第二十章:y= sin(x)/x,漫步坐标系计算,y= sin(x)/x 带廓幅图形,奥运五环,小球滚动与弹跳,流水显示,矩形优化裁剪,r个皇后全控nxn棋盘
- QT -- qfileinfo file information reading
- Does SQL always report foreign key errors when creating tables?
- Yolov3 network model building
- [academic related] how to find the innovation of top papers? Chinese universities won the CVPR Best Student Thesis Award for the first time
- 利用可视化结果,点击出现对应的句子
- [new year job hopping season] test the technical summary of interviewers' favorite questions (with video tutorials and interview questions)
- How to design a high concurrency system
- 第一章:三位阶乘和数,图形点扫描
- Common text labels
猜你喜欢
![[wallpaper] (commercially available) 70 wallpaper HD free](/img/21/6802da1056a18157b15de85df60cf5.jpg)
[wallpaper] (commercially available) 70 wallpaper HD free

This Chinese numpy quick look-up table is too easy!

第一章:求n的阶乘n!

Does SQL always report foreign key errors when creating tables?

2020 intermediate financial management (escort class)

QT -- qfileinfo file information reading
![第二章:基于分解的求水仙花数,基于组合的求水仙花数, 兰德尔数,求[x,y]内的守形数,探求n位守形数,递推探索n位逐位整除数](/img/c5/0081689817700770f6210d50ec4e1f.png)
第二章:基于分解的求水仙花数,基于组合的求水仙花数, 兰德尔数,求[x,y]内的守形数,探求n位守形数,递推探索n位逐位整除数

Help change the socket position of PCB part
![[proteus simulation] a simple encrypted electronic password lock designed with 24C04 and 1602LCD](/img/51/209e35e0b94a51b3b406a184459475.png)
[proteus simulation] a simple encrypted electronic password lock designed with 24C04 and 1602LCD

Simulation scheduling problem of SystemVerilog (1)
随机推荐
Simulation scheduling problem of SystemVerilog (1)
P3402 persistent and searchable
第一章:递归求n的阶乘n!
Thesis study - 7 Very Deep Convolutional Networks for Large-Scale Image Recognition (3/3)
FBI警告:有人利用AI换脸冒充他人身份进行远程面试
Flutter network and data storage framework construction-b1
cipher
Recommend a GIF processing artifact less than 300K - gifsicle (free download)
[water quality prediction] water quality prediction based on MATLAB Fuzzy Neural Network [including Matlab source code 1923]
Web Security (VIII) what is CSRF attack? Why can token prevent csdf attacks?
Pecan — @expose()
为什么要做特征的归一化/标准化?
The most valuable thing
Nous avons fait une plateforme intelligente de règlement de détail
第二章:求长方体数组,指定区间内的完全数,改进指定区间内的完全数
Zhang Fei hardware 90 day learning notes - personal records on day 2, please see my personal profile / homepage for the complete
Compared with 4G, what are the advantages of 5g to meet the technical requirements of industry 4.0
Understanding of database architecture
第一章:求n的阶乘n!
SSM整合-前后台协议联调(列表功能、添加功能、添加功能状态处理、修改功能、删除功能)