0

我正在拼命地尝试从虹吸纹理(名为 textureName 的属性)中获取像素数据。我从这里使用 xcode Developer SDK:http: //syphon.v002.info/

在客户端部分,SimpleImageView.m有一种drawRect方法似乎通过绑定纹理,glBindVertexArray(_vao)这样人们就可以通过glGetTexImage. 我制作了一个调试视频,其中每个像素都包含 RGB[0, 0, 255]。

我将像素读入一维缓冲区,并按预期获取值,但仅针对第一行。视频输入为 480x360 (WxH),我得到 r=0, g=0, b=255 从元素 0 开始重复到元素 3 479,但随后元素在元素 3 480 处为 0(这是第一个下一行的像素)

这是上面提到的下载中存在的内容,并添加了examinePixels功能:

        glUseProgram(_program);
        glBindTexture(GL_TEXTURE_RECTANGLE, image.textureName);

        glBindVertexArray(_vao);
        
        glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
        
        
        [self examinePixels:image.textureSize.width height:image.textureSize.height];

        glBindVertexArray(0);
        glBindTexture(GL_TEXTURE_RECTANGLE, 0);
        glUseProgram(0);

这是我的examinePixels功能:

- (void)examinePixels:(float) width height:(float)height
{
    int bytesPerElement = 3;
    GLuint psize = height * width * bytesPerElement;
    GLubyte *pixels = malloc(psize);
    
    glGetTexImage(GL_TEXTURE_RECTANGLE, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels);
    
    NSString *info;
    int startingPixelRowForPrint = 0;
    int startingPixelColForPrint = 470;
    int endPrintingAfterNumCol = 50;
    int startingPixelForPrint = width * startingPixelRowForPrint * 3 + startingPixelColForPrint * bytesPerElement;
    info = [NSMutableString stringWithString:@"p2:\n"];
    
    for(int pix=startingPixelForPrint; pix<startingPixelForPrint + endPrintingAfterNumCol; pix+=bytesPerElement)
    {
        info = [NSMutableString stringWithFormat:@"%@%d -> %03d:%03d:%03d\n", info, pix/bytesPerElement, pixels[pix], pixels[pix+1], pixels[pix+2]];
    }
    
    self.frameInfo = info;
}

我错过了什么?

4

0 回答 0