Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.09 KB | None | 0 0
  1. #include "GLAux.h"
  2. #include "glut.h"
  3. #include "stdio.h"
  4.  
  5.  
  6. #pragma comment(lib, "opengl32.lib")
  7. #pragma comment(lib, "glut32.lib")
  8. #pragma comment(lib, "glaux.lib")
  9. float re,we,qe,te,fe,ge;
  10. float map [40][40];
  11.  
  12. int x,y;
  13. int x0,y0;
  14. float max=0,min=0;
  15.  
  16. unsigned int grass, road, wood;
  17.  
  18. void RenderScene() {
  19. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  20.  
  21. glViewport(0, 0, 600, 600);
  22. glMatrixMode(GL_PROJECTION);
  23. glLoadIdentity();
  24. gluPerspective(45.0f, 1.0f, 0.1f, 100.0f);
  25. glMatrixMode(GL_MODELVIEW);
  26. glLoadIdentity();
  27.  
  28.  
  29.  
  30. glTranslatef(0, 0, te - 70);
  31. glRotatef(re, 0, 0, 1);
  32. glRotatef(we, 1, 0, 0);
  33. glRotatef(qe, 0, 1, 0);
  34. glEnable(GL_TEXTURE_2D);
  35.  
  36.  
  37. glBindTexture(GL_TEXTURE_2D, grass);
  38. glBegin(GL_QUADS);
  39. glTexCoord2f(1, 1);
  40. glVertex3f(20,20,0);
  41. glTexCoord2f(1,0);
  42. glVertex3f(20,-20,0);
  43. glTexCoord2f(0,0);
  44. glVertex3f(-20,-20,0);
  45. glTexCoord2f(0,1);
  46. glVertex3f(-20,20,0);
  47. glEnd();
  48.  
  49.  
  50.  
  51. glBindTexture(GL_TEXTURE_2D, road);
  52. glBegin(GL_QUADS);
  53. glTexCoord2f(1, 1);
  54. glVertex3f(10, 20, 0.01);
  55. glTexCoord2f(0, 1);
  56. glVertex3f(0, 20, 0.01);
  57. glTexCoord2f(0, 0);
  58. glVertex3f(0, -20, 0.01);
  59. glTexCoord2f(1, 0);
  60. glVertex3f(10, -20, 0.01);
  61. glEnd();
  62.  
  63.  
  64.  
  65. glBindTexture(GL_TEXTURE_2D, wood);
  66. glBegin(GL_QUADS);
  67. glTexCoord2f(1, 1);
  68. glVertex3f(-8, 12, 0.01);
  69. glTexCoord2f(0, 1);
  70. glVertex3f(-12, 12, 0.01);
  71. glTexCoord2f(0, 0);
  72. glVertex3f(-12, 8, 0.01);
  73. glTexCoord2f(1, 0);
  74. glVertex3f(-8, 8, 0.01);
  75. glEnd();
  76. glBegin(GL_QUADS);
  77. glTexCoord2f(1, 1);
  78. glVertex3f(-8, 12, 0.01);
  79. glTexCoord2f(0, 1);
  80. glVertex3f(-8, 12, 3.01);
  81. glTexCoord2f(0, 0);
  82. glVertex3f(-12, 12, 3.01);
  83. glTexCoord2f(1, 0);
  84. glVertex3f(-12, 12, 0.01);
  85. glEnd();
  86. glBegin(GL_QUADS);
  87. glTexCoord2f(1, 1);
  88. glVertex3f(-12, 12, 0.01);
  89. glTexCoord2f(0, 1);
  90. glVertex3f(-12, 12, 3.01);
  91. glTexCoord2f(0, 0);
  92. glVertex3f(-12, 8, 3.01);
  93. glTexCoord2f(1, 0);
  94. glVertex3f(-12, 8, 0.01);
  95. glEnd();
  96. glBegin(GL_QUADS);
  97. glTexCoord2f(1, 1);
  98. glVertex3f(-12, 8, 0.01);
  99. glTexCoord2f(0, 1);
  100. glVertex3f(-12, 8, 3.01);
  101. glTexCoord2f(0, 0);
  102. glVertex3f(-8, 8, 3.01);
  103. glTexCoord2f(1, 0);
  104. glVertex3f(-8, 8, 0.01);
  105. glEnd();
  106. glBegin(GL_QUADS);
  107. glTexCoord2f(1, 1);
  108. glVertex3f(-8, 8, 0.01);
  109. glTexCoord2f(0, 1);
  110. glVertex3f(-8, 8, 3.01);
  111. glTexCoord2f(0, 0);
  112. glVertex3f(-8, 12, 3.01);
  113. glTexCoord2f(1, 0);
  114. glVertex3f(-8, 12, 0.01);
  115. glEnd();
  116. glBegin(GL_QUADS);
  117. glTexCoord2f(1, 1);
  118. glVertex3f(-8, 12, 3.01);
  119. glTexCoord2f(0, 1);
  120. glVertex3f(-12, 12, 3.01);
  121. glTexCoord2f(0, 0);
  122. glVertex3f(-12, 8, 3.01);
  123. glTexCoord2f(1, 0);
  124. glVertex3f(-8, 8, 3.01);
  125. glEnd();
  126.  
  127.  
  128. glDisable(GL_TEXTURE_2D);
  129. glColor3f(0, 1, 0);
  130. //первая елка
  131. glPushMatrix();
  132. glTranslatef(-10, -15, 3);
  133. glutSolidCone(5, 10, 10, 10);
  134. glPopMatrix();
  135.  
  136. glPushMatrix();
  137. glTranslatef(-10, -15, 9);
  138. glutSolidCone(5, 6, 6, 6);
  139. glPopMatrix();
  140.  
  141. //вторая
  142. glPushMatrix();
  143. glTranslatef(-10, 10, 3);
  144. glutSolidCone(5, 10, 10, 10);
  145. glPopMatrix();
  146.  
  147. glPushMatrix();
  148. glTranslatef(-10, 10, 9);
  149. glutSolidCone(5, 6, 6, 6);
  150. glPopMatrix();
  151.  
  152. glPushMatrix();
  153. glColor3f(0.51, 0.25, 0);
  154. glTranslatef(-10, -15, 1.51);
  155. glutSolidCube(3);
  156. glPopMatrix();
  157.  
  158.  
  159. //снег
  160. glPushMatrix();
  161. glColor3f(1, 1, 1);
  162. glTranslatef(15, -5, 3);
  163. glutSolidSphere(3, 5, 5);
  164. glPopMatrix();
  165.  
  166. glPushMatrix();
  167. glColor3f(1, 1, 1);
  168. glTranslatef(15, -5, 6.5);
  169. glutSolidSphere(2, 5, 5);
  170. glPopMatrix();
  171.  
  172. glPushMatrix();
  173. glColor3f(1, 1, 1);
  174. glTranslatef(15, -5, 9);
  175. glutSolidSphere(1, 5, 5);
  176. glPopMatrix();
  177.  
  178.  
  179.  
  180. glPushMatrix();
  181. glColor3f(1, 1, 1);
  182. glTranslatef(15, -5, 1);
  183. glutSolidCube(1);
  184. glPopMatrix();
  185.  
  186. glutSwapBuffers();
  187. }
  188. void ReadKeyBoard(unsigned char key, int, int) //считываем клавишу
  189. {
  190. if (key=='q') //нажав q поворот на 15 градусов вокруг z
  191. re+=15;
  192. if (key=='e')//вокруг x
  193. we-=15;
  194. if (key=='w')//вокруг y
  195. qe-=15;
  196. if (key==27) exit(0);
  197. if (key=='='){
  198. if ((te+1)<0)
  199. te+=1;
  200. }
  201.  
  202. if (key=='-')
  203. te-=1;
  204. glutPostRedisplay();
  205. }
  206.  
  207. /*void Idle()
  208. {
  209. ge-=0.1;
  210.  
  211. }*/
  212. void Mouse1(int button, int state, int x, int y)
  213. {
  214. if (state==GLUT_DOWN)
  215. {
  216. x0=x;
  217. y0=y;
  218. }
  219. }
  220. void Mouse2(int x, int y)
  221. {
  222. we=y-y0;
  223. qe=x-x0;
  224. glutPostRedisplay();
  225. }
  226.  
  227.  
  228. int main(int argc, char *argv[]) {
  229.  
  230. glutInit(&argc, argv);
  231. glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
  232. glutInitWindowPosition(100, 100);
  233. glutInitWindowSize(600, 600);
  234. glutCreateWindow("Пример вывода 3D графики");
  235. glEnable(GL_DEPTH_TEST);
  236. glClearColor(0, 0, 0, 1);
  237.  
  238. AUX_RGBImageRec *p_texture = auxDIBImageLoad("grass_02.bmp");
  239. glGenTextures(1, &grass);
  240. glBindTexture(GL_TEXTURE_2D, grass);
  241. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  242. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  243. glTexImage2D(GL_TEXTURE_2D, 0, 3, p_texture->sizeX, p_texture->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, p_texture->data);
  244.  
  245.  
  246. p_texture = auxDIBImageLoad("roof_03.bmp");
  247. glGenTextures(1, &road);
  248. glBindTexture(GL_TEXTURE_2D, road);
  249. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  250. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  251. glTexImage2D(GL_TEXTURE_2D, 0, 3, p_texture->sizeX, p_texture->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, p_texture->data);
  252.  
  253.  
  254. p_texture = auxDIBImageLoad("roof_03.bmp");
  255. glGenTextures(1, &wood);
  256. glBindTexture(GL_TEXTURE_2D, wood);
  257. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  258. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  259. glTexImage2D(GL_TEXTURE_2D, 0, 3, p_texture->sizeX, p_texture->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, p_texture->data);
  260.  
  261. glEnable(GL_TEXTURE_2D);
  262.  
  263. glutDisplayFunc(RenderScene);
  264. //glEnable(GL_LIGHTING);
  265. //glEnable(GL_LIGHT0);
  266.  
  267. // glutIdleFunc(Idle);
  268. glutKeyboardFunc(ReadKeyBoard);
  269. glutMouseFunc(Mouse1);
  270. glutMotionFunc(Mouse2);
  271.  
  272. glutMainLoop();
  273.  
  274. return 0;
  275. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement