2010-06-11 114 views
1

..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; 
} 

哪个更好,但宽度似乎被拉伸,高度被搞乱。

任何帮助表示赞赏。

回答

1

,你在画这样的背景下在纵向或横向模式?该glDrawTexiOES参数(x, y, z, width, height)既然你的代码的所有其他部分似乎引用这些数字作为320x480可能是导致了“错误不全”的问题 - 请尝试关闭在裁剪矩形320480和宽度/高度在glDrawTex呼叫。 (可能会部分是我的错,因为没有在最后一个线程中发布参数,对不起!)

不过你必须使用第二个FB副本例程。 memcpy命令不起作用的原因是因为它将抓取320x480x2缓冲区(307200字节)并将其作为单个连续块转储到512x512x2缓冲区(524288字节) - 它不会足够复制320字节,添加192块“死亡空间”和恢复。

0

它看起来像分配的缓冲区不够大。如果每个颜色分量有8位(1字节),则分配的一个字节太少。这可以解释为什么图像仅显示图像的一部分是正确的。 我想下面几行:

//Create enough storage for a 512x512 power of 2 texture 
int8_t lBuf[2*512*512]; 
memcpy (lBuf, frameBuf, 320*480*2); 

将需要更改为:

//Create enough storage for a 512x512 power of 2 texture 
int8_t lBuf[3*512*512]; 
memcpy (lBuf, frameBuf, 320*480*3); 
+0

Ben的加载为RGB565(16bpp) - 每个像素两个字节是正确的。 – 2010-06-11 15:26:28