当前位置:网站首页>OpenGL绘制圆
OpenGL绘制圆
2022-08-04 04:27:00 【后知后觉】
#include "circle.h"
#include <QTimer>
#include <QDateTime>
#include <QImage>
#include <QtMath>
#define POINT_COUNT (362)
static float vertices[POINT_COUNT*3];
Circle::Circle(QWidget* parent)
{
QTimer * timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
timer->start(17);
//center
vertices[0] = 0;
vertices[1] = 0;
vertices[2] = 0;
for(int i = 1; i <= POINT_COUNT - 1; i++) {
int index = i*3;
vertices[index] = sin(i * M_PI/ 180.0f);
vertices[index+1] = cos(i * M_PI/ 180.0f);
vertices[index+2] = 0;
}
}
void Circle::initializeGL()
{
bool enabled = initializeOpenGLFunctions();
qDebug() << "initializeGL" << enabled;
glGenVertexArrays(1, &mVAO);
glGenBuffers(1, &mVBO);
glBindVertexArray(mVAO);
glBindBuffer(GL_ARRAY_BUFFER, mVBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
mProgram.addShaderFromSourceFile(QOpenGLShader::Vertex, ":/shaders/circle.vsh");
mProgram.addShaderFromSourceFile(QOpenGLShader::Fragment, ":/shaders/circle.fsh");
bool success = mProgram.link();
if(!success){
qDebug() << "ERR: " << mProgram.log();
}
}
void Circle::resizeGL(int w, int h)
{
}
void Circle::paintGL()
{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
mProgram.bind();
glBindVertexArray(mVAO);
glDrawArrays(GL_TRIANGLE_FAN, 0, POINT_COUNT);
}
如此即可绘制出一个圆形。
边栏推荐
猜你喜欢
随机推荐
TL431的基本特性以及振荡电路
Jenkins export and import Job Pipeline
移动支付线上线下支付场景
杭电多校-Slipper-(树图转化+虚点建图)
MySQL query optimization and tuning
[21 Days Learning Challenge] Image rotation problem (two-dimensional array)
劝退背后。
【21天学习挑战赛】图像的旋转问题(二维数组)
Learn iframes and use them to solve cross-domain problems
将xml标签转换为txt(voc格式转换为yolo方便进行训练)
2022支付宝C2C现金红包PHP源码DEMO/兼容苹果/安卓浏览器和扫码形式
Gigabit 2 X light 8 electricity management industrial Ethernet switches WEB management - a key Ring Ring net switch
目标检测-中篇
Mobile payment online and offline payment scenarios
网络工程师入门必懂华为认证体系,附系统学习路线分享
How to keep the source code confidential in the development under the burning scenario
看DevExpress丰富图表样式,如何为基金公司业务创新赋能
7-2 LVS+DR Overview and Deployment
马尔可夫链
如何动态添加script依赖的脚本









