2010-06-11 76 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