draw_point.cpp 1.8 KB

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