title: glDrawArrays not drawing correctly
body: <p>I made a painting program. Everything works as I expected. But while drawing, sometimes some strange things happen.</p>
  
  <p>I run app, and press left mouse button on image. It should draw point from code:</p>
  
  <pre><code>glEnableClientState(GL_VERTEX_ARRAY);
  glEnable(GL_TEXTURE_2D);
  glBindTexture(GL_TEXTURE_2D, brushTextura);
  glPointSize(100);
  glVertexPointer(2, GL_FLOAT, 0,GLVertices);
  glDrawArrays(GL_POINTS, 0, count);
  glDisableClientState(GL_VERTEX_ARRAY);
  </code></pre>
  
  <p>at point where I press. <code>mouseDown</code> registers mouseDown location, converts it to NSValue, sends to array, and then before drawing I extract NSValue to CGPoint and send it to GLfloat so that it could be drawn by glDrawArrays. But no matter where I click the mouse on the image it draws the point at coordinates (0,0). After that every thing works OK. See image:</p>
  
  <p><img src="https://i.stack.imgur.com/3dCCE.png" alt="mouse click"></p>
  
  <p>This was first problem. The second problem is that when I paint with it (drag pressed mouse), sometimes points appear where they are not drawn. Image:</p>
  
  <p><img src="https://i.stack.imgur.com/cMKxM.png" alt="mouse drag"></p>
  
  <p>When I continue drag it disappears. After some dragging it appears again and disappears again. And so on. Image:</p>
  
  <p><img src="https://i.stack.imgur.com/UNKaZ.png" alt="enter image description here"></p>
  
  <p>Any Ideas why it could happen? I will post code bellow:</p>
  
  <hr>
  
  <p>Mouse down:</p>
  
  <pre><code>- (void) mouseDown:(NSEvent *)event
  {
      location = [self convertPoint: [event locationInWindow] fromView:self];
      NSValue *locationValue = [NSValue valueWithPoint:location];
      [vertices addObject:locationValue];
  
          [self drawing];
  }
  </code></pre>
  
  <p>Mouse dragged:</p>
  
  <pre><code>- (void) mouseDragged:(NSEvent *)event
  {
      location = [self convertPoint: [event locationInWindow] fromView:self];
      NSValue *locationValue = [NSValue valueWithPoint:location];
      [vertices addObject:locationValue];
  
          [self drawing];
  }
  </code></pre>
  
  <p>Drawing:</p>
  
  <pre><code>- (void) drawing {
  int count = [vertices count] * 2;
  NSLog(@"count: %d", count);
  int currIndex = 0;
  GLfloat *GLVertices = (GLfloat *)malloc(count * sizeof(GLfloat));
  for (NSValue *locationValue in vertices) {
      CGPoint loc = locationValue.pointValue;
      GLVertices[currIndex++] = loc.x;
      GLVertices[currIndex++] = loc.y;    
   }
  glEnableClientState(GL_VERTEX_ARRAY);
  glEnable(GL_TEXTURE_2D);
  glBindTexture(GL_TEXTURE_2D, brushTextura);
  glPointSize(100);
  glVertexPointer(2, GL_FLOAT, 0, GLVertices);
  glDrawArrays(GL_POINTS, 0, count);
  glDisableClientState(GL_VERTEX_ARRAY);
  }
  </code></pre>