draw_floor.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include "draw_floor.h"
  2. #ifndef IGL_NO_OPENGL
  3. #include "OpenGL_convenience.h"
  4. IGL_INLINE void igl::draw_floor(const float * colorA, const float * colorB)
  5. {
  6. // old settings
  7. int old_lighting=0,old_color_material=0;
  8. glGetIntegerv(GL_LIGHTING,&old_lighting);
  9. glGetIntegerv(GL_COLOR_MATERIAL,&old_color_material);
  10. glDisable(GL_LIGHTING);
  11. glColorMaterial( GL_FRONT, GL_EMISSION);
  12. glEnable(GL_COLOR_MATERIAL);
  13. glColorMaterial( GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
  14. // Set material
  15. const float black[] = {0.,0.,0.,1.};
  16. glMaterialfv(GL_FRONT, GL_AMBIENT, black);
  17. glMaterialfv(GL_FRONT, GL_DIFFUSE, black);
  18. glMaterialfv(GL_FRONT, GL_SPECULAR, black);
  19. glMaterialfv(GL_FRONT, GL_EMISSION, black);
  20. glMaterialf(GL_FRONT, GL_SHININESS,0);
  21. const bool use_lighting = false;
  22. if(use_lighting)
  23. {
  24. glEnable(GL_LIGHTING);
  25. }else
  26. {
  27. glDisable(GL_LIGHTING);
  28. }
  29. int GridSizeX = 100;
  30. int GridSizeY = 100;
  31. float SizeX = 0.5f;
  32. float SizeY = 0.5f;
  33. glBegin(GL_QUADS);
  34. glNormal3f(0,1,0);
  35. for (int x =-GridSizeX/2;x<GridSizeX/2;++x)
  36. {
  37. for (int y =-GridSizeY/2;y<GridSizeY/2;++y)
  38. {
  39. if ((x+y)&0x00000001) //modulo 2
  40. {
  41. glColor4fv(colorA);
  42. }else
  43. {
  44. glColor4fv(colorB);
  45. }
  46. glVertex3f( x*SizeX,0,(y+1)*SizeY);
  47. glVertex3f((x+1)*SizeX,0,(y+1)*SizeY);
  48. glVertex3f((x+1)*SizeX,0, y*SizeY);
  49. glVertex3f( x*SizeX,0, y*SizeY);
  50. }
  51. }
  52. glEnd();
  53. (old_lighting ? glEnable(GL_LIGHTING) : glDisable(GL_LIGHTING));
  54. (old_color_material? glEnable(GL_COLOR_MATERIAL) : glDisable(GL_COLOR_MATERIAL));
  55. }
  56. IGL_INLINE void igl::draw_floor()
  57. {
  58. const float grey[] = {0.80,0.80,0.80,1.};
  59. const float white[] = {0.95,0.95,0.95,1.};
  60. igl::draw_floor(grey,white);
  61. }
  62. #endif