我正在使用像素颜色拾取来计算我单击了哪个 OpenGL 对象,并且效果非常好
在视图中打开 GLKViewDrawableMultisample4X 后,拾取停止工作?
我尝试在触摸屏幕时打开和关闭它,但只能工作一次。
拣货代码:
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);
}