So I have made paint app. And I want to fix one problem with my brush stroke. When I paint with mouse slowly - everything is ok. When I do it faster, there are some spacings. Its because not all mouse coordinates are registered then. But how can I fix it? Is there ant solution? I'm using vertex array with mouse locations. Here's code:
Code :int count = [vertices count] * 2; int sum = [vertices count]; // 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_BLEND); glBlendFuncSeparate(GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ZERO); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, brushTexture); glPointSize(50); glHint(GL_POINT_SMOOTH_HINT, GL_NICEST); glEnable(GL_POINT_SMOOTH); glVertexPointer(2, GL_FLOAT, 0, GLVertices); glDrawArrays(GL_POINTS, 0, sum); glDisable(GL_POINT_SMOOTH); glDisable(GL_BLEND); glDisableClientState(GL_VERTEX_ARRAY);
And mouse location registering code:
Code :- (void) mouseDragged:(NSEvent *)event { location = [self convertPoint: [event locationInWindow] fromView:self]; NSValue *locationValue = [NSValue valueWithPoint:location]; [vertices addObject:locationValue]; [self drawArray]; } - (void) mouseDown:(NSEvent *)event { location = [self convertPoint: [event locationInWindow] fromView:self]; NSValue *locationValue = [NSValue valueWithPoint:location]; [vertices addObject:locationValue]; [self drawArray]; }
And my app image:
![]()



This solution sounds nice, but I don't really get it. It would be easy if I do it manually. I mean, describe few points and draw them (static way). But how to do it dynamically? I mean that distance would be calculated at every mouse movement? I think you know what I mean. How to do that it would calculate distances from vertex array?
