English 中文(简体)
页: 1 5 + GLKView: 如何获得彩色阴道选取的六氯苯胺数据?
原标题:iOS 5 + GLKView: How to access pixel RGB data for colour-based vertex picking?

I ve been converting my own personal OGLES 2.0 framework to take advantage of the functionality added by the new iOS 5 framework GLKit.

在认罪后,我现在要实施所描述的彩色采集机制:here。 为此,你必须进入后方缓冲,以检索触动的冰箱价值,然后作为外向/原始/露面物体的独特识别码。 当然,这要求临时独一无二地对所有vert/原始物品进行区分。

我有两个问题。

  1. I have access to a GLKViewController, GLKView, CAEAGLLayer (of the GLKView) and an EAGLContext. I also have access to all OGLES 2.0 buffer related commands. How do I combine these to identify the color of a pixel in the EAGLContext I m tapping on-screen?

  2. Given that I m using Vertex Buffer Objects to do my rendering, is there a neat way to override the colour provided to my vertex shader which firstly doesn t involve modifying buffered vertex (colour) attributes, and secondly doesn t involve the addition of an IF statement into the vertex shader?

我假设对(2)的答复是“无”,但由于表现和非修正的法典,我认为与更有经验的人核对是明智的。

任何建议都会得到感谢。 感谢你时间

<>>>>>

我现在知道如何用glReadPixels。 因此,我猜测,我只得做特殊“独特颜色”才能回到后方缓冲地带,简单地转而去,然后改写。 这将不可避免地产生直观浮器,但我猜测它最容易;当然比创建<条码>CGImageContextRef更为快捷(而且更敏感)。

然而,对于后方缓冲而言,任何失误都会受到高度赞赏。

最佳回答

我很想确切地研究如何尽可能简明地做到这一点。 下面我解释如何做到这一点,并列出所有必要的守则:

In order to allow touch interaction to select a pixel, first add a UITapGestureRecognizer to your GLKViewController subclass (assuming you want tap-to-select-pixel), with the following target method inside that class. You must make your GLKViewController subclass a UIGestureRecognizerDelegate:

@interface GLViewController : GLKViewController <GLKViewDelegate, UIGestureRecognizerDelegate>

在您的姿态识别器上,在<编码>view上添加(在GLKViewController上,实际上为GLKView):

// Inside GLKViewController subclass init/awakeFromNib:
[[self view] addGestureRecognizer:[self tapRecognizer]];
[[self tapRecognizer] setDelegate:self];

为您的姿态识别员确定目标行动;在使用特定<代码>init......时,你可以这样做,然而,我却利用故事板(在Xcode4.2中打新的界面)制造了地雷,并用这种方式加以控制。

Anyway, here s my target action for the tap gesture recognizer:

-(IBAction)onTapGesture:(UIGestureRecognizer*)recognizer {
    const CGPoint loc = [recognizer locationInView:[self view]];
    [self pickAtX:loc.x Y:loc.y];
}

在我的<编码>GLKViewController子流中,有一门I ve被指:

-(void)pickAtX:(GLuint)x Y:(GLuint)y {
    GLKView *glkView = (GLKView*)[self view];
    UIImage *snapshot = [glkView snapshot];
    [snapshot pickPixelAtX:x Y:y];
}

这种方法利用了一种手法的新方法snapshot,即 Apple在GLKView上,以便产生一个<代码>UIImage,从背后编码

值得注意的是<代码>snapshot中的评论。 内容提要文件:

This method should be called whenever your application explicitly needs the contents of the view; never attempt to directly read the contents of the underlying framebuffer using OpenGL ES functions.

这使我感到奇怪的是,我早先试图在试图获取六氯代苯数据时援引<条码>glReadPixels的尝试,以及把正确道路倒塌的指标。

页: 1 一段时期前,我称之为<代码>pickPixelAtX:Y: on the UIImage。 这是在“编码”栏目中添加的一种方法:

@interface UIImage (NDBExtensions)
-(void)pickPixelAtX:(NSUInteger)x Y:(NSUInteger)y;
@end

这里是执行;它载有必要的最后法典。 该守则来自。 问题,并根据收到的答复加以修正:

@implementation UIImage (NDBExtensions)

- (void)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);
        NSLog(@"R:%i G:%i B:%i A:%i",r,g,b,a);
    }
}

@end

最初,我尝试了在阿普尔特普切案中发现的一些相关代码:“从CGImage的角度来看待六氯苯数据”,其中要求有2个方法定义,而不是1个方法定义,但还需要更多的代码,并且有“避免”号码”数据,因此我无法执行正确的解释。

!! 在你的项目中添加这一编号,然后在绘制一张图时,它将以下列形式产生:

R:24 G:46 B:244 A:255

当然,你应写出一些方法,以摘取欧洲复兴开发银行的内在价值(在0-255之间),并使用这些价值。 一种做法是从上述方法中收回一个<编码>UIColor,即:

UIColor *color = [UIColor colorWithRed:red/255.0f green:green/255.0f blue:blue/255.0f alpha:alpha/255.0f];
问题回答

暂无回答




相关问题
using colors in calculated member

Im using this query in MDX for a calculate measure topcount(nonempty([StatusPlanes].[Status].Status.members,[Measures].[Planes]),1)(0).member_caption this will bring me this result Dimension1 ...

Using colors with MDX calculated measure

I m using this query in MDX for a calculated measure topcount(nonempty([StatusPlanes].[Status].Status.members,[Measures].[Planes]),1)(0).member_caption This will bring me this result Dimension1 ...

How can I convert a color image to grayscale in MATLAB?

I am trying to implement an algorithm in computer vision and I want to try it on a set of pictures. The pictures are all in color, but I don t want to deal with that. I want to convert them to ...

Hex colors: Numeric representation for "transparent"?

I am building a web CMS in which the user can choose colours for certain site elements. I would like to convert all colour values to hex to avoid any further formatting hassle ("rgb(x,y,z)" or named ...

How to change out-of-focus text selection color in Xcode?

Okay, I ll bite. I ve got really pleasant code/window colors set up in Xcode. Ordinarily, my selection color is very visible. When I am doing a project search and iterating through the results, ...

How to change Gmap markers color?

I ve a custom google map with different points: Markers[0] = new Array(new GMarker(new GLatLng(45.0, 9.0)), "Location1", "<strong>Address Line</strong><br/>Some information"); ...

热门标签