draw_point.cpp 1.7 KB

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