Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: combining two depth images

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2000
    Posts
    14

    combining two depth images

    I am trying to render 2 different images and save each one of them in an array (colors+depths). then, i want to combine the two images to a final image. For example, look at this code:

    int v;
    static GLfloat pixelsColor1[1512*1512];
    static GLfloat pixelsDepth1[512*512];

    static GLfloat pixelsColor2[1512*1512];
    static GLfloat pixelsDepth2[512*512];

    static GLfloat finalImageColor[1512*1512];

    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); //clear all the buffers that are in use.

    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    glPixelStorei(GL_PACK_ALIGNMENT, 1);


    glBegin(GL_POLYGON);
    glVertex3f(300.0, -300.0, 200.0);
    glVertex3f(300.0, 300.0, 200.0);
    glVertex3f(-300.0, 300.0, 200.0);
    glVertex3f(-300.0, -300.0, 200.0);
    glEnd();

    glReadPixels(0, 0, prcView->right, prcView->bottom, GL_RGB, GL_FLOAT, pixelsColor1);
    glReadPixels(0, 0, prcView->right, prcView->bottom, GL_DEPTH_COMPONENT, GL_FLOAT, pixelsDepth1);

    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); //clear all the buffers that are in use.
    //--------------------------------------

    glBegin(GL_POLYGON);
    glVertex3f(450.0, -300.0, 300.0);
    glVertex3f(450.0, 300.0, 300.0);
    glVertex3f(-150.0, 300.0, 300.0);
    glVertex3f(-150.0, -300.0, 300.0);
    glEnd();


    glReadPixels(0, 0, prcView->right, prcView->bottom, GL_RGB, GL_FLOAT, pixelsColor2);
    glReadPixels(0, 0, prcView->right, prcView->bottom, GL_DEPTH_COMPONENT, GL_FLOAT, pixelsDepth2);

    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); //clear all the buffers that are in use.
    //--------------------------------------


    //////////////// DRAWING /////////////////////////
    for(v = 0; v < prcView->right*prcView->bottom; v++){
    if(pixelsDepth1[v] <= pixelsDepth2[v]){
    finalImageColor[v*3] = pixelsColor1[v*3];
    finalImageColor[v*3 + 1] = pixelsColor1[v*3 + 1];
    finalImageColor[v*3 + 2] = pixelsColor1[v*3 + 2];
    }
    else{
    finalImageColor[v*3] = pixelsColor2[v*3];
    finalImageColor[v*3 + 1] = pixelsColor2[v*3 + 1];
    finalImageColor[v*3 + 2] = pixelsColor2[v*3 + 2];
    }
    }

    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); //clear all the buffers that are in use.

    glDrawPixels(prcView->right, prcView->bottom, GL_RGB, GL_FLOAT, finalImageColor);

    glFinish();
    return;

    but i am geting a distortions!!
    It looks like one of the polygons has a strange frame and it looks shifted.
    Is anyone knows what the problem or how it is need to be done?

  2. #2
    Junior Member Newbie
    Join Date
    Aug 2000
    Posts
    14

    Re: combining two depth images

    I wanted to add a remark to my question.
    The most annoying and not predicted thing with my problem is that it not always happening. I am running the program and i get the distortion, I am closing it and run it again and get the distortion again(though it a little bit different), then, after a few times i try this, i am geting the right picture. If anyone know what can causing this i will be grateful.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •