draw_rectangular_marquee.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 igl;
  18. using namespace std;
  19. int l;
  20. glGetIntegerv(GL_LIGHTING,&l);
  21. int s;
  22. glGetIntegerv(GL_LINE_STIPPLE,&s);
  23. double lw;
  24. glGetDoublev(GL_LINE_WIDTH,&lw);
  25. glDisable(GL_LIGHTING);
  26. // Screen space for this viewport
  27. GLint viewport[4];
  28. glGetIntegerv(GL_VIEWPORT,viewport);
  29. const int width = viewport[2];
  30. const int height = viewport[3];
  31. glMatrixMode(GL_PROJECTION);
  32. glPushMatrix();
  33. glLoadIdentity();
  34. gluOrtho2D(0,width,0,height);
  35. glMatrixMode(GL_MODELVIEW);
  36. glPushMatrix();
  37. glLoadIdentity();
  38. glEnable(GL_LINE_STIPPLE);
  39. glLineStipple(3,0xAAAA);
  40. glLineWidth(1);
  41. glColor4f(0.2,0.2,0.2,1);
  42. glBegin(GL_LINE_STRIP);
  43. glVertex2d(from_x,from_y);
  44. glVertex2d(to_x,from_y);
  45. glVertex2d(to_x,to_y);
  46. glVertex2d(from_x,to_y);
  47. glVertex2d(from_x,from_y);
  48. glEnd();
  49. glPopMatrix();
  50. glMatrixMode(GL_PROJECTION);
  51. glPopMatrix();
  52. glMatrixMode(GL_MODELVIEW);
  53. glLineWidth(lw);
  54. (s ? glEnable(GL_LINE_STIPPLE):glDisable(GL_LINE_STIPPLE));
  55. (l ? glEnable(GL_LIGHTING):glDisable(GL_LIGHTING));
  56. }