Guest User

Untitled

a guest
Jan 17th, 2019
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.35 KB | None | 0 0
  1. void Fragment::generateFragment(glm::vec3 fPos, glm::vec3 fAng){
  2.  
  3. renderAng = fAng;
  4. renderPos = fPos;
  5.  
  6. //create a single fragment
  7. for(int x = 0; x <FRAGMENTSIZE; x++) {
  8. for(int y = 0; y <FRAGMENTSIZE; y++){
  9. for(int z = 0; z<FRAGMENTSIZE; z++){
  10.  
  11.  
  12. fragment[x][y][z] = 1;
  13.  
  14. }
  15. }
  16.  
  17. }
  18.  
  19. int render = 0;
  20.  
  21. // initate vectors to store the information about the visible faces
  22. std::vector<GLfloat> chunkVertices;
  23. std::vector<GLfloat> chunkNormals;
  24. std::vector<GLfloat> chunkTextures;
  25.  
  26. //analyze each face to see if its visible
  27. for(int x = 0; x <FRAGMENTSIZE; x++) {
  28. for(int y = 0; y<FRAGMENTSIZE; y++){
  29. for(int z = 0; z<FRAGMENTSIZE; z++){
  30.  
  31. if(fragment[x][y][z] != 0) {
  32. render = 0;
  33. if(fragment[x+1][y][z]==0 || x == FRAGMENTSIZE-1) {
  34. renderVisible[renderIndex][0]=1;
  35. render=1;
  36. }
  37. if(fragment[x-1][y][z]==0 || x == 0) {
  38. renderVisible[renderIndex][1]=1;
  39. render=1;
  40. }
  41. if(fragment[x][y+1][z]==0 || y == FRAGMENTSIZE-1) {
  42. renderVisible[renderIndex][5]=1;
  43. render=1;
  44. }
  45. if(fragment[x][y-1][z]==0 || y == 0) {
  46. renderVisible[renderIndex][4]=1;
  47. render=1;
  48. }
  49. if(fragment[x][y][z+1]==0 || z == FRAGMENTSIZE-1) {
  50. renderVisible[renderIndex][3]=1;
  51. render=1;
  52. }
  53. if(fragment[x][y][z-1]==0 || z == 0) {
  54. renderVisible[renderIndex][2]=1;
  55. render=1;
  56. }
  57.  
  58. int side = 0;
  59. int draw = 0;
  60. int sideadd = 0;
  61.  
  62. // if one or more faces are visible
  63. if(render) {
  64. for(int idx = 0; idx < 6; idx++) {
  65. draw = renderVisible[renderIndex][idx];
  66.  
  67. if(draw) {
  68.  
  69. // adding texture points
  70. for(int i = idx*6; i < idx*6+6; i++) {
  71. chunkTextures.push_back(texture_data[i]);
  72. }
  73.  
  74. // adding surface normals and vertexes
  75. // sideadd variable is used to insert the proper coordinates into each face
  76. for(int i = idx*12; i < idx*12+12; i++) {
  77.  
  78. switch(side) {
  79. case 0:
  80. sideadd = x;
  81. break;
  82. case 1:
  83. sideadd = y;
  84. break;
  85. case 2:
  86. sideadd = z;
  87. break;
  88. }
  89.  
  90. chunkVertices.push_back(vertice_data[i]+sideadd);
  91. chunkNormals.push_back(normals[i]);
  92.  
  93. side++; if(side>2) {side=0;}
  94. }
  95. }
  96. }
  97. }
  98. }
  99. } // z
  100. } // y
  101. } // x
  102.  
  103.  
  104. // converting the vectors to buffers that can be drawn in the main rendering loop
  105. glGenBuffers(1, &normalbuf);
  106. glBindBuffer(GL_ARRAY_BUFFER, normalbuf);
  107. glBufferData(GL_ARRAY_BUFFER, chunkNormals.size()*sizeof(chunkNormals[0]), &chunkNormals, GL_STATIC_DRAW);
  108.  
  109.  
  110. glGenBuffers(1, &vertexbuf);
  111. glBindBuffer(GL_ARRAY_BUFFER, vertexbuf);
  112. glBufferData(GL_ARRAY_BUFFER, chunkVertices.size()*sizeof(chunkVertices[0]), &chunkVertices, GL_STATIC_DRAW);
  113.  
  114.  
  115. glGenBuffers(1, &uvbuf);
  116. glBindBuffer(GL_ARRAY_BUFFER, uvbuf);
  117. glBufferData(GL_ARRAY_BUFFER, chunkTextures.size()*sizeof(chunkTextures[0]), &chunkTextures, GL_STATIC_DRAW);
  118. }
  119.  
  120. First-chance exception at 0x69977420 in minecraft.exe: 0xC0000005: Access violation reading location 0x00300000.
  121. Unhandled exception at 0x77a415de (ntdll.dll) in minecraft.exe: 0xC0000005: Access violation reading location 0x00300000.
  122.  
  123. static const GLfloat texture_data[] = {
  124. //right
  125. 0.66f, 1.0f,
  126. 0.33f, 0.5f,
  127. 0.33f, 1.0f,
  128.  
  129. //right
  130. 0.33f, 0.5f,
  131. 0.66f, 1.0f,
  132. 0.66f, 0.5f,
  133.  
  134. //left
  135. 0.0f, 0.0f,
  136. 0.33f, 0.0f,
  137. 0.33f, 0.5f,
  138.  
  139. //left
  140. 0.0f, 0.0f,
  141. 0.33f, 0.5f,
  142. 0.0f, 0.5f,
  143.  
  144. // rear
  145. 0.33f, 0.5f,
  146. 0.66f, 0.0f,
  147. 0.66f, 0.5f,
  148.  
  149. //rear
  150. 0.33f, 0.5f,
  151. 0.33f, 0.0f,
  152. 0.66f, 0.0f,
  153.  
  154. //front
  155. 0.33f, 1.0f,
  156. 0.33f, 0.5f,
  157. 0.0f, 0.5f,
  158.  
  159. //front
  160. 0.0f, 1.0f,
  161. 0.33f, 1.0f,
  162. 0.0f, 0.5f,
  163.  
  164. //bottom
  165. 1.0f, 0.5f,
  166. 0.666f, 0.0f,
  167. 1.0f, 0.0f,
  168.  
  169. //bottom
  170. 1.0f, 0.5f,
  171. 0.666f, 0.5f,
  172. 0.666f, 0.0f,
  173.  
  174. // top
  175. 0.6666f, 0.5f,
  176. 0.666f, 1.0f,
  177. 1.0f, 1.0f,
  178.  
  179. // top
  180. 0.6666f, 0.5f,
  181. 1.00f, 1.0f,
  182. 1.00f, 0.5f
  183.  
  184.  
  185. };
  186. static const GLfloat vertice_data[] = {
  187. //right
  188. 1.0f, 1.0f, 1.0f,
  189. 1.0f,-1.0f,-1.0f,
  190. 1.0f, 1.0f,-1.0f,
  191.  
  192. //right
  193. 1.0f,-1.0f,-1.0f,
  194. 1.0f, 1.0f, 1.0f,
  195. 1.0f,-1.0f, 1.0f,
  196.  
  197. //left
  198. -1.0f,-1.0f,-1.0f,
  199. -1.0f,-1.0f, 1.0f,
  200. -1.0f, 1.0f, 1.0f,
  201.  
  202. //left
  203. -1.0f,-1.0f,-1.0f,
  204. -1.0f, 1.0f, 1.0f,
  205. -1.0f, 1.0f,-1.0f,
  206.  
  207.  
  208. //rear
  209. 1.0f, 1.0f,-1.0f,
  210. -1.0f,-1.0f,-1.0f,
  211. -1.0f, 1.0f,-1.0f,
  212.  
  213. //rear
  214. 1.0f, 1.0f,-1.0f,
  215. 1.0f,-1.0f,-1.0f,
  216. -1.0f,-1.0f,-1.0f,
  217.  
  218. //front
  219. -1.0f, 1.0f, 1.0f,
  220. -1.0f,-1.0f, 1.0f,
  221. 1.0f,-1.0f, 1.0f,
  222.  
  223. //front
  224. 1.0f, 1.0f, 1.0f,
  225. -1.0f, 1.0f, 1.0f,
  226. 1.0f,-1.0f, 1.0f,
  227.  
  228. //bottom
  229. 1.0f,-1.0f, 1.0f,
  230. -1.0f,-1.0f,-1.0f,
  231. 1.0f,-1.0f,-1.0f,
  232.  
  233. //bottom
  234. 1.0f,-1.0f, 1.0f,
  235. -1.0f,-1.0f, 1.0f,
  236. -1.0f,-1.0f,-1.0f,
  237.  
  238. //top
  239. 1.0f, 1.0f, 1.0f,
  240. 1.0f, 1.0f,-1.0f,
  241. -1.0f, 1.0f,-1.0f,
  242.  
  243. //top
  244. 1.0f, 1.0f, 1.0f,
  245. -1.0f, 1.0f,-1.0f,
  246. -1.0f, 1.0f, 1.0f
  247.  
  248.  
  249.  
  250. };
  251. static const GLfloat normals[] = {
  252. //right
  253. 1.0f, 0.0f, 0.0f,
  254. 1.0f, 0.0f, 0.0f,
  255. 1.0f, 0.0f, 0.0f,
  256. //right
  257. 1.0f, 0.0f, 0.0f,
  258. 1.0f, 0.0f, 0.0f,
  259. 1.0f, 0.0f, 0.0f,
  260.  
  261. //left
  262. -1.0f, 0.0f, 0.0f,
  263. -1.0f, 0.0f, 0.0f,
  264. -1.0f, 0.0f, 0.0f,
  265. //left
  266. -1.0f, 0.0f, 0.0f,
  267. -1.0f, 0.0f, 0.0f,
  268. -1.0f, 0.0f, 0.0f,
  269.  
  270. //rear
  271. 0.0f, 0.0f, -1.0f,
  272. 0.0f, 0.0f, -1.0f,
  273. 0.0f, 0.0f, -1.0f,
  274.  
  275. //rear
  276. 0.0f, 0.0f, -1.0f,
  277. 0.0f, 0.0f, -1.0f,
  278. 0.0f, 0.0f, -1.0f,
  279.  
  280. //front
  281. 0.0f, 0.0f, 1.0f,
  282. 0.0f, 0.0f, 1.0f,
  283. 0.0f, 0.0f, 1.0f,
  284. //front
  285. 0.0f, 0.0f, 1.0f,
  286. 0.0f, 0.0f, 1.0f,
  287. 0.0f, 0.0f, 1.0f,
  288.  
  289.  
  290. //bottom
  291. 0.0f, -1.0f, 0.0f,
  292. 0.0f, -1.0f, 0.0f,
  293. 0.0f, -1.0f, 0.0f,
  294. //bottom
  295. 0.0f, -1.0f, 0.0f,
  296. 0.0f, -1.0f, 0.0f,
  297. 0.0f, -1.0f, 0.0f,
  298.  
  299. //top
  300. 0.0f, 1.0f, 0.0f,
  301. 0.0f, 1.0f, 0.0f,
  302. 0.0f, 1.0f, 0.0f,
  303. //top
  304. 0.0f, 1.0f, 0.0f,
  305. 0.0f, 1.0f, 0.0f,
  306. 0.0f, 1.0f, 0.0f
  307.  
  308. };
Add Comment
Please, Sign In to add comment