将PNG复制到更大的空白/代码生成纹理的最佳方法? (OpenGL ES 1.1 / iPhone)

时间:2009-02-06 18:14:46

标签: iphone opengl-es textures

我有一个320x480 PNG,我想在iPhone上进行纹理贴图/操作,但这些尺寸显然不是2的强度。我已经在512x512 PNG上测试了我的纹理贴图操作算法,这是一个黑色背景,带有320x480叠加在其上的图像,以原点(左下角(0,0))为中心,其中320x480区域在iPhone屏幕上正确定向/居中/缩放。

我现在要做的是进步到可以拍摄320x480源图像并将它们应用到代码中生成的空白/黑色背景512x512纹理,以便两者合并为一个纹理以便我可以应用我在512x512测试中使用的顶点和纹理坐标。这将最终用于相机拍摄和相机胶卷源图像等。

有什么想法? (必须使用OpenGL ES 1.1而不使用GL util工具包等。)

谢谢, ARI

1 个答案:

答案 0 :(得分:0)

我发现一种方法是简单地将两个图像绘制到当前上下文中,然后提取生成的组合图像。还有另一种更适合OpenGL的方式可能更有效吗?

// CGImageRef for background image
// CGImageRef for foreground image

// CGSize for current context

// Define CGContextRef for current context

// UIGraphicsBeginImageContext using CGSize

// Get value for current context with UIGraphicsGetCurrentContext()

// Define 2 rectangles, one for the background and one for the foreground images

// CGContextDrawImage(currentContext, backgroundRect, backgroundImage);
// CGContextDrawImage(currentContext, foregroundRect, foregroundImage);

// UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();

// spriteImage = finalImage.CGImage();

// UIGraphicsEndImageContext();

此时,您可以继续使用spriteImage作为纹理的图像源,例如,它将是空白512x512 PNG与320x480 PNG的组合。

我将用代码生成的图像替换512x512空白PNG,但这确实有效。

相关问题