iosobjective-cmulti-touchuitoucheaglview

iOS Multi-Touch Not Working


I have the regular OpenGL / EAGL setup going on:

@interface EAGLView : UIView {
@public
    EAGLContext* context;
}
@property (nonatomic, retain) EAGLContext* context;
@end

@implementation EAGLView
@synthesize context;
+ (Class)layerClass {
    return [CAEAGLLayer class];
}
@end

@interface EAGLViewController : UIViewController {
@public
    EAGLView* glView;
}
@property(nonatomic, retain) EAGLView* glView;
@end

@implementation EAGLViewController
@synthesize glView;

- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
    for (UITouch* touch in touches) {
        CGPoint location = [touch locationInView:glView];
        int index;
        for (index = 0; index < gCONST_CURSOR_COUNT; ++index) {
            if (sCursor[index] == NULL) {
                sCursor[index] = touch;
                break;
            }
        }
    }
    [super touchesBegan:touches withEvent:event];
}

That implementation includes corresponding touchesEnded/Canceled/Moved as well. The code fully works and tracks well.

I also make sure that I'm giving proper values for everything:

sViewController = [EAGLViewController alloc];

CGRect rect = [[UIScreen mainScreen] applicationFrame];
sViewController.glView = [[EAGLView alloc] initWithFrame:CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height)];
Assert(sViewController.glView);
sViewController.glView.userInteractionEnabled = YES;
sViewController.glView.multipleTouchEnabled = YES;
sViewController.glView.exclusiveTouch = YES;

It all compiles just fine, but I'm never receiving more than one UITouch. I don't mean in a single touchesBegan, but the index never goes past 0. I also set a breakpoint for the second time it enters that function, and putting two fingers on doesn't make it trigger.


Solution

  • It seems all I was missing was this:

    sViewController.view = sViewController.glView;