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

边栏推荐
- 我們做了一個智能零售結算平臺
- Ctrip will implement a 3+2 work system in March, with 3 days on duty and 2 days at home every week
- C enum contains value - C enum contains value
- Summary of learning materials and notes of Zhang Fei's actual combat electronics 1-31
- SSM integration - joint debugging of front and rear protocols (list function, add function, add function status processing, modify function, delete function)
- EGO Planner代码解析bspline_optimizer部分(3)
- 01. Preparation for automated office (free guidance, only three steps)
- During MySQL installation, the download interface is empty, and the components to be downloaded are not displayed. MySQL installer 8.0.28.0 download interface is empty solution
- [optics] dielectric constant calculation based on MATLAB [including Matlab source code 1926]
- Using the visualization results, click to appear the corresponding sentence
猜你喜欢
![[new year job hopping season] test the technical summary of interviewers' favorite questions (with video tutorials and interview questions)](/img/4e/a51365bb88b1fc29d1c77fcdde5350.jpg)
[new year job hopping season] test the technical summary of interviewers' favorite questions (with video tutorials and interview questions)

Verilog HDL continuous assignment statement, process assignment statement, process continuous assignment statement

Buuctf's different flags and simplerev

Integrated easy to pay secondary domain name distribution system

利用可视化结果,点击出现对应的句子

Nous avons fait une plateforme intelligente de règlement de détail

Ego planner code parsing Bspline_ Optimizer section (3)

Record: install MySQL on ubuntu18.04

During MySQL installation, the download interface is empty, and the components to be downloaded are not displayed. MySQL installer 8.0.28.0 download interface is empty solution
![[free sharing] kotalog diary2022 plan electronic manual ledger](/img/ca/1ffbfcc16e3019261f70274a89c16f.jpg)
[free sharing] kotalog diary2022 plan electronic manual ledger
随机推荐
P3402 persistent and searchable
Redis master-slave synchronization, clustering, persistence
Zhang Fei hardware 90 day learning notes - personal record on day 6. Please see my personal profile / homepage for the complete record
math_泰勒公式
Pecan - route
Dart JSON编码器和解码器剖析
Integrated easy to pay secondary domain name distribution system
Day18 - basis of interface testing
[free sharing] kotalog diary2022 plan electronic manual ledger
Free year-end report summary template Welfare Collection
SSM integration - joint debugging of front and rear protocols (list function, add function, add function status processing, modify function, delete function)
Pecan — Overview
[mathematical modeling] ship three degree of freedom MMG model based on MATLAB [including Matlab source code 1925]
Pytorch introduction to deep learning practice notes 13- advanced chapter of cyclic neural network - Classification
Sustainable service business models
Octopus online ecological chain tour Atocha protocol received near grant worth $50000
Recommend a GIF processing artifact less than 300K - gifsicle (free download)
Help change the socket position of PCB part
Valentine's Day - make an exclusive digital collection for your lover
Pecan — @expose()