1

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

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

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

谢谢,阿里

4

1 回答 1

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();

At this point you can proceed to use spriteImage as the image source for the texture and it will be a combination of a blank 512x512 PNG with a 320x480 PNG for example.

I'll replace the 512x512 blank PNG with an image generated in code but this does work.

于 2009-02-06T19:14:02.073 回答