   Occlusion Culling (Need Help)
  I''m trying to do occlusion culling and seems to have some problems again...The Code that i use is that:   GLubyte    GetPixel(int x,int y){   return (PixelData[x + y * Width]);}void ReadPixelsOfDepth(){glReadPixels (0,0,HOM[0].Width,HOM[0].Height,GL_DEPTH_COMPONENT,GL_UNSIGNED_BYTE,HOM[0].PixelData);for(int NumOfLevels = 1; NumOfLevels < HowManyLevels; NumOfLevels++){gluScaleImage(GL_DEPTH_COMPONENT,HOM[0].Width,HOM[0].Height,GL_UNSIGNED_BYTE,HOM[0].PixelData,HOM[NumOfLevels].Width,HOM[NumOfLevels].Height,GL_UNSIGNED_BYTE,HOM[NumOfLevels].PixelData);}}void ProjectBoundingBox(cHOEBoundingBox BBox){cHOEVector ProjVertex[8];cHOEVector BBoxVertex[8];BBoxVertex[0] = BBox.BBoxMax;BBoxVertex[1] = cHOEVector(BBox.BBoxMax.x    ,BBox.BBoxMax.y ,BBox.BBoxMax.z - BBox.BBoxSize.z);BBoxVertex[2] = cHOEVector(BBox.BBoxMax.x    ,BBox.BBoxMax.y - BBox.BBoxSize.y,BBox.BBoxMax.z - BBox.BBoxSize.z);BBoxVertex[3] = cHOEVector(BBox.BBoxMax.x    ,BBox.BBoxMax.y - BBox.BBoxSize.y,BBox.BBoxMax.z);BBoxVertex[4] = cHOEVector(BBox.BBoxMax.x - BBox.BBoxSize.x,BBox.BBoxMax.y ,BBox.BBoxMax.z);BBoxVertex[5] = cHOEVector(BBox.BBoxMax.x - BBox.BBoxSize.x,BBox.BBoxMax.y - BBox.BBoxSize.y,BBox.BBoxMax.z);BBoxVertex[6] = cHOEVector(BBox.BBoxMax.x - BBox.BBoxSize.x,BBox.BBoxMax.y - BBox.BBoxSize.y,BBox.BBoxMax.z - BBox.BBoxSize.z);BBoxVertex[7] = cHOEVector(BBox.BBoxMax.x - BBox.BBoxSize.x,BBox.BBoxMax.y ,BBox.BBoxMax.z - BBox.BBoxSize.z);double Model1ViewMatrix [16];double Projection1Matrix[16];int   ViewPort1Matrix  [4];glGetDoublev (GL_MODELVIEW_MATRIX  ,Model1ViewMatrix );glGetDoublev (GL_PROJECTION_MATRIX ,Projection1Matrix);glGetIntegerv(GL_VIEWPORT ,ViewPort1Matrix);cHOEVector Temp;double x,y,z;for(int a = 0; a< 8; a++){gluProject  (BBoxVertex[a].x,BBoxVertex[a].y,BBoxVertex[a].z,Model1ViewMatrix,Projection1Matrix,ViewPort1Matrix,&x,&y,&z);x /= z;y /= z;ProjVertex[a].x  = x;ProjVertex[a].y  = y;}cHOEBoundingBox BRectangle;cHOEVector Max = cHOEVector(-10000000.0f,-10000000.0f,0,1);cHOEVector Min = cHOEVector( 10000000.0f, 10000000.0f,0,1);for(a = 0; a< 8; a++){if(ProjVertex[a].x < Min.x) Min.x = ProjVertex[a].x;if(ProjVertex[a].y < Min.y) Min.y = ProjVertex[a].y;if(ProjVertex[a].x > Max.x) Max.x = ProjVertex[a].x;if(ProjVertex[a].y > Max.y) Max.y = ProjVertex[a].y;}BRectangle.BBoxMax  = Max;BRectangle.BBoxMin  = Min;BRectangle.BBoxSize = Max - Min;for(a = 0; a< 8; a++)BRectangle.BBoxPoints[a] = ProjVertex[a];int CountTrasparentPixels = 0;for(int i = 0; i < HOM[0].Width * HOM[0].Height; i++){if(HOM[0].PixelData[i] == 0)   CountTrasparentPixels++;}if(BRectangle.BBoxMin.x < 0)   BRectangle.BBoxMin.x = 0;if(BRectangle.BBoxMin.y < 0)   BRectangle.BBoxMin.y = 0;if(BRectangle.BBoxMax.x < 0)   BRectangle.BBoxMax.x = 0;if(BRectangle.BBoxMax.y < 0)   BRectangle.BBoxMax.y = 0;if(BRectangle.BBoxMin.x > HOM[0].Width)   BRectangle.BBoxMin.x = HOM[0].Width;if(BRectangle.BBoxMin.y > HOM[0].Height)   BRectangle.BBoxMin.y = HOM[0].Height;if(BRectangle.BBoxMax.x > HOM[0].Width)   BRectangle.BBoxMax.x = HOM[0].Width;if(BRectangle.BBoxMax.y > HOM[0].Height)   BRectangle.BBoxMax.y = HOM[0].Height;IsVisible(HowManyLevels - 1 ,BRectangle,CountTrasparentPixels);}bool IsVisible(int Level,cHOEBoundingBox BRenctangle,int m0){if(Level < 0)   return false;int maxPixelCount = (1 << (2 * Level)) - m0;if(maxPixelCount < 0)maxPixelCount = 0;for(int y =(int)BRenctangle.BBoxMin.y >> Level; y < (int)BRenctangle.BBoxMax.y >> Level; y++){for(int x = (int)BRenctangle.BBoxMin.x >> Level; x < (int)BRenctangle.BBoxMax.x >> Level; x++){if(HOM[Level].GetPixel(x,y) < maxPixelCount){if(HOM[Level].GetPixel(x,y) == 0){return true;}else{bool Reject = true;cHOEBoundingBox PixelRect;PixelRect.BBoxMin.x = x<< Level;PixelRect.BBoxMax.x =(x +1) << Level;PixelRect.BBoxMin.y = y<< Level;PixelRect.BBoxMax.y =(y +1) << Level;if(BRenctangle.BBoxMin.x > PixelRect.BBoxMin.x){PixelRect.BBoxMin.x = BRenctangle.BBoxMin.x;Reject = false;}if(BRenctangle.BBoxMax.x < PixelRect.BBoxMax.x){PixelRect.BBoxMax.x = BRenctangle.BBoxMax.x;Reject = false;}if(BRenctangle.BBoxMin.y > PixelRect.BBoxMin.y){PixelRect.BBoxMin.y = BRenctangle.BBoxMin.y;Reject = false;}if(BRenctangle.BBoxMax.y < PixelRect.BBoxMax.y){PixelRect.BBoxMax.y = BRenctangle.BBoxMax.y;Reject = false;}if(Reject || IsVisible(Level - 1,PixelRect,m0)){return true;}}}}}return  false;}1. The problem is that i don''t create my own function to create the Z-pyramid of the occlusion map but i use the gluScaleImage.According to MSDN the gluScaleImage funcuses a box filter to sample the source image, that is like the box filter Zhangsaid in his dissertation.Is that right or i have to write a function like the one that Gerhard Kurka propose in his paper "Fast Creation Of a Hierarchical Occlusion Map"?2. The other problem is that i don''t extend to the screen the BBox but i use the gluProject to extend it for me? And ,again is this right? I know the way of doing it my self (PROJECTION MATRIX * MODELVIEW MATRIX ...)but it seems togive the same results.3. On another paper of Kurka i found the IsVisible(...) function and i have some questions about it.   3.1. Why he is compare the Current Pixel''s Opacity with the maxPixelsCount (Algorithm below line 12) ? (I don''t know if he is doing that because he has no comments).The authentic algorithm is this:01: BOOL isVisible(HOM, level, rect, m0)02: BEGIN03: IF Level < 0 THEN04: RETURN FALSE;05: END06: maxPixelCount := (1 LEFTSHIFT (2 * Level)) - m0;07: IF maxPixelCount < 0 THEN08: maxPixelCount := 0;09: END10: FOR y:=rect.y1 RIGHTSHIFT level TO rect.y2 RIGHTSHIFT level DO11: FOR x:=rect.x1 RIGHTSHIFT level TO rect.x2 RIGHTSHIFT level DO12: IF HOM(level)(x, y) < maxPixelCount THEN13: IF HOM(level)(x, y) = 0 THEN14: RETURN TRUE;15: ELSE16: reject := TRUE;17: pixelRect.x1 := x LEFTSHIFT level;18: pixelRect.x2 := (x+1) LEFTSHIFT level;19: pixelRect.y1 := y LEFTSHIFT level;20: pixelRect.y2 := (y+1) LEFTSHIFT level;21: IF x1 > pixelRect.x1 THEN22: pixelRect.x1 := x1; reject := FALSE;23: END;24: IF x2 < pixelRect.x2 THEN25: pixelRect.x2 := x2; reject := FALSE;26: END;27: IF y1 > pixelRect.x1 THEN28: pixelRect.y1 := y1; reject := FALSE;29: END;30: IF y2 < pixelRect.y2 THEN31: pixelRect.y2 := y2; reject := FALSE;32: END;33: IF reject OR isVisible(HOM,level-1,pixelRect,m0) THEN34: RETURN TRUE;35: END;36: END;37: END;38: END;39: END;40: RETURN FALSE;41: END;if he isn''t compare the pixel''s opacity then what the HOM[level](x,y) means?3.2 In line 21 what is the x1 which is compared with the pixelRect.x1? Is the rect.x1 so x1 = rect.x1?3.3 How you can find the number of transparent pixels that you pass in this function ? (m0 parameter is the number of neglectable transparent pixels of level-0 map).    The Transparent pixels are the pixels with opacity 0 ?And the final question is how can you do the depth test to find if the polygon is back or front of the occluder?I hope somebody answer at least some of my questions because i''ve done Abtrees and seems that i can''t use with them other visibility method than occlusion culling?Thanks in advance.HellRaizer. 