Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7895759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:43:16+00:00 2026-06-03T07:43:16+00:00

The idea is to render specific parts of a scene in a FrameBuffer object

  • 0

The idea is to render specific parts of a scene in a FrameBuffer object in different color attachments and then combining those using the depth buffer for the final image. in the first step I want only to render to a single attachment and then to the screen. I’m using glut for this purpose and the EXT_framebuffer_object specification due to my old graphics card. In the main function I have:

int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitWindowSize(600, 512);
    glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
    int mainHandle = glutCreateWindow("Demo");
    glutSetWindow(mainHandle);
    glutDisplayFunc(RenderCallback);
    glutReshapeFunc(ReshapeCallback);
    glutIdleFunc(IdleCallback);
    glutKeyboardFunc(KeyboardCallback);
    glutSpecialFunc(ArrowKeyCallback);
    glutMouseFunc(MouseCallback);
    glutMotionFunc(MotionCallback);

    MotionCallback(0,0);
    atexit(ExitNx);

    // Setup default render states
    glClearColor(0.3f, 0.4f, 0.5f, 1.0);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_COLOR_MATERIAL);

    // Setup lighting
    glEnable(GL_LIGHTING);
    float ambientColor[]    = { 0.0f, 0.1f, 0.2f, 0.0f };
    float diffuseColor[]    = { 1.0f, 1.0f, 1.0f, 0.0f };       
    float specularColor[]   = { 0.0f, 0.0f, 0.0f, 0.0f };       
    float position[]        = { 100.0f, 100.0f, 400.0f, 1.0f };     
    glLightfv(GL_LIGHT0, GL_AMBIENT, ambientColor);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseColor);
    glLightfv(GL_LIGHT0, GL_SPECULAR, specularColor);
    glLightfv(GL_LIGHT0, GL_POSITION, position);
    glEnable(GL_LIGHT0);
    GLenum status,st1,st2;                                            
    GLint colorBufferCount ;
    glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &colorBufferCount);   
    printf("Max number of attachments:%d \n " ,colorBufferCount);
    //initialising FBO
    glGenFramebuffersEXT(1,&fb);
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,fb);
    //attaching an image to render to
    glGenRenderbuffersEXT(1,&colorbf);
    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT,colorbf);
    glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT,GL_RGBA8,600,512);
    glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,   GL_RENDERBUFFER_EXT, colorbf);
    //creating depht buffer
    glGenRenderbuffersEXT(1, &depth_rb);
    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depth_rb);
    glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, 600, 512);
    //attaching the depth buffer to the FBO
    glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depth_rb);
    st1=glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
    //checking for errors
    st2=glGetError();
    if(st1==GL_FRAMEBUFFER_COMPLETE_EXT)
        printf("so far so good\n ");
    else
        if(st1==GL_FRAMEBUFFER_UNSUPPORTED_EXT)
            printf("not good");
    const GLubyte *sir= new GLubyte [256];
    sir=gluErrorString(st1);
    printf("error received %s \n", sir);

    glutMainLoop();
}

In the display callback function I have

void RenderCallback()
{
    // Setup projection matrix
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(60.0f, (float)glutGet(GLUT_WINDOW_WIDTH)/(float)glutGet(GLUT_WINDOW_HEIGHT), 1.0f, 10000.0f);
    gluLookAt(gEye.x, gEye.y, gEye.z, gEye.x + gDir.x, gEye.y + gDir.y, gEye.z + gDir.z, 0.0f, 1.0f, 0.0f);

    // Setup modelview matrix
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); //setting our FBO to render to
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);  
    //render code 
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,0); //unbiding

    //now I wish to see what I have written in the colorbf attachment , most likely my mistake is in the following to come
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
    glMatrixMode(GL_MODELVIEW); 
    glLoadIdentity();
    //should I have done something else before?
    glutSwapBuffers();
}

The output is an empty scene.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:43:17+00:00Added an answer on June 3, 2026 at 7:43 am
    glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
    

    GL_COLOR_ATTACHMENT0_EXT is not a valid argument for glDrawBuffer().

    Add a texture attachment if you want to visualize your FBO. Just bind your texture attachment after you’re done rendering to your FBO and draw a full-screen textured quad.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using OpenLayers to render a OpenLayers.Geometry.LineString on a OpenLayers.Layer.Vector layer. The idea is
Any idea how to render a PDF using iTextSharp so that it renders the
Any idea how to join multiple tables in ssis programatically using Merge Join ?
This is not a specific question, instead I'm trying to get an idea of
I'm trying to render Pdfs pages into png files using Ghostscript v9.02. For that
Styling form elements using css can be problematic since every browser render tag in
Can you please give me an idea how to render custom controls in property
I want to implement copy protection for opengl render, here are some idea, none
I'm using WebView to load and render a variety of websites with no problem.
does anyone have an idea how to render unicode 'astral plane' characters (whose CIDs

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.