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[15121512];
static GLfloat pixelsDepth1[512512];
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->rightprcView->bottom; v++){
if(pixelsDepth1[v] <= pixelsDepth2[v]){
finalImageColor[v3] = pixelsColor1[v3];
finalImageColor[v3 + 1] = pixelsColor1[v3 + 1];
finalImageColor[v3 + 2] = pixelsColor1[v3 + 2];
}
else{
finalImageColor[v3] = pixelsColor2[v3];
finalImageColor[v3 + 1] = pixelsColor2[v3 + 1];
finalImageColor[v3 + 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?