Home Game Development Frame Buffer Object (FBO) just isn’t working. What is the fitting means to make use of?

Frame Buffer Object (FBO) just isn’t working. What is the fitting means to make use of?

0
Frame Buffer Object (FBO) just isn’t working. What is the fitting means to make use of?

[ad_1]

I’m making an attempt to make use of FBO however i’m dwelling some issues. I’ll present you my steps however first i’ll present my working display screen ,so we will evaluate them. Like earlier than fbo after fbo.

My working display screen and Draw() perform code:
enter image description here

glClearColor(0.5,0.5,0.5,1.0);
glLoadIdentity();
glTranslatef(0.0,0.0,-3.0);
glRotatef(0,0.0,1.0,0.0);
glUniform3f(glGetUniformLocation(mainShader->getProgramId(),"lightPos"),0,1,2); 
mainShader->useShader();    
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    scene->draw(mainShader->getProgramId());    
mainShader->delShader();

After I attempted so as to add FBO :

Create FBO texture perform:

unsigned int createTexture(int w,int h,bool isDepth=false)
{
    unsigned int textureId;
    glGenTextures(1,&textureId);
    glBindTexture(GL_TEXTURE_2D,textureId);
    glTexImage2D(GL_TEXTURE_2D,0,(!isDepth ? GL_RGBA8 : GL_DEPTH_COMPONENT),w,h,0,isDepth ? GL_DEPTH_COMPONENT : GL_RGBA,GL_FLOAT,NULL);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);

    int i;
    i=glGetError();
    if(i!=0)
    {
        std::cout << "Error occurred whereas loading the feel: " << i << std::endl;
    }
    glBindTexture(GL_TEXTURE_2D,0);
    return textureId;
}

Init() perform :

void init()
{
    glClearColor(0,0,0,1);
    glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(50,640.0/480.0,1,1000);
    glMatrixMode(GL_MODELVIEW);
    glEnable(GL_DEPTH_TEST);
    mainShader=new shader("vertex.vs","fragment.frag");
    quadRenderShader=new shader("quadRender.vs","quadRender.frag");
    scene=new meshLoader("check.mix");

    renderTexture=createTexture(640,480);
    depthTexture=createTexture(640,480,true);
    glGenFramebuffers(1,&FBO);
    glBindFramebuffer(GL_FRAMEBUFFER,FBO);
    //GL_COLOR_ATTACHMENT0
    //GL_DEPTH_ATTACHMENT
    glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,renderTexture,0);

    glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_TEXTURE_2D,depthTexture,0);


    int i=glCheckFramebufferStanding(GL_FRAMEBUFFER);
    if(i!=GL_FRAMEBUFFER_COMPLETE)
    {
        std::cout << "Framebuffer just isn't OK, standing=" << i << std::endl;
    }
    glBindFramebuffer(GL_FRAMEBUFFER,0);

}

And Draw() perform:

void show()
GL_DEPTH_BUFFER_BIT);
        scene->draw(mainShader->getProgramId());
    glBindFramebuffer(GL_FRAMEBUFFER,0);
    mainShader->delShader();




    glClearColor(0.0,0.0,0.0,1.0);
    //render texture to display screen
    glLoadIdentity();       
    glClear(GL_COLOR_BUFFER_BIT

and Result solely drawing final setup coloration (glClearColor) so black :
enter image description here

Result ought to be like in tutorial :
enter image description here

Note: I do know tutorial monkey is purple however it’s not downside.

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here