Advertisement
Guest User

DrawBox

a guest
Apr 15th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. static void
  2. drawBox(GLfloat size, GLenum type)
  3. {
  4. static GLfloat n[6][3] =
  5. {
  6. {-1.0, 0.0, 0.0},
  7. {0.0, 1.0, 0.0},
  8. {1.0, 0.0, 0.0},
  9. {0.0, -1.0, 0.0},
  10. {0.0, 0.0, 1.0},
  11. {0.0, 0.0, -1.0}
  12. };
  13. static GLint faces[6][4] =
  14. {
  15. {0, 1, 2, 3},
  16. {3, 2, 6, 7},
  17. {7, 6, 5, 4},
  18. {4, 5, 1, 0},
  19. {5, 6, 2, 1},
  20. {7, 4, 0, 3}
  21. };
  22. GLfloat v[8][3];
  23. GLint i;
  24.  
  25. v[0][0] = v[1][0] = v[2][0] = v[3][0] = -size / 2;
  26. v[4][0] = v[5][0] = v[6][0] = v[7][0] = size / 2;
  27. v[0][1] = v[1][1] = v[4][1] = v[5][1] = -size / 2;
  28. v[2][1] = v[3][1] = v[6][1] = v[7][1] = size / 2;
  29. v[0][2] = v[3][2] = v[4][2] = v[7][2] = -size / 2;
  30. v[1][2] = v[2][2] = v[5][2] = v[6][2] = size / 2;
  31.  
  32. for (i = 5; i >= 0; i--) {
  33. glBegin(type);
  34. glNormal3fv(&n[i][0]);
  35. glVertex3fv(&v[faces[i][0]][0]);
  36. glVertex3fv(&v[faces[i][1]][0]);
  37. glVertex3fv(&v[faces[i][2]][0]);
  38. glVertex3fv(&v[faces[i][3]][0]);
  39. glEnd();
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement