 //      glUniformMatrix3fv(uniforms[UNIFORM_NORMAL_MATRIX], 1, 0, UnsafePointer($0));
 //    })
     
-    glDrawArrays(GLenum(GL_TRIANGLES), 0, 3)
-    glUniform3f(uniforms[UNIFORM_COLOR], 1.0, 0.0, 0.0)
-    glDrawArrays(GLenum(GL_TRIANGLES), 3, 3)
+//    glDrawArrays(GLenum(GL_TRIANGLES), 0, 6)
+//    glUniform3f(uniforms[UNIFORM_COLOR], 1.0, 0.0, 0.0)
+//    glDrawArrays(GLenum(GL_TRIANGLES), 3, 3)
     
     //glInsertEventMarkerEXT(0, "com.apple.GPUTools.event.debug-frame")
+//    glUniform3f(uniforms[UNIFORM_COLOR], 1.0, 0.0, 0.0)
+    
+//    drawLine((0,0.2), to: (1,1), width: 2)
+    let thick : GLfloat = 1.0
+    let thin  : GLfloat = 0.5
+//    let fivepx : GLfloat = 5 //(5.0/640.0)*pointScale
+    
+    drawLine((0.25,0.25), to:(0.25,0.75), width: thick)
+    drawLine((0.75,0.25), to:(0.75,0.75), width: thick)
+    
+    // Line across
+    drawLine((0.25,0.5), to: (0.75,0.5), width: thin)
+    
+    drawTriangle((0.25, 0.5), rotation: 3.1415926/2, height: 0.03125)
+    drawTriangle((0.75, 0.5), rotation: -3.1415926/2, height: 0.03125)
+    drawTriangle((0.5, 0.75), rotation: 3.1415926, height: 0.03125)
+    
+    // box: 70x17, 60x7 inside (5 width)
+    // 86 between them
+//    drawLine((206.0/640.0, (320-8.5)/640.0), to: ((206.0+70.0)/640.0, (320-8.5)/640.0), width: 5)
+    
+    
+    drawHUDCenter()
+    
+    
+    // Draw the log displays
+    // Left: 4 orders, right: 4.6 orders.
+    
+    // Do the height display
+    let currentDH : Float = 0
+    drawLogDisplay(currentDH, left: true)
+  }
+  
+  func drawLogDisplay(value : Float, left : Bool)
+  {
+    let lgeTickSize = -0.1
+    let medTickSize = lgeTickSize / 2
+    let smlTickSize = medTickSize / 2
+    
+    let center = PseudoLog10(Double(value))
+    // Calculate the minimum and maximum of the log range to draw
+    let logRange = left ? 4 : 4.6
+    var logMin = Int(floor(center)-logRange/2)
+    let logMax = Int(ceil(center)+logRange/2)
+    if !left {
+      logMin = max(0, logMin)
+    }
+    let bottom = center - logRange / 2
+//    let top    = center + logRange / 2
+    // Draw the major marks
+    for power in logMin...logMax {
+      var y = (Double(power)-bottom)/logRange
+      drawLine((0,GLfloat(y)), to: (GLfloat(lgeTickSize * (left ? -1 : 1)), GLfloat(y)), width: 1)
+      
+      var nextPow = InversePseudoLog10(Double(power >= 0 ? power+1 : power))
+      let halfPoint = PseudoLog10(nextPow*0.5)
+      y = (halfPoint-bottom)/logRange
+      drawLine((0,GLfloat(y)), to: (GLfloat(medTickSize * (left ? -1 : 1)), GLfloat(y)), width: 1)
+
+      nextPow = InversePseudoLog10(Double(power >= 0 ? power+1 : power))
+      let doubPoint = PseudoLog10(nextPow*0.1*2)
+      y = (doubPoint-bottom)/logRange
+      drawLine((0,GLfloat(y)), to: (GLfloat(smlTickSize * (left ? -1 : 1)), GLfloat(y)), width: 1)
+    }
+    
   }
   
   // MARK: -  OpenGL ES 2 shader compilation

    
    glGenBuffers(1, &vertexBuffer)
    glBindBuffer(GLenum(GL_ARRAY_BUFFER), vertexBuffer)
    glBufferData(GLenum(GL_ARRAY_BUFFER), GLsizeiptr(sizeof(GLfloat) * gSquareVertexData.count), &gSquareVertexData, GLenum(GL_STATIC_DRAW))
    
    glEnableVertexAttribArray(GLuint(GLKVertexAttrib.Position.rawValue))
    glVertexAttribPointer(GLuint(GLKVertexAttrib.Position.rawValue), 3, GLenum(GL_FLOAT), GLboolean(GL_FALSE), 12, BUFFER_OFFSET(0))
//    glEnableVertexAttribArray(GLuint(GLKVertexAttrib.Normal.rawValue))

  1,1,0,
  1,0,0,
  0,0,0,
]

// Equilateral triangle with height 1, facing up, with point at 0,0
var gTriangleData : [GLfloat] = [
  0,0,0,
  0.625,-1,0,
  -0.625,-1,0,
]

func openSemiCircle(r : GLfloat, w : GLfloat) -> [(x: GLfloat, y: GLfloat)]
{
  var points : [(x: GLfloat, y: GLfloat)] = []
  let Csteps = 20
  let innerR = r - w/2
  let outerR = r + w/2
  
  for step in 0...Csteps {
    let theta = GLfloat((3.1415926/Double(Csteps))*Double(step))
    points.append((innerR*sin(theta), innerR*cos(theta)))
    points.append((outerR*sin(theta), outerR*cos(theta)))
  }
  return points
}

func crossHair(H : GLfloat, J : GLfloat, w : GLfloat, theta : GLfloat) -> [GLfloat]
{
  var points : [(x: GLfloat, y: GLfloat)] = []
  let m = sin(theta)/cos(theta)
  
  points.append((w/2,-H-J))
  points.append((  0,-H-J))
  points.append((w/2,m*w/2 - H - w/cos(theta)))
  points.append((0,-H))
  points.append((m*(H+w/cos(theta)-w/2),-w/2))
  points.append((m*(H+w/2),w/2))

  // W - the point the open box starts
  let W : GLfloat = 41.0
  points.append((W, -w/2))
  points.append((W, w/2))
  
  // B : Box Width
  // Bh : Box Height
  let B : GLfloat = 70
  let Bh : GLfloat = 17
  let BiY = (Bh-2*w)*0.5
//  points.append((W+w, -BiX))
  points.append((W+w,  BiY))
  points.append((W, Bh/2))    // 10
  points.append((W+B-w, BiY)) // 11
  points.append((W+B, Bh/2))  // 12
  points.append((W+B-w, -BiY)) // 13
  points.append((W+B, -Bh/2))  // 14
  points.append((W+w,  -BiY)) // 15
  points.append((W, -Bh/2))    // 16
  points.append((W+w,  BiY)) // 17
  points.append((W, -w/2)) // 18
  
  // Jump to the upper cursor part
  points.append(points.last!)
  points.append((w/2, 24))
  // New squares
  points.append((w/2, 24))
  points.append((0, 24))
  points.append((w/2, H+J))
  points.append((0, H+J))
  
  // Finally, append the central semicircle
  points.append(points.last!)
  
  let circPoints = openSemiCircle(5, w: 2.5)
  points.append(circPoints.first!)
  points.extend(circPoints)
  
  var flts : [GLfloat] = []
  for p in points {
    flts.append(p.x / 640)
    flts.append(p.y / 640)
    flts.append(0.0)
  }
  return flts
}

var gCenterHUD : [GLfloat] = crossHair(16, J: 68, w: 5, theta: 0.7243116395776468)
