I want to clip specific area from texture and given set of coordinates.
So I can use CGContextMoveToPoint and CGContextAddLineToPoint to clip it:
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL, pageWidth, 480, 8, 4 * pageWidth, colorSpace, kCGImageAlphaPremultipliedFirst);
CGRect rect = CGRectMake(0, 0, pageWidth, 480);
CGContextMoveToPoint(context, 0, 0);
CGContextAddLineToPoint(context, 0, 480);
CGContextAddLineToPoint(context, 320, 480);
CGContextAddLineToPoint(context, 320, 480 - y1);
CGContextAddLineToPoint(context, x1, 480 - y2);
CGContextAddLineToPoint(context, x2, 0);
CGContextClosePath(context);
CGContextClip(context);
CGContextDrawImage(context, rect, top.CGImage);
CGImageRef imageMasked = CGBitmapContextCreateImage(context);
CGContextRelease(context);
UIImage *newImage = [UIImage imageWithCGImage:imageMasked];
CGImageRelease(imageMasked);
But now I want to use OpenGL ES for these purposes.
So I loaded texture from image, define array of coords:
const GLfloat coords[] = {
-1.0, 1.5,
1.0, 1.5,
x1, y1,
x2, y2,
-1.0, 1.5
};
where x1, x2, y1, y2 - custom coords which are calculated in runtime.
The problem is that resulting image become scaled and transformed and I can not set the right coordinates to clip needed area.
What coordinates should I use or in what order I should define them?