当前位置:网站首页>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);
}
如此即可绘制出一个圆形。
边栏推荐
- Hangdian Multi-School-Slipper- (tree map conversion + virtual point mapping)
- Mini program + e-commerce, fun new retail
- 【机器学习】21天挑战赛学习笔记(一)
- JVM Notes
- 【id类型和NSObject指针 ObjectIve-C中】
- Hey, I had another fight with HR in the small group!
- 深度学习——以CNN服装图像分类为例,探讨怎样评价神经网络模型
- pnpm 是凭什么对 npm 和 yarn 降维打击的
- 7-2 LVS+DR概述与部署
- 复现20字符短域名绕过
猜你喜欢
随机推荐
Senior PHP development case (1) : use MYSQL statement across the table query cannot export all records of the solution
外卖店优先级
文件系统的简单操作
FFmpeg —— 录制麦克风声音(附源码)
内网服务器访问远程服务器的端口映射
使用serve搭建本地服务器
【机器学习】21天挑战赛学习笔记(一)
出现504怎么办?由于服务器更新导致的博客报504错误[详细记录]
Learn iframes and use them to solve cross-domain problems
拿捏JVM性能优化(自己笔记版本)
深度学习——以CNN服装图像分类为例,探讨怎样评价神经网络模型
移动支付线上线下支付场景
sql语句查询String类型字段小于10的怎么查
【id类型和NSObject指针 ObjectIve-C中】
[Skill] Using Sentinel to achieve priority processing of requests
XSS相关知识点
3000字,一文带你搞懂机器学习!
【21天学习挑战赛】顺序查找
马尔可夫链
张量篇-应用案例