读取深度值出错
IDirect3DSurface9 * ppZStencilSurface;
Device->GetDepthStencilSurface(&ppZStencilSurface);
D3DLOCKED_RECT pLockedRect;
ppZStencilSurface->LockRect(&pLockedRect,NULL,0);
float * p=(float *)(pLockedRect.pBits);
FILE *fp;
fp=fopen("data.txt","a+");
for (int x=0;x<ViewHeight;x++)//ViewWidth、ViewHeight为视口宽和高
{
for (int y=0;y<ViewWidth;y++)
{
fprintf(fp,"depth[%d][%d]=%f\n",x,y,&p[x*(pLockedRect.Pitch/4)+y]);
}
}
fclose(fp);
ppZStencilSurface->UnlockRect();
想利用以上代码把深度缓冲区中的深度值读取出来并写道文本文档中,但是结果出错,请问错误出在哪里。以下为实验结果
depth[0][0]=0.000000
depth[0][1]=0.000000
depth[0][2]=0.000000
depth[0][3]=0.000000
depth[0][4]=0.000000
depth[0][5]=0.000000
depth[0][6]=0.000000
depth[0][7]=0.000000
depth[0][8]=0.000000
depth[0][9]=0.000000
depth[0][10]=0.000000
depth[0][11]=0.000000
depth[0][12]=0.000000
depth[0][13]=0.000000
depth[0][14]=0.000000
depth[0][15]=0.000000
depth[0][16]=0.000000
depth[0][17]=0.000000
depth[0][18]=0.000000
depth[0][19]=0.000000
depth[0][20]=0.000000
depth[0][21]=0.000000
depth[0][22]=0.000000
......