I made a drawing program. Everything works as I expected. But when drawing, some strange things sometimes happen.
Launch the application and left-click on the image. He should draw a point from the 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);
at the point where I click. mouseDown registers the location of mouseDown, converts it to NSValue, sends it to an array, and then before drawing, I extract the NSValue to CGPoint and send it to GLfloat so that it can be drawn with glDrawArrays. But no matter where I click on the image, it draws a point in coordinates (0,0). After that, everything works fine. See Image:

This was the first problem. The second problem is that when I draw with it (by dragging with the mouse), sometimes points appear where they are not drawn. Picture:

When I continue, it will disappear. After some dragging appears and disappears again. And so on. Picture:

Any ideas why this might happen? I will send the code below:
Mouse down:
- (void) mouseDown:(NSEvent *)event { location = [self convertPoint: [event locationInWindow] fromView:self]; NSValue *locationValue = [NSValue valueWithPoint:location]; [vertices addObject:locationValue]; [self drawing]; }
The mouse is dragged:
- (void) mouseDragged:(NSEvent *)event { location = [self convertPoint: [event locationInWindow] fromView:self]; NSValue *locationValue = [NSValue valueWithPoint:location]; [vertices addObject:locationValue]; [self drawing]; }
Drawing:
- (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); }