
void CheckFramebufferStatus()


{
GLenum status;
status = (GLenum) glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);

switch(status)
{
case GL_FRAMEBUFFER_COMPLETE_EXT:
break;
case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
printf("Unsupported framebuffer format\n");
break;
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
printf("Framebuffer incomplete, missing attachment\n");
break;
case GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT:
printf("Framebuffer incomplete, duplicate attachment\n");
break;
case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
printf("Framebuffer incomplete, attached images must have same dimensions\n");
break;
case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
printf("Framebuffer incomplete, attached images must have same format\n");
break;
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
printf("Framebuffer incomplete, missing draw buffer\n");
break;
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
printf("Framebuffer incomplete, missing read buffer\n");
break;
default:
printf("unknown error !!!!\n");
return;
}
}

void CreateDepthSurface()


{
// 在N卡上,必须创建 color buffer 的镜像.
// 否则,depth buffer 是无效的.
// 如果不想向color buffer 写入数据.
// 可以调用 glDrawBuffer(GL_NONE) glReadBuffer(GL_NONE) 来屏蔽.
// 而在A卡上, 是可以创建独立的 Depth buffer 的..
glGenTextures(1, &ctex);
// glGenRenderbuffersEXT(1, &depth_rb);

// glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);

// init texture
// glBindTexture(texTarget, tex);
// glTexImage2D(texTarget, 0, texInternalFormat, texWidth, texHeight, 0,
// GL_RGBA, GL_FLOAT, NULL);

/**///////////////////////////////////////////////////////////////////////////

glBindTexture(GL_TEXTURE_2D, ctex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, texWidth, texWidth, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

glGenTextures(1, &dtex);
glBindTexture(GL_TEXTURE_2D, dtex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, texWidth, texWidth, 0, GL_DEPTH_COMPONENT, GL_INT, NULL);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);


glGenFramebuffersEXT(1, &fb);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
CheckFramebufferStatus();

glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
GL_TEXTURE_2D, ctex, 0);

CheckFramebufferStatus();
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
GL_DEPTH_ATTACHMENT_EXT,
GL_TEXTURE_2D, dtex, 0);

CheckFramebufferStatus();
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

}


我很奇怪为什么SGI , OPENGL.ORG 上的关于fbo扩展的文档都没有说明这一点. 连NV自己的也没有. 或许是那么长的一篇文章,我没有看仔细.
郁闷,,,郁闷,,,,,郁闷.