Advertisement
Guest User

Untitled

a guest
Feb 24th, 2015
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. struct Triangle {
  2. GLushort vertex[3];
  3. GLushort color[3];
  4. };
  5.  
  6. QOpenGLBuffer arrayBuf;
  7. QOpenGLBuffer indexBuf;
  8. QOpenGLBuffer colorBuf;
  9.  
  10. void init() {
  11. QVector3D vertices[] = {
  12. QVector3D(-1, -1, 1),
  13. QVector3D(1, -1, 1),
  14. QVector3D(1, 1, 1),
  15. QVector3D(-1, 1, 1),
  16.  
  17. QVector3D(1, -1, -1),
  18. QVector3D(-1, -1, -1),
  19. QVector3D(-1, 1, -1),
  20. QVector3D(1, 1, -1)
  21. };
  22.  
  23. QVector3D colors[] = {
  24. QVector3D(1,1,1),
  25. QVector3D(1,1,1),
  26. QVector3D(1,1,1)
  27. };
  28.  
  29. Triangle index[] = {
  30. {{0,1,2},{0,1,2}},
  31. {{2,3,0},{0,1,2}}
  32. };
  33.  
  34.  
  35. arrayBuf.bind();
  36. arrayBuf.allocate(vertices, sizeof(vertices));
  37.  
  38. colorBuf.bind();
  39. colorBuf.allocate(colors, sizeof(colors));
  40.  
  41. indexBuf.bind();
  42. indexBuf.allocate(index, sizeof(index));
  43. }
  44.  
  45. void draw(QOpenGLShaderProgram *program) {
  46. arrayBuf.bind();
  47. colorBuf.bind();
  48. indexBuf.bind();
  49.  
  50. // HERFRA SKURRER DET VELDIG
  51. int vertexLocation = program->attributeLocation("a_position");
  52. program->enableAttributeArray(vertexLocation);
  53. program->setAttributeBuffer(vertexLocation, GL_FLOAT, 0, 3, sizeof(QVector3D));
  54.  
  55. int colorLocation = program->attributeLocation("a_color");
  56. program->enableAttributeArray(colorLocation);
  57. program->setAttributeBuffer(colorLocation, GL_FLOAT, 1, 3, sizeof(QVector3D));
  58.  
  59. glDrawElements(GL_TRIANGLES, indexCount, GL_UNSIGNED_SHORT, 0);
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement