draw_rectangular_marquee.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. #ifndef IGL_NO_OPENGL
  9. #include "draw_rectangular_marquee.h"
  10. #include "OpenGL_convenience.h"
  11. #include "material_colors.h"
  12. IGL_INLINE void igl::draw_rectangular_marquee(
  13. const int from_x,
  14. const int from_y,
  15. const int to_x,
  16. const int to_y)
  17. {
  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. }
  57. #endif