Advertisement
Guest User

Untitled

a guest
Aug 30th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.82 KB | None | 0 0
  1. var rSimWidth:Int = 0
  2. var rSimHeight:Int = 0
  3. var mesh:[GLfloat] = []
  4. var tex:[GLfloat] = []
  5. var ind:[Indicie] = []
  6.  
  7. var realWidth:Int = 0
  8. var realHeight:Int = 0
  9.  
  10. //In this case width = 568, height = 320, mpp varies look at top of picture
  11. init(width: Int, height: Int, mpp: Int)
  12. {
  13. rSimWidth = width / mpp
  14. rSimHeight = height / mpp
  15. rSimWidth += 1; rSimHeight += 1
  16. realWidth = width
  17. realHeight = height
  18.  
  19. mesh = [GLfloat](count: rSimWidth * rSimHeight * 2, repeatedValue: 0)
  20. tex = [GLfloat](count: rSimWidth * rSimHeight * 2, repeatedValue: 0)
  21. ind = [Indicie](count: (rSimHeight-1)*(rSimWidth*2+2), repeatedValue: 0)
  22.  
  23. print("Screen is ((width) x (height))tPond is ((rSimWidth) x (rSimHeight))tScreenSA: (width * height)tPond sa: (rSimWidth * rSimHeight)tMP: (mpp) ((rSimWidth * rSimHeight) * mpp)")
  24. }
  25.  
  26. var index:Int = 0
  27. for i in 0..<rSimHeight - 1
  28. {
  29. for j in 0..<rSimWidth
  30. {
  31. if (i%2==0)//X is even
  32. {
  33. if (j == 0)
  34. {
  35. //DEGENRATE TRIANGLE
  36. ind[index] = Indicie(i*rSimWidth + j)
  37. index += 1
  38. }
  39.  
  40. ind[index] = Indicie(i * rSimWidth + j)
  41. index += 1
  42. ind[index] = Indicie((i + 1) * rSimWidth + j)
  43. index += 1
  44. //(114 + 1) * 569 + 101
  45. //
  46.  
  47. if (j == rSimWidth - 1)
  48. {
  49. //DEGENERATE TRIANGLE
  50. ind[index] = Indicie((i+1)*rSimWidth + j)
  51. index += 1
  52. }
  53. }
  54. else
  55. {
  56. if (j == 0)
  57. {
  58. //DEGENRATE TRIANGLE
  59. ind[index] = Indicie((i+1)*rSimWidth + j)
  60. index += 1
  61. }
  62.  
  63. ind[index] = Indicie((i + 1) * rSimWidth + j)
  64. index += 1
  65. ind[index] = Indicie(i * rSimWidth + j)
  66. index += 1
  67.  
  68. if (j == rSimWidth - 1)
  69. {
  70. //DEGENRATE TRIANGLE
  71. ind[index] = Indicie(i*rSimWidth + j)
  72. index += 1
  73. }
  74. }
  75. }
  76. }
  77.  
  78. for yy in 0..<rSimHeight
  79. {let y = GLfloat(yy);
  80. for xx in 0..<rSimWidth
  81. {let x = GLfloat(xx);
  82. let index = (yy*rSimWidth + xx) * 2
  83. tex[index] = x / GLfloat(rSimWidth - 1)
  84. tex[index + 1] = y / GLfloat(rSimHeight - 1)
  85.  
  86. mesh[index] = tex[index] * GLfloat(realWidth)
  87. mesh[index + 1] = tex[index + 1] * GLfloat(realHeight)
  88. }
  89. }
  90.  
  91. glUseProgram(shade.progId)
  92.  
  93.  
  94. let posLoc = GLuint(glGetAttribLocation(shade.progId, "pos"))
  95. let texLoc = GLuint(glGetAttribLocation(shade.progId, "tc"))
  96.  
  97.  
  98. glBindBuffer(GLenum(GL_ARRAY_BUFFER), texVBO);
  99. glBufferData(GLenum(GL_ARRAY_BUFFER), sim.tex.count * sizeof(GLfloat), sim.tex, GLenum(GL_DYNAMIC_DRAW));
  100. glVertexAttribPointer(texLoc, 2, GLenum(GL_FLOAT), GLboolean(GL_FALSE), 2, BUFFER_OFFSET(0))
  101. glEnableVertexAttribArray(texLoc)
  102.  
  103. glBindBuffer(GLenum(GL_ARRAY_BUFFER), posVBO)
  104. glVertexAttribPointer(posLoc, 2, GLenum(GL_FLOAT), GLboolean(GL_FALSE), 2, BUFFER_OFFSET(0))
  105. glEnableVertexAttribArray(posLoc)
  106.  
  107. let uniOrtho = glGetUniformLocation(shade.progId, "matrix")
  108. glUniformMatrix4fv(uniOrtho, 1, GLboolean(GL_FALSE), &orthographicMatrix)
  109.  
  110.  
  111. glBindBuffer(GLenum(GL_ELEMENT_ARRAY_BUFFER), indVBO)
  112.  
  113.  
  114. glDrawElements(GLenum(GL_TRIANGLE_STRIP), GLsizei(sim.ind.count), GLenum(GL_UNSIGNED_SHORT), nil)
  115.  
  116. glBindBuffer(GLenum(GL_ARRAY_BUFFER), 0)
  117. glBindBuffer(GLenum(GL_ELEMENT_ARRAY_BUFFER), 0)
  118. glDisableVertexAttribArray(posLoc)
  119. glDisableVertexAttribArray(texLoc)
  120.  
  121. for (var i = <value before ..>; i < <value after dot>; <happens automatically>)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement