3

I work under MS WindowsXP,my video card is itel GMA4500, my code:

glClearStencil(0);
glClear(GL_STENCIL_BUFFER_BIT);

unsigned char* data = new unsigned char[width*height];
glPixelStorei(GL_PACK_ALIGNMENT,1);
glReadPixels(0,0,width,height,GL_STENCIL_INDEX,GL_UNSIGNED_BYTE,data);

but when i checked the data buffer, i can see that the bytes are not all zero, so what's the problem?


YES, I'm sure i have a stencil buffer, and after call glReadPixels, i checked glGetError,there's no error. i also tried memset to fill data buffer with zero, but the result didn't changed.

Tim Post
  • 33,371
  • 15
  • 110
  • 174
user897101
  • 31
  • 1
  • Does anything change if you `memset()` `data` to zeros before your `glReadPixels()` call? – genpfault Aug 16 '11 at 17:58
  • So it most of the buffer is zero? Is it a smattering on non-zero or does it have non-zero in blocks, at the start, or end? Could you paste a (very) small hex dump? Also, what's the width and height? – MattiasF Aug 17 '11 at 16:19

2 Answers2

5

Do you actually have a stencil buffer? If not, glReadPixels will raise an error (check glGetError(…)) and leave the target buffer's contents unchanged.

datenwolf
  • 159,371
  • 13
  • 185
  • 298
0

Did you mean to use

glPixelStorei(GL_UNPACK_ALIGNMENT,1);

since you are trying to get the contents FROM the stencil buffer?

aparker
  • 178
  • 9