draw_rectangular_marquee.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "draw_rectangular_marquee.h"
  2. #include "OpenGL_convenience.h"
  3. #include "material_colors.h"
  4. void igl::draw_rectangular_marquee(
  5. const int from_x,
  6. const int from_y,
  7. const int to_x,
  8. const int to_y)
  9. {
  10. using namespace igl;
  11. using namespace std;
  12. int l;
  13. glGetIntegerv(GL_LIGHTING,&l);
  14. int s;
  15. glGetIntegerv(GL_LINE_STIPPLE,&s);
  16. double lw;
  17. glGetDoublev(GL_LINE_WIDTH,&lw);
  18. glDisable(GL_LIGHTING);
  19. // Screen space for this viewport
  20. GLint viewport[4];
  21. glGetIntegerv(GL_VIEWPORT,viewport);
  22. const int width = viewport[2];
  23. const int height = viewport[3];
  24. glMatrixMode(GL_PROJECTION);
  25. glPushMatrix();
  26. glLoadIdentity();
  27. gluOrtho2D(0,width,0,height);
  28. glMatrixMode(GL_MODELVIEW);
  29. glPushMatrix();
  30. glLoadIdentity();
  31. glEnable(GL_LINE_STIPPLE);
  32. glLineStipple(3,0xAAAA);
  33. glLineWidth(1);
  34. glColor4f(0.2,0.2,0.2,1);
  35. glBegin(GL_LINE_STRIP);
  36. glVertex2d(from_x,from_y);
  37. glVertex2d(to_x,from_y);
  38. glVertex2d(to_x,to_y);
  39. glVertex2d(from_x,to_y);
  40. glVertex2d(from_x,from_y);
  41. glEnd();
  42. glPopMatrix();
  43. glMatrixMode(GL_PROJECTION);
  44. glPopMatrix();
  45. glMatrixMode(GL_MODELVIEW);
  46. glLineWidth(lw);
  47. (s ? glEnable(GL_LINE_STIPPLE):glDisable(GL_LINE_STIPPLE));
  48. (l ? glEnable(GL_LIGHTING):glDisable(GL_LIGHTING));
  49. }