Camera frame to UIImage to OpenGL rendering gives

2019-08-29 02:23发布

问题:

I'm extracting a UIImage with

NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
UIImage *image = [UIImage imageWithData:imageData];

then i'm creating an OpenGL texture and render it. then i extract a UIImage from the frame buffer but it comes out wrong as you can see.

i tried playing with texture vertices array but it stayed the same.

this are the coordinates:

const GLfloat squareVertices[] = {
-1.0f, -1.0f,
1.0f, -1.0f,
-1.0f,  1.0f,
1.0f,  1.0f,
};


const GLfloat textureVertices[] = {
1.0f, 1.0f,
1.0f, 0.0f,
0.0f,  1.0f,
0.0f,  0.0f,
};


 glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, squareVertices);
    glEnableVertexAttribArray(ATTRIB_VERTEX);
    glVertexAttribPointer(ATTRIB_TEXTUREPOSITON, 2, GL_FLOAT, 0, 0, textureVertices);
    glEnableVertexAttribArray(ATTRIB_TEXTUREPOSITON);`

回答1:

It is problem with your texture coordinates. Check them properly.