..Continued on from my previous question仅绘制一个纹理的OpenGL ES iPhone
的一部分我有一个320×480帧缓冲器RGB565我希望在iPhone上使用OpenGL ES 1.0绘制。
- (void)setupView
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, (int[4]){0, 0, 480, 320});
glEnable(GL_TEXTURE_2D);
}
// Updates the OpenGL view when the timer fires
- (void)drawView
{
// Make sure that you are drawing to the current context
[EAGLContext setCurrentContext:context];
//Get the 320*480 buffer
const int8_t * frameBuf = [source getNextBuffer];
//Create enough storage for a 512x512 power of 2 texture
int8_t lBuf[2*512*512];
memcpy (lBuf, frameBuf, 320*480*2);
//Upload the texture
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 512, 512, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, lBuf);
//Draw it
glDrawTexiOES(0, 0, 1, 480, 320);
[context presentRenderbuffer:GL_RENDERBUFFER_OES];
}
如果我在512 * 512产生原始纹理输出被裁剪错误,但除此之外看起来不错。然而,使用320 * 480的要求输出尺寸,一切都会失真和混乱。
我非常确定这是我将帧缓存复制到新的512 * 512缓冲区的方式。我曾试过这个例程
int8_t lBuf[512][512][2];
const char * frameDataP = frameData;
for (int ii = 0; ii < 480; ++ii) {
memcpy(lBuf[ii], frameDataP, 320);
frameDataP += 320;
}
哪个更好,但宽度似乎被拉伸,高度被搞乱。
任何帮助表示赞赏。
Ben的加载为RGB565(16bpp) - 每个像素两个字节是正确的。 – 2010-06-11 15:26:28