Pixel Access from Texture to an Array

Home Forums Syphon Syphon Development – Developer Pixel Access from Texture to an Array

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
  • #59219


    So I am trying to utilize syphon to simply grab the pixel information (RGB) for the current frame and then send it out as an array to another program I am writing. I have tried a bunch of different methods and am running into a wall.

    Most likely I am just missing a step as I am new to openGL. My understanding is that I have to first initialize the frame buffer then set up the texture. Then via the syphon client attach texture and read the pixels. I have tried two technicals both glReadPixels and glGetTexImage but neither provided the pixel information. I looked through some of the other forum posts and some information was useful but I was not able to replicate their implementations.

    I realize I am most likely just forgetting something, but I would greatly appreciate any help/advice people may have.

    Below is a code snippet of the section in question.

    Thanks so much.

    SyphonImage *frame = [client newFrameImage];
                    NSSize imageSize = frame.textureSize;
                    CGFloat width = imageSize.width;
                    CGFloat height = imageSize.height;
                    //Full Pixel Arrray Length
                    NSInteger myDataLength = imageSize.width * imageSize.height * 3;
                    //Establish a New Frame Buffer
                    GLuint frameBuffer;
                    glGenFramebuffers(1, &frameBuffer);
                    //Causes a clearing of the framebuffer
                    //glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer);
                    GLuint texture;
                    glGenTextures(1, &texture);
                    glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture);
                    glBindTexture(GL_TEXTURE_RECTANGLE_EXT, [frame textureName]);
                    glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGB, imageSize.width, imageSize.height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
                    texture = frame.textureName;
                    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE_ARB, texture, 0);
                    //Determins if Frame Status has been Complete
                    GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
                    if (status != GL_FRAMEBUFFER_COMPLETE){
                        NSLog(@"NOT Complete");
                    // allocate array and read pixels into it.
                    GLubyte *buffer = malloc(myDataLength);
                    GLubyte *buffer2 = (GLubyte *) malloc(myDataLength);
                    //Get Texture to Buffer
                    glGetTexImage(GL_TEXTURE_RECTANGLE_ARB, frame.textureName, GL_RGB, GL_INT, buffer);
                    //Read Pixels frome Frame Buffer
                    glReadPixels(0,0, imageSize.width, imageSize.height, GL_RGB, GL_UNSIGNED_BYTE, buffer2);
                    //NSLog(@ "Width %f  Height: %f", imageSize.width, imageSize.height);
                    //NSLog(@ "Texture RGB: %d %d %d", buffer[0], buffer[1], buffer[2]);
                    //NSLog(@ "Texture RGB: %d %d %d", buffer[3], buffer[4], buffer[5]);
                    //Frame Buffer
                    //NSLog(@ "FrameBuffer RGB: %d %d %d", buffer2[0], buffer2[1], buffer2[2]);
                    //NSLog(@ "FrameBuffer RGB: %d %d %d", buffer2[3], buffer2[4], buffer2[5]);
                    // Close Frame Buffers etc.
                    glDeleteFramebuffers(1, &frameBuffer);

    A peculiarity of the IOSurface-backed textures which Syphon uses is that they are reluctant to return pixel data by the usual means. You will likely have to draw the texture into an FBO and then get the pixels from the FBO’s texture backing.

    Rough example code in a previous post here.


    Thanks so much!

    I tried to implement a version of this and am still getting random values.

    Just want to make sure my logic is correct.

    The process is:

    Create frame buffer, Texture

    Frame Step
    Bind the texture to frame buffer
    Establish a PBO
    Pack Framebuffer into PBO
    Save PBO
    Then access the pixels.

    Thanks again.


    Your frame step is missing a draw-the-texture-into-the-FBO line


    I’ve been trying really hard to draw a GL_TEXTURE_RECTANGLE_ARB to a GL_TEXTURE_2D in order to perform mipmapping, which GL_TEXTURE_RECTANGLE_ARB does not support.

    I’ve tried accessing the pixel data directly but with no success. If you should succeed with accessing the pixels, please post your solution.


    The solution is in the forum post I link above – see here.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.