当前位置:网站首页>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);
}
如此即可绘制出一个圆形。
边栏推荐
猜你喜欢
[Ryerson emotional speaking/singing audiovisual dataset (RAVDESS)]
if,case,for,while
Hey, I had another fight with HR in the small group!
ADC噪声全面分析 -03- 利用噪声分析进行实际设计
docker安装mysql与宿主机相差8小时的问题。
JVM笔记
if,case,for,while
Significant differences between Oracle and Postgresql in PLSQL transaction rollback
PL/SQL Some Advanced Fundamental
小程序 + 电商,玩转新零售
随机推荐
劝退背后。
【 observe 】 super fusion: the first mention of "calculate net nine order" evaluation model, build open prosperity of power network
嵌入式数据库开发编程MySQL(全)
数据治理平台项目总结和分析
Mini program + e-commerce, fun new retail
Oracle与Postgresql在PLSQL内事务回滚的重大差异
How to simplify the automation of modern e-procurement?
马尔可夫链
7-2 LVS+DR Overview and Deployment
7-3 LVS+Keepalived Cluster Description and Deployment
【Ryerson情感说话/歌唱视听数据集(RAVDESS) 】
7.LVS负载均衡群集之原理叙述
docker安装mysql与宿主机相差8小时的问题。
2022 Hangzhou Electric Power Multi-School League Game 5 Solution
Hangdian Multi-School-Slipper- (tree map conversion + virtual point mapping)
【21天学习挑战赛】图像的旋转问题(二维数组)
Converts XML tags to TXT format (voc conversion for yolo convenient training)
【21天学习挑战赛】直接插入排序
图像处理之Bolb分析(一)
share总结