how to render FBO texture to screen?

This topic contains 3 replies, has 4 voices, and was last updated by  Joe Davis 7 years, 4 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #29655

    dyllanzhou
    Member

    hi, all

        i am a newer to opengles 2.0,  and i currently try to use FBO to render to texture, then show the texture to the screen.

    but i cound not show it correctly , can anyone give me some idear? i refer to the code for openglees2.0 programming guideline.

    the following is my code:

    ps.480×800 is screen width*height

     

    //

    GLuint vbo;
    GLuint texture;
    GLuint fbo;

    GLuint rbo;

     

    //generate one vbo

    glGenBuffers(1,&vbo);
    glBindBuffer(GL_ARRAY_BUFFER, vbo);
    glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*8, 0, GL_DYNAMIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);

     

    //generate one texture

    glGenTextures(1,&texture); 

        glBindTexture(GL_TEXTURE_2D,texture);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 480,800, 0, GL_RGB, GL_UNSIGNED_BYTE,0);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);

     

    //generate one render buffer

    glGenRenderbuffers(1, &rbo);

        glBindRenderbuffer(GL_RENDERBUFFER, rbo);
        glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COMPONENT16, 480, 800);

     

    //generate FBO

    glGenFramebuffers(1, &fbo);

        glBindFramebuffer(GL_FRAMEBUFFER, fbo);
        glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D, texture, 0); // attach texture
         glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER,rbo);
     

    //check status

     GLint status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
     if(status != GL_FRAMEBUFFER_COMPLETE){
        printf(“framebuffer not complete ++++++++++n”);
     }

     

    //render one rectangel to this FBO

    glBindFramebuffer(GL_FRAMEBUFFER, fbo);

    drawRectangle();

     

    //show on display window
    glBindFramebuffer(GL_FRAMEBUFFER,0);

    glClear(GL_COLOR_BUFFER_BIT);
    glBindTexture(GL_TEXTURE_2D,texture);
    glBindBuffer(GL_ARRAY_BUFFER, vbo);
    glReadPixels(0, 0, 480,800, GL_RGBA,GL_FLOAT, 0);

    glViewport(0,0,480,800);
    glVertexAttribPointer (0, 2, GL_FLOAT, GL_FALSE, 0, 0);
    glDrawArrays (GL_TRIANGLE_FAN, 0,4);
    glBindBuffer(GL_ARRAY_BUFFER, 0 );

     

     
    #32550

    Xmas
    Member

    Do you actually use a NULL pointer for glBufferData? What does the drawRectangle function do? What shader program are you using? What’s the point of the glReadPixels call?

    #32551

    Z_boy
    Member

    the shading languages shouid be written like….?I don’t know how to write it?it’s for what use?i have already seen all the topics in the forum,but still have little idea….

    #32552

    Joe Davis
    Member

    Hi Z_boy,

    The best place to start is to read through the SDK documentation and the source code of tutorials and demos that are most applicable to the effect you are trying to achieve. Some of the simpler examples, such as the texturing training course, provide an easy to understand introduction to GLSL ES shaders.

    The PowerVR SDK as a learning resource targets programmers that are familiar with the basics of 3D graphics and teaches them how to optimise their code for PowerVR Graphics cores. If you are looking for an introduction to shaders, you may find it easier to use a text book or online resource that focuses on teaching this.

    If there are any specific questions you need answering, you can send an email directly to us at devtech@imgtec.com.

    Regards,

    Joe

    p.s. If you have a new question, can you please start a new topic for it? Its easier to help you when the topic you post in is related to your specific problem 🙂

Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic.