   Problem using glReadPixels to get stencil buffer
  Hi Everyone.For purpose of computing area of an object on the screen, I decided to get the content of stencil buffer. So I call the function glReadPixels :glReadPixels(viewport[0], viewport[1], viewport[2], viewport[3], GL_DEPTH_COMPONENT, GL_FLOAT, pDepth);glReadPixels(viewport[0], viewport[1], viewport[2], viewport[3], GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, pSten);After this, it seems that the code got depth buffer correctly, but it didn't get stencil buffer correctly.Then i use google to search similar problems and found this:http://www.gamedev.net/community/forums/topic.asp?topic_id=531102so I try the same code :unsigned char stencilData[] ={9, 8, 7,6, 5, 4,3, 2, 1,};glEnable(GL_STENCIL_TEST);glPixelStorei(GL_UNPACK_ALIGNMENT, 4);glPixelStorei(GL_UNPACK_ROW_LENGTH, 3);glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);glRasterPos2i(0, 0);glDrawPixels(3, 3, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, stencilData);unsigned char *data = new unsigned char[9];glPixelStorei(GL_PACK_ALIGNMENT, 4);glPixelStorei(GL_PACK_ROW_LENGTH, 3);glPixelStorei(GL_PACK_SKIP_ROWS, 0);glPixelStorei(GL_PACK_SKIP_PIXELS, 0);glReadPixels(0, 0, 3, 3, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, data);for (int y = 0; y < 3; y++) {for (int x = 0; x < 3; x++) {std::cout << (int)data[y * 3 + x] << "\t";}std::cout << std::endl;}   But I get    0   0   0  205  0   0   0  205  0I guess the key to the prob is storage format. How can I get it right.I'm using ATI radeon 4300 on a HP notepad.Anyone can give me any guide ? Thanks a lot:)   
  :-| Find out that i forgot to Enable Stencil test before render, and after change the "glPixelStorei(GL_UNPACK_ALIGNMENT, 4);" to "glPixelStorei(GL_UNPACK_ALIGNMENT, 1);"Reading the stencil buffer with glReadPixels works...   