Advertisement
Guest User

Untitled

a guest
Feb 28th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 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. 0.0f, 0.0f, 0.0f, 1.0f,
  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. 1.0f, 0.0f, 0.0f, 1.0f,
  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. initializeOpenGLFunctions();
  53. vao_ = new QOpenGLVertexArrayObject(0);
  54. vao_->create(); //
  55. // glGenVertexArrays(1, &vao_);
  56. vao_->bind();
  57. // glBindVertexArray(vao_);
  58.  
  59. glGenBuffers(1, &vertices_);
  60. glBindBuffer(GL_ARRAY_BUFFER, vertices_);
  61. glBufferData(GL_ARRAY_BUFFER, sizeof(VERTICES), VERTICES, GL_STATIC_DRAW);
  62. glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
  63. glEnableVertexAttribArray(0);
  64.  
  65. glGenBuffers(1, &colors_);
  66. glBindBuffer(GL_ARRAY_BUFFER, colors_);
  67. glBufferData(GL_ARRAY_BUFFER, sizeof(COLORS), COLORS, GL_STATIC_DRAW);
  68. glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, 0);
  69. glEnableVertexAttribArray(1);
  70.  
  71. }
  72.  
  73.  
  74. void star::Draw(Program * prog){
  75. glEnable(GL_DEPTH_TEST);
  76. glDepthFunc(GL_LESS);
  77. vao_->bind();
  78. // glBindVertexArray(m_triangle_vao);
  79.  
  80. glUseProgram(*prog);
  81.  
  82. glDrawArrays(GL_TRIANGLE_FAN, 0, 12);
  83.  
  84. glUseProgram(0);
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement