2010-05-03 13 views
6

Ho un problema con il rendering di texture e framebuffer offscreen con OpenGLES su iPhone.Render to texture framebuffer o offscreen

alt text http://j.imagehost.org/0923/IMG_0020.pngalt text http://j.imagehost.org/0725/IMG_0019.png

prima immagine mostra mattonelle del mahjong resi alla CAEAGLLayer direttamente e questo è corretto. Il secondo mostra le tessere rese su framebuffer fuori schermo, copiate su texture usando glCopyTexImage2D e la trama resa su CAEAGLLayer. Entrambi usano quad bianco opaco per lo sfondo. Ho anche provato a eseguire il rendering direttamente sulla texture ma l'effetto era lo stesso del framebuffer fuori schermo.

Il mio codice per la creazione di framebuffer:

GLuint framebuffer; 
    glGenFramebuffersOES(1, &framebuffer); 
    glBindFramebufferOES(GL_FRAMEBUFFER_OES, framebuffer); 

    GLuint renderbuffer; 
    glGenRenderbuffersOES(1, &renderbuffer); 
    glBindRenderbufferOES(GL_RENDERBUFFER_OES, renderbuffer); 
    glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_RGB8_OES, 
      512, 512); 

    glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, 
      GL_RENDERBUFFER_OES, renderbuffer);

ho trarre tutte le tessere da una texture atlante con una chiamata al glDrawElements usando VBO per il passaggio di dati interlacciati vertice (coordinate, coordinata della texture, colore). Io uso il formato texture RGBA8888, disegnando ogni immagine su due triangoli (quad) con la funzione di fusione glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA). Non uso il buffer di profondità (in tutti i casi).

Qualcuno può dirmi quale potrebbe essere il problema?

+1

Che non è corretto circa le immagini di rendering? Cosa ti aspetti che assomigli? – Frogblast

+0

@Frogblast Il primo, che non è reso al framebuffer fuori dallo schermo, né alla trama, è corretto. – sfider

+0

Codice insufficiente mostrato. Gli FBO probabilmente non sono il problema. – karx11erx

risposta

0

Sembra che tu non abbia postato abbastanza del codice ma da quello che viene pubblicato sembra che tu abbia fuso i ruoli della trama e del renderbuffer nel tuo FBO. (il tuo titolo del post ha detto render to texture) Inoltre hai dimenticato di definire i buffer di disegno.

Il buffer di rendering collegato a un FBO viene solitamente utilizzato come buffer di profondità. quindi cercare il seguente:

GLuint framebuffer; 
glGenFramebuffersOES(1, &framebuffer); 
glBindFramebufferOES(GL_FRAMEBUFFER_OES, framebuffer); 

//set up the Depth Buffer 
GLuint renderbuffer; 
glGenRenderbuffersOES(1, &renderbuffer); 
glBindRenderbufferOES(GL_RENDERBUFFER_OES, renderbuffer); 
glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT24, 
     512, 512); 

glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT, 
     GL_RENDERBUFFER_OES, renderbuffer); 
//set up the texture that you will be rendering to 
glActiveTexture(GL_TEXTURE0); 
GLuint textureID; 
glGenTextures(1, &textureID); 
glBindTexture(GL_TEXTURE_2D, textureID); 
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 
//add various other texture parameters here 
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8_OES, 512,512); 
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureID, 0); 
// define your draw buffers 
GLenum drawBuffers[1] = {GL_COLOR_ATTACHMENT0}; 
glDrawBuffers(1, drawBuffers); 

speranza che aiuta