hockeyman
07-09-2012, 03:44 AM
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:
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:
- (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:
http://s9.postimage.org/5dso9ff33/Screen_Shot_2012_07_09_at_1_33_57_PM.png
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:
- (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:
http://s9.postimage.org/5dso9ff33/Screen_Shot_2012_07_09_at_1_33_57_PM.png