title: Getting individual pixels from touch point
body: <p>Is it possible to detect every pixel being touched? More specifically, when the user touches the screen, is it possible to track all the x-y coordinates of the cluster of points touched by the user? How can I tell the difference between when users are drawing with their thumb and when they are drawing with the tip of a finger? I would like to reflect the brush difference depending on how users touch the screen, and would also like to track all the pixels being touched.</p>
  
  <p>I am currently using the following codes from the GLPaint sample from Apple developer site:</p>
  
  <p><a href="http://developer.apple.com/library/ios/#samplecode/GLPaint/Introduction/Intro.html" rel="nofollow">http://developer.apple.com/library/ios/#samplecode/GLPaint/Introduction/Intro.html</a></p>
  
  <p>The sample codes allow drawing with a predefined brush size and tracking the x-y coordinates along the way. How can I change the brush depending on how users touch the screen and track all the pixels being touched over time?</p>
  
  <pre><code>// Drawings a line onscreen based on where the user touches
  
  - (void) renderLineFromPoint:(CGPoint)start toPoint:(CGPoint)end
  
  {
       NSLog(@"x:%f   y:%f",start.x, start.y);
  
       static GLfloat*          vertexBuffer = NULL;
  
       static NSUInteger     vertexMax = 64;
  
       NSUInteger               vertexCount = 0,
  
                      count,
  
                      i;
  
  
  
       [EAGLContext setCurrentContext:context];
  
       glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
  
  
  
       // Convert locations from Points to Pixels
  
       CGFloat scale = self.contentScaleFactor;
  
       start.x *= scale;
  
       start.y *= scale;
  
       end.x *= scale;
  
       end.y *= scale;
  
  
  
       // Allocate vertex array buffer
  
       if(vertexBuffer == NULL)
  
            vertexBuffer = malloc(vertexMax * 2 * sizeof(GLfloat));
  
  
  
       // Add points to the buffer so there are drawing points every X pixels
  
       count = MAX(ceilf(sqrtf((end.x - start.x) * (end.x - start.x) + (end.y - start.y) * (end.y - start.y)) / kBrushPixelStep), 1);
  
       for(i = 0; i &lt; count; ++i) {
  
            if(vertexCount == vertexMax) {
  
                 vertexMax = 2 * vertexMax;
  
                 vertexBuffer = realloc(vertexBuffer, vertexMax * 2 * sizeof(GLfloat));
  
            }
  
  
  
            vertexBuffer[2 * vertexCount + 0] = start.x + (end.x - start.x) * ((GLfloat)i / (GLfloat)count);
  
            vertexBuffer[2 * vertexCount + 1] = start.y + (end.y - start.y) * ((GLfloat)i / (GLfloat)count);
  
            vertexCount += 1;
  
       }
  
  
  
       // Render the vertex array
  
       glVertexPointer(2, GL_FLOAT, 0, vertexBuffer);
  
       glDrawArrays(GL_POINTS, 0, vertexCount);
  
  
  
       // Display the buffer
  
       glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
  
       [context presentRenderbuffer:GL_RENDERBUFFER_OES];
  
  }
  
  
  // Handles the start of a touch
  
  - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
  
  {
  
       CGRect                    bounds = [self bounds];
  
       UITouch*     touch = [[event touchesForView:self] anyObject];
  
       firstTouch = YES;
  
       // Convert touch point from UIView referential to OpenGL one (upside-down flip)
  
       location = [touch locationInView:self];
  
       location.y = bounds.size.height - location.y;
  
  }
  
  // Handles the continuation of a touch.
  
  - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
  
  {  
  
       CGRect                    bounds = [self bounds];
  
       UITouch*               touch = [[event touchesForView:self] anyObject];
  
  
  
       // Convert touch point from UIView referential to OpenGL one (upside-down flip)
  
       if (firstTouch) {
  
            firstTouch = NO;
  
            previousLocation = [touch previousLocationInView:self];
  
            previousLocation.y = bounds.size.height - previousLocation.y;
  
       } else {
  
            location = [touch locationInView:self];
  
           location.y = bounds.size.height - location.y;
  
            previousLocation = [touch previousLocationInView:self];
  
            previousLocation.y = bounds.size.height - previousLocation.y;
  
       }
  
  
  
       // Render the stroke
  
       [self renderLineFromPoint:previousLocation toPoint:location];
  
  }
  
  
  
  // Handles the end of a touch event when the touch is a tap.
  
  - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
  
  {
  
       CGRect                    bounds = [self bounds];
  
      UITouch*     touch = [[event touchesForView:self] anyObject];
  
       if (firstTouch) {
  
            firstTouch = NO;
  
            previousLocation = [touch previousLocationInView:self];
  
            previousLocation.y = bounds.size.height - previousLocation.y;
  
            [self renderLineFromPoint:previousLocation toPoint:location];
  
       }
  
  }
  
  
  // Handles the end of a touch event.
  
  - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
  
  {
  
       // If appropriate, add code necessary to save the state of the application.
  
       // This application is not saving state.
  
  }
  </code></pre>