Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "star.h"
- #include "glfunctions.h"
- star::~star(){
- glDisableVertexAttribArray(1);
- glDisableVertexAttribArray(0);
- vao_->release();
- // glBindBuffer(GL_ARRAY_BUFFER, 0);
- glDeleteBuffers(1, &colors_);
- glDeleteBuffers(1, &vertices_);
- vao_->destroy();
- }
- void star::Initialize(){
- const float VERTICES[]={
- 0.0f, 0.0f, 0.0f, 1.0f,
- 0.0f, 1.0f, 0.0f, 1.0f,
- 0.25f, 0.5f, 0.0f, 1.0f,
- 1.0f, 0.5f, 0.0f, 1.0f,
- 0.5f ,0.0f, 0.0f, 1.0f,
- 1.0f, -1.0f, 0.0f, 1.0f,
- 0.0f, -0.5f, 0.0f, 1.0f,
- -1.0f, -1.0f, 0.0f, 1.0f,
- -0.5f ,0.0f, 0.0f, 1.0f,
- -1.0f, 0.5f, 0.0f, 1.0f,
- -0.25f, 0.5f, 0.0f, 1.0f,
- 0.0f, 1.0f, 0.0f, 1.0f,
- };
- const float COLORS[]={
- 1.0f, 0.0f, 0.0f, 1.0f,
- 1.0f, 0.0f, 0.0f, 1.0f,
- 1.0f, 0.0f, 0.0f, 1.0f,
- 1.0f, 0.0f, 0.0f, 1.0f,
- 1.0f, 0.0f, 0.0f, 1.0f,
- 1.0f, 0.0f, 0.0f, 1.0f,
- 1.0f, 0.0f, 0.0f, 1.0f,
- 1.0f, 0.0f, 0.0f, 1.0f,
- 1.0f, 0.0f, 0.0f, 1.0f,
- 1.0f, 0.0f, 0.0f, 1.0f,
- 1.0f, 0.0f, 0.0f, 1.0f,
- 1.0f, 0.0f, 0.0f, 1.0f,
- };
- initializeOpenGLFunctions();
- vao_ = new QOpenGLVertexArrayObject(0);
- vao_->create(); //
- // glGenVertexArrays(1, &vao_);
- vao_->bind();
- // glBindVertexArray(vao_);
- glGenBuffers(1, &vertices_);
- glBindBuffer(GL_ARRAY_BUFFER, vertices_);
- glBufferData(GL_ARRAY_BUFFER, sizeof(VERTICES), VERTICES, GL_STATIC_DRAW);
- glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
- glEnableVertexAttribArray(0);
- glGenBuffers(1, &colors_);
- glBindBuffer(GL_ARRAY_BUFFER, colors_);
- glBufferData(GL_ARRAY_BUFFER, sizeof(COLORS), COLORS, GL_STATIC_DRAW);
- glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, 0);
- glEnableVertexAttribArray(1);
- }
- void star::Draw(Program * prog){
- glEnable(GL_DEPTH_TEST);
- glDepthFunc(GL_LESS);
- vao_->bind();
- // glBindVertexArray(m_triangle_vao);
- glUseProgram(*prog);
- glDrawArrays(GL_TRIANGLE_FAN, 0, 12);
- glUseProgram(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement