draw_point.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include "draw_point.h"
  2. #ifndef IGL_NO_OPENGL
  3. // Implementation
  4. #include "OpenGL_convenience.h"
  5. #include <cassert>
  6. #include <cmath>
  7. IGL_INLINE void igl::draw_point(
  8. const double x,
  9. const double y,
  10. const double z,
  11. const double requested_r,
  12. const bool selected)
  13. {
  14. // Push GL settings
  15. //GLboolean old_depth_test;
  16. //glGetBooleanv(GL_DEPTH_TEST,&old_depth_test);
  17. GLboolean old_lighting;
  18. glGetBooleanv(GL_LIGHTING,&old_lighting);
  19. float f;
  20. glGetFloatv(GL_POINT_SIZE_MAX,&f);
  21. assert(requested_r<=0.5*f);
  22. double r = (requested_r<0.5*f?requested_r:0.5*f);
  23. //glDisable(GL_DEPTH_TEST);
  24. glDisable(GL_LIGHTING);
  25. // get current color
  26. float color[4];
  27. glGetFloatv(GL_CURRENT_COLOR,color);
  28. double outline_size = (r>7 ? sqrt(r/7.0) : 1.0);
  29. // White outline
  30. glColor4f(1,1,1,color[3]);
  31. glPointSize(2*r);
  32. glBegin(GL_POINTS);
  33. glVertex3d(x,y,z);
  34. glEnd();
  35. // Black outline
  36. glColor4f(0,0,0,color[3]);
  37. glPointSize(2*r-2*outline_size);
  38. glBegin(GL_POINTS);
  39. glVertex3d(x,y,z);
  40. glEnd();
  41. // Foreground
  42. glColor4fv(color);
  43. glPointSize(2*r-4*outline_size);
  44. glBegin(GL_POINTS);
  45. glVertex3d(x,y,z);
  46. glEnd();
  47. // Selection inner circle
  48. if(selected)
  49. {
  50. glColor4f(0,0,0,color[3]);
  51. double selected_size = 2*r-7*outline_size;
  52. selected_size = (selected_size>3?selected_size:3);
  53. glPointSize(selected_size);
  54. glBegin(GL_POINTS);
  55. glVertex3d(x,y,z);
  56. glEnd();
  57. }
  58. // reset color
  59. glColor4fv(color);
  60. // Pop GL settings
  61. if(old_lighting) glEnable(GL_LIGHTING);
  62. //if(old_depth_test) glEnable(GL_DEPTH_TEST);
  63. }
  64. #endif