draw_floor.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. float old_line_width =0;
  9. glGetIntegerv(GL_LIGHTING,&old_lighting);
  10. glGetIntegerv(GL_COLOR_MATERIAL,&old_color_material);
  11. glGetFloatv(GL_LINE_WIDTH,&old_line_width);
  12. glDisable(GL_LIGHTING);
  13. glColorMaterial( GL_FRONT, GL_EMISSION);
  14. glEnable(GL_COLOR_MATERIAL);
  15. glColorMaterial( GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
  16. // Set material
  17. const float black[] = {0.,0.,0.,1.};
  18. glMaterialfv(GL_FRONT, GL_AMBIENT, black);
  19. glMaterialfv(GL_FRONT, GL_DIFFUSE, black);
  20. glMaterialfv(GL_FRONT, GL_SPECULAR, black);
  21. glMaterialfv(GL_FRONT, GL_EMISSION, black);
  22. glMaterialf(GL_FRONT, GL_SHININESS,0);
  23. const bool use_lighting = false;
  24. if(use_lighting)
  25. {
  26. glEnable(GL_LIGHTING);
  27. }else
  28. {
  29. glDisable(GL_LIGHTING);
  30. }
  31. int GridSizeX = 100;
  32. int GridSizeY = 100;
  33. //int GridSizeX = 5;
  34. //int GridSizeY = 5;
  35. float SizeX = 0.5f;
  36. float SizeY = 0.5f;
  37. glBegin(GL_QUADS);
  38. glNormal3f(0,1,0);
  39. for (int x =-GridSizeX/2;x<GridSizeX/2;++x)
  40. {
  41. for (int y =-GridSizeY/2;y<GridSizeY/2;++y)
  42. {
  43. if ((x+y)&0x00000001) //modulo 2
  44. {
  45. glColor4fv(colorA);
  46. }else
  47. {
  48. glColor4fv(colorB);
  49. }
  50. glVertex3f( x*SizeX,0,(y+1)*SizeY);
  51. glVertex3f((x+1)*SizeX,0,(y+1)*SizeY);
  52. glVertex3f((x+1)*SizeX,0, y*SizeY);
  53. glVertex3f( x*SizeX,0, y*SizeY);
  54. }
  55. }
  56. glEnd();
  57. glLineWidth(2.0f);
  58. glBegin(GL_LINES);
  59. for (int x =-GridSizeX/2;x<=GridSizeX/2;++x)
  60. {
  61. if(x!=(GridSizeX/2))
  62. {
  63. for(int s = -1;s<2;s+=2)
  64. {
  65. int y = s*(GridSizeY/2);
  66. int cy = y==(GridSizeY/2) ? y-1 : y;
  67. if ((x+cy)&0x00000001) //modulo 2
  68. {
  69. glColor4fv(colorA);
  70. //glColor3f(1,0,0);
  71. }else
  72. {
  73. glColor4fv(colorB);
  74. //glColor3f(0,0,1);
  75. }
  76. glVertex3f((x+1)*SizeX,0,y*SizeY);
  77. glVertex3f( x*SizeX,0,y*SizeY);
  78. }
  79. }
  80. if(x==-(GridSizeX/2) || x==(GridSizeX/2))
  81. {
  82. int cx = x==(GridSizeX/2) ? x-1 : x;
  83. for (int y =-GridSizeY/2;y<GridSizeY/2;++y)
  84. {
  85. if ((cx+y)&0x00000001) //modulo 2
  86. {
  87. glColor4fv(colorA);
  88. //glColor3f(1,0,0);
  89. }else
  90. {
  91. glColor4fv(colorB);
  92. //glColor3f(0,0,1);
  93. }
  94. glVertex3f(x*SizeX,0,(y+1)*SizeY);
  95. glVertex3f(x*SizeX,0, y*SizeY);
  96. }
  97. }
  98. }
  99. glEnd();
  100. (old_lighting ? glEnable(GL_LIGHTING) : glDisable(GL_LIGHTING));
  101. (old_color_material? glEnable(GL_COLOR_MATERIAL) : glDisable(GL_COLOR_MATERIAL));
  102. glLineWidth(old_line_width);
  103. }
  104. IGL_INLINE void igl::draw_floor()
  105. {
  106. const float grey[] = {0.80,0.80,0.80,1.};
  107. const float white[] = {0.95,0.95,0.95,1.};
  108. igl::draw_floor(grey,white);
  109. }
  110. #endif