Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var rSimWidth:Int = 0
- var rSimHeight:Int = 0
- var mesh:[GLfloat] = []
- var tex:[GLfloat] = []
- var ind:[Indicie] = []
- var realWidth:Int = 0
- var realHeight:Int = 0
- //In this case width = 568, height = 320, mpp varies look at top of picture
- init(width: Int, height: Int, mpp: Int)
- {
- rSimWidth = width / mpp
- rSimHeight = height / mpp
- rSimWidth += 1; rSimHeight += 1
- realWidth = width
- realHeight = height
- mesh = [GLfloat](count: rSimWidth * rSimHeight * 2, repeatedValue: 0)
- tex = [GLfloat](count: rSimWidth * rSimHeight * 2, repeatedValue: 0)
- ind = [Indicie](count: (rSimHeight-1)*(rSimWidth*2+2), repeatedValue: 0)
- print("Screen is ((width) x (height))tPond is ((rSimWidth) x (rSimHeight))tScreenSA: (width * height)tPond sa: (rSimWidth * rSimHeight)tMP: (mpp) ((rSimWidth * rSimHeight) * mpp)")
- }
- var index:Int = 0
- for i in 0..<rSimHeight - 1
- {
- for j in 0..<rSimWidth
- {
- if (i%2==0)//X is even
- {
- if (j == 0)
- {
- //DEGENRATE TRIANGLE
- ind[index] = Indicie(i*rSimWidth + j)
- index += 1
- }
- ind[index] = Indicie(i * rSimWidth + j)
- index += 1
- ind[index] = Indicie((i + 1) * rSimWidth + j)
- index += 1
- //(114 + 1) * 569 + 101
- //
- if (j == rSimWidth - 1)
- {
- //DEGENERATE TRIANGLE
- ind[index] = Indicie((i+1)*rSimWidth + j)
- index += 1
- }
- }
- else
- {
- if (j == 0)
- {
- //DEGENRATE TRIANGLE
- ind[index] = Indicie((i+1)*rSimWidth + j)
- index += 1
- }
- ind[index] = Indicie((i + 1) * rSimWidth + j)
- index += 1
- ind[index] = Indicie(i * rSimWidth + j)
- index += 1
- if (j == rSimWidth - 1)
- {
- //DEGENRATE TRIANGLE
- ind[index] = Indicie(i*rSimWidth + j)
- index += 1
- }
- }
- }
- }
- for yy in 0..<rSimHeight
- {let y = GLfloat(yy);
- for xx in 0..<rSimWidth
- {let x = GLfloat(xx);
- let index = (yy*rSimWidth + xx) * 2
- tex[index] = x / GLfloat(rSimWidth - 1)
- tex[index + 1] = y / GLfloat(rSimHeight - 1)
- mesh[index] = tex[index] * GLfloat(realWidth)
- mesh[index + 1] = tex[index + 1] * GLfloat(realHeight)
- }
- }
- glUseProgram(shade.progId)
- let posLoc = GLuint(glGetAttribLocation(shade.progId, "pos"))
- let texLoc = GLuint(glGetAttribLocation(shade.progId, "tc"))
- glBindBuffer(GLenum(GL_ARRAY_BUFFER), texVBO);
- glBufferData(GLenum(GL_ARRAY_BUFFER), sim.tex.count * sizeof(GLfloat), sim.tex, GLenum(GL_DYNAMIC_DRAW));
- glVertexAttribPointer(texLoc, 2, GLenum(GL_FLOAT), GLboolean(GL_FALSE), 2, BUFFER_OFFSET(0))
- glEnableVertexAttribArray(texLoc)
- glBindBuffer(GLenum(GL_ARRAY_BUFFER), posVBO)
- glVertexAttribPointer(posLoc, 2, GLenum(GL_FLOAT), GLboolean(GL_FALSE), 2, BUFFER_OFFSET(0))
- glEnableVertexAttribArray(posLoc)
- let uniOrtho = glGetUniformLocation(shade.progId, "matrix")
- glUniformMatrix4fv(uniOrtho, 1, GLboolean(GL_FALSE), &orthographicMatrix)
- glBindBuffer(GLenum(GL_ELEMENT_ARRAY_BUFFER), indVBO)
- glDrawElements(GLenum(GL_TRIANGLE_STRIP), GLsizei(sim.ind.count), GLenum(GL_UNSIGNED_SHORT), nil)
- glBindBuffer(GLenum(GL_ARRAY_BUFFER), 0)
- glBindBuffer(GLenum(GL_ELEMENT_ARRAY_BUFFER), 0)
- glDisableVertexAttribArray(posLoc)
- glDisableVertexAttribArray(texLoc)
- for (var i = <value before ..>; i < <value after dot>; <happens automatically>)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement