Advertisement
Guest User

Untitled

a guest
Feb 28th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. #include "star.h"
  2. #include "glfunctions.h"
  3.  
  4. star::~star(){
  5. glDisableVertexAttribArray(1);
  6. glDisableVertexAttribArray(0);
  7.  
  8. vao_->release();
  9. // glBindBuffer(GL_ARRAY_BUFFER, 0);
  10.  
  11. glDeleteBuffers(1, &colors_);
  12. glDeleteBuffers(1, &vertices_);
  13.  
  14. vao_->destroy();
  15.  
  16. }
  17.  
  18. void star::Initialize(){
  19.  
  20. const float VERTICES[]={
  21.  
  22. 0.0f, 1.0f, 0.0f, 1.0f,
  23. 0.25f, 0.5f, 0.0f, 1.0f,
  24. 1.0f, 0.5f, 0.0f, 1.0f,
  25. 0.5f ,0.0f, 0.0f, 1.0f,
  26. 1.0f, -1.0f, 0.0f, 1.0f,
  27. 0.0f, -0.5f, 0.0f, 1.0f,
  28. -1.0f, -1.0f, 0.0f, 1.0f,
  29. -0.5f ,0.0f, 0.0f, 1.0f,
  30. -1.0f, 0.5f, 0.0f, 1.0f,
  31. -0.25f, 0.5f, 0.0f, 1.0f,
  32. 0.0f, 1.0f, 0.0f, 1.0f,
  33. };
  34.  
  35.  
  36. const float COLORS[]={
  37.  
  38. 1.0f, 0.0f, 0.0f, 1.0f,
  39. 1.0f, 0.0f, 0.0f, 1.0f,
  40. 1.0f, 0.0f, 0.0f, 1.0f,
  41. 1.0f, 0.0f, 0.0f, 1.0f,
  42. 1.0f, 0.0f, 0.0f, 1.0f,
  43. 1.0f, 0.0f, 0.0f, 1.0f,
  44. 1.0f, 0.0f, 0.0f, 1.0f,
  45. 1.0f, 0.0f, 0.0f, 1.0f,
  46. 1.0f, 0.0f, 0.0f, 1.0f,
  47. 1.0f, 0.0f, 0.0f, 1.0f,
  48. 1.0f, 0.0f, 0.0f, 1.0f,
  49.  
  50.  
  51.  
  52. };
  53. initializeOpenGLFunctions();
  54. vao_ = new QOpenGLVertexArrayObject(0);
  55. vao_->create(); //
  56. // glGenVertexArrays(1, &vao_);
  57. vao_->bind();
  58. // glBindVertexArray(vao_);
  59.  
  60. glGenBuffers(1, &vertices_);
  61. glBindBuffer(GL_ARRAY_BUFFER, vertices_);
  62. glBufferData(GL_ARRAY_BUFFER, sizeof(VERTICES), VERTICES, GL_STATIC_DRAW);
  63. glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
  64. glEnableVertexAttribArray(0);
  65.  
  66. glGenBuffers(1, &colors_);
  67. glBindBuffer(GL_ARRAY_BUFFER, colors_);
  68. glBufferData(GL_ARRAY_BUFFER, sizeof(COLORS), COLORS, GL_STATIC_DRAW);
  69. glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, 0);
  70. glEnableVertexAttribArray(1);
  71.  
  72. }
  73.  
  74.  
  75. void star::Draw(Program * prog){
  76. glEnable(GL_DEPTH_TEST);
  77. glDepthFunc(GL_LESS);
  78. vao_->bind();
  79. // glBindVertexArray(m_triangle_vao);
  80.  
  81. glUseProgram(*prog);
  82.  
  83. glDrawArrays(GL_LINE_LOOP, 0, 12);
  84.  
  85. glUseProgram(0);
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement