Results 1 to 7 of 7

Thread: front-to-back compositing

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2003
    Posts
    5

    front-to-back compositing

    I need front-to-back compositing functionality and my first intuition was to simply use
    Code :
    (GL_ONE_MINUS_DST_ALPHA, GL_DST_ALPHA)
    as blending parameters.
    A blank screen leads to the idea, that the color buffer could be only RGB. But

    Code :
    unsigned char bMode;
    glGetBooleanv(GL_RGBA_MODE, &bMode);
    results in ONE, so I decided to have a closer look into the buffer. Then I noticed, that the alpha channel was everywhere ONE, so rendering an object with the above blending function must of course result in (0,0,0,0). So clearing the buffer with (0,0,0,0) before drawing should make a rendered object visible exactly with it's color and alpha values, doesn't it?
    Finally I observed, that clearing the buffer actually doesn't clear it

    Code :
    // get (back) buffer
    glGetIntegerv(GL_DRAW_BUFFER, &bufferIndex);
     
    // and clear it
    glClearColor(0.0,0.0,0.0,0.0);
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
     
    // just to be sure...
    glFinish();
     
    // have a closer look at some region of the buffer
    float pMem[10*10*4];
    glReadBuffer(bufferIndex);
    glReadPixels(100, 100, 10, 10, GL_RGBA, GL_FLOAT, pMem);
    Now I'm completely confused....

    Who can help me?

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: front-to-back compositing

    Usually you won't get a destination alpha by default unless you explictly request one. How you request one depends on how you are setting up your window. With Win32 stuff, you have to set the number of alpha bits you want in the PFDPIXELFORMATDESCRIPTOR. With glut, I think you use GLUT_ALPHA as one of the flags in your call to glutInitDisplayMode.
    Deiussum
    Software Engineer and OpenGL enthusiast

  3. #3
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,450

    Re: front-to-back compositing

    It's GL_RGBA_MODE vs. color index mode.
    Having a GL_RGBA_MODE doesn't mean you have a destination alpha, only that the OpenGL works on RGBA values instead of color indices.
    You need to query the GL_ALPA_BITS or use DescribePixelFormat and look at the cAlphaBits!

    Yes, if you have no destination alpha buffer a read of alpha will return all 1's.

    Make sure your glReadBuffer is set correctly, too. For double buffering it defaults to GL_BACK for draw and read initially.

    Oh, and if even the clear doesn't work, make sure you have a rendering context current while you're using OpenGL.

    [This message has been edited by Relic (edited 10-28-2003).]

  4. #4
    Junior Member Newbie
    Join Date
    Oct 2003
    Posts
    5

    Re: front-to-back compositing

    Thanks for the quick answer!
    OK, I thought that GLUT_RGBA in the glutInitDisplay Mode(...) directly leads to a buffer with alpha... Problem is, that I can't call this method on my own and surely I can't change the PixelFormat since it's already set!?
    What about creating another context with the desired settings and after rendering the whole scene into this one copying all pixels to the (first) framebuffer? Is this the only/best solution for me now in face of being expensive?

  5. #5
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,450

    Re: front-to-back compositing

    "Problem is, that I can't call this method on my own and surely I can't change the PixelFormat since it's already set!?"

    You're working on a project where you cannot influence the OpenGL pixelformat? Ouch.

    Yes, pixelformats can only be set once per window.
    You need to create a whole new window with a different pixelformat then (not only an OpenGL context).

    BTW, destination alpha will never work in 16 bit color resolutions.

    To copy the data from one window to another would need a glReadPixels glDrawPixels through the host. This sucks big time and will not work if the image is occluded by any other window because the readback is undefined for unexposed regions. You can use a pbuffer to solve that.

    [This message has been edited by Relic (edited 10-28-2003).]

  6. #6
    Junior Member Newbie
    Join Date
    Oct 2003
    Posts
    5

    Re: front-to-back compositing

    destination alpha will never work in 16 bit color resolutions
    clear!

    This sucks big time and will not work if the image is occluded by any other window because the readback is undefined for unexposed regions. You can use a pbuffer to solve that.
    That's exactly what I thought of!!! I already use a pbuffer for light attenuation in the course of shadow computation. Using another one and especially the read/write pixel will additionally slow down the application that is anyway not very fast *g; so i actually wanted to avoid such proceeding....

    Thanks anyway!

  7. #7
    Junior Member Newbie
    Join Date
    Oct 2003
    Posts
    5

    Re: front-to-back compositing

    Me again...
    I solved the problem with the alpha bits, but nevertheless I don't understand the bearing of the above 'clearing-code' (in my first post). I have a valid rendering context and glGetError() returns nothing, so in principle it should work, doesn't it???

Similar Threads

  1. Front to Back vs Back to Front Compositing
    By balogna in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 12-11-2005, 12:11 PM
  2. Front and back surfaces
    By TanjuOZgur in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 12-01-2003, 01:39 AM
  3. Front to Back
    By Fernando in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 12-18-2002, 02:44 PM
  4. Back to front question..
    By kaysoft in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 11-26-2002, 02:03 AM
  5. what is faster? fill front and back or only front
    By Jan in forum OpenGL: Advanced Coding
    Replies: 10
    Last Post: 02-21-2002, 06:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean