draw_rectangular_marquee.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #include "draw_rectangular_marquee.h"
  9. #include "OpenGL_convenience.h"
  10. #include "material_colors.h"
  11. IGL_INLINE void igl::draw_rectangular_marquee(
  12. const int from_x,
  13. const int from_y,
  14. const int to_x,
  15. const int to_y)
  16. {
  17. using namespace std;
  18. int l;
  19. glGetIntegerv(GL_LIGHTING,&l);
  20. int s;
  21. glGetIntegerv(GL_LINE_STIPPLE,&s);
  22. double lw;
  23. glGetDoublev(GL_LINE_WIDTH,&lw);
  24. glDisable(GL_LIGHTING);
  25. // Screen space for this viewport
  26. GLint viewport[4];
  27. glGetIntegerv(GL_VIEWPORT,viewport);
  28. const int width = viewport[2];
  29. const int height = viewport[3];
  30. glMatrixMode(GL_PROJECTION);
  31. glPushMatrix();
  32. glLoadIdentity();
  33. gluOrtho2D(0,width,0,height);
  34. glMatrixMode(GL_MODELVIEW);
  35. glPushMatrix();
  36. glLoadIdentity();
  37. glEnable(GL_LINE_STIPPLE);
  38. glLineStipple(3,0xAAAA);
  39. glLineWidth(1);
  40. glColor4f(0.2,0.2,0.2,1);
  41. glBegin(GL_LINE_STRIP);
  42. glVertex2d(from_x,from_y);
  43. glVertex2d(to_x,from_y);
  44. glVertex2d(to_x,to_y);
  45. glVertex2d(from_x,to_y);
  46. glVertex2d(from_x,from_y);
  47. glEnd();
  48. glPopMatrix();
  49. glMatrixMode(GL_PROJECTION);
  50. glPopMatrix();
  51. glMatrixMode(GL_MODELVIEW);
  52. glLineWidth(lw);
  53. (s ? glEnable(GL_LINE_STIPPLE):glDisable(GL_LINE_STIPPLE));
  54. (l ? glEnable(GL_LIGHTING):glDisable(GL_LIGHTING));
  55. }