Home › Forums › Syphon › Syphon Development – Developer › Pixel Access from Texture to an Array
- This topic has 5 replies, 3 voices, and was last updated 3 years, 11 months ago by bangnoise.
-
AuthorPosts
-
November 13, 2016 at 7:39 pm #59219ayParticipant
Hello,
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); //Texture 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); glActiveTexture(GL_TEXTURE0); glEnable(GL_TEXTURE_RECTANGLE_EXT); 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); //Texture //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);
November 16, 2016 at 5:01 am #59220bangnoiseKeymasterA 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.
November 30, 2016 at 6:40 am #59221ayParticipantThanks 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:
INIT STEP
Create frame buffer, TextureFrame Step
Bind the texture to frame buffer
Establish a PBO
Pack Framebuffer into PBO
Save PBO
Then access the pixels.Thanks again.
December 5, 2016 at 11:21 am #59222bangnoiseKeymasterYour frame step is missing a draw-the-texture-into-the-FBO line
December 17, 2016 at 11:16 pm #59223osgmParticipantI’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.
April 12, 2017 at 4:22 am #59257 -
AuthorPosts
- You must be logged in to reply to this topic.