Problem about rendering to depth texture

Hi all:
I’m about to implement shadow mapping in my engine, so I began to play with depth texture recently. I’ve never touched it before, and I’m having some really weird problems now, one of which is:
I created a pbuffer at size of 1024*1024, and a texture with the same size. Then I cleared the pbuffer with depth value of 0.2, copyed its content to the texture, and then projected the texture to the objects in the world. what I got is like this:

http://img.photobucket.com/albums/v438/991060/Snap1.jpg

As you can see, only part of the texture is filled with the assigned value(0.2), and if I make the program window larger, it becomes:

http://img.photobucket.com/albums/v438/991060/Snap2.jpg

Looks like the region of the pbuffer’s depth buffer which was cleared is related to the size of my main window, but I created the pbuffer with a separated rendering context, this shouldn’t happen, I think. Any idea why?

Also, if I create the pbuffer/texture at size of 2048*2048, the region got cleared becomes relatively smaller(see below), shouldn’t the whole depth buffer be cleared?

http://img.photobucket.com/albums/v438/991060/Snap3.jpg

i guess the clear call only clears what is within the viewport that was defined for the pbuffer
try calling glViewport with your pbuffer sizes before clearing it (or when initializing it…)

I have had simillar problems on ATI hw and drivers…