Question

I am using pixel colour picking to work out which OpenGL object I have clicked on and it works brilliantly

As soon as I turn GLKViewDrawableMultisample4X on in the view, the picking stops working?

I have tried turning this on and off when I touch the screen but only works once.

Picking code:

  GLKView *glkView = (GLKView*)[self view];
  UIImage *snapshot = [glkView snapshot];
  GLKVector4 colour = [snapshot pickPixelAtX:xPos Y:yPos];

@implementation UIImage (NDBExtensions)

- (GLKVector4)pickPixelAtX:(NSUInteger)x Y:(NSUInteger)y {

    CGImageRef cgImage = [self CGImage];
    size_t width = CGImageGetWidth(cgImage);
    size_t height = CGImageGetHeight(cgImage);

    if ((x < width) && (y < height))
    {
        CGDataProviderRef provider = CGImageGetDataProvider(cgImage);
        CFDataRef bitmapData = CGDataProviderCopyData(provider);
        const UInt8* data = CFDataGetBytePtr(bitmapData);
        size_t offset = ((width * y) + x) * 4;

        UInt8 b = data[offset+0];
        UInt8 g = data[offset+1];
        UInt8 r = data[offset+2];
        UInt8 a = data[offset+3];

        CFRelease(bitmapData);

        return GLKVector4Make(r, g, b, a );

    }
    return GLKVector4Make(0,0,0,0);
}
Was it helpful?

Solution

I managed to fix this using the code from this

OpenGL ES 2.0 Object Picking on iOS

Very good answer, basically GLKViewDrawableMultisample4X does not work with picking and so you need to make another render buffer

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top