about get color value

I just want to get a pixel's color value.
In openGL ,I know a function,is:glReadPixel(...);
How to use D3D implent same function


Answer this question

about get color value

  • snandan

    I'm not sure I fully understand you... I've only written a couple of OpenGL programs (years ago!) so I don't really know anything about glReadPixel()!

    If you want to read, at a given pixel, from the depth buffer then it's more tricky - for performance reasons it's best not to mess with it. By design, you have to be using a lockable depth buffer (e.g. D3DFMT_D16_LOCKABLE) to gain access - attempting to read the other (more common) formats will fail.

    hth
    Jack



  • Thodlak

    First off... reading back that sort of information can *really* hurt your performance. Don't do it unless you really have to Smile

    Do you want the pixel from the frame buffer or a texture

    Either way it involves "locking" the resource (see IDirect3DSurface9::LockRect() and/or IDirect3DTexture9::LockRect()) and then processing the raw pixel data. It can be quite an involved process if you're using an exotic pixel format. You get the raw binary data - not a convenient ARGB vector..

    If you want the frame buffer pixel colour, then use IDirect3DDevice9::GetFrontBufferData() along with the aforementioned locking technique.

    hth

    Jack



  • hoinar

    Thank you!
    Can I use depth value than direct to read current scene pixel's color value.
    Just like glReadPixel() in openGL,if just is  IDirect3DDevice9::GetFrontBufferData()
    Thank you again!

  • about get color value