Jump to content
  • Advertisement
Sign in to follow this  
delbogun

OpenGL How do I copy Direct3D surface to custom buffer?

This topic is 4469 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How do I copy the content on a Direct3D surface to a custom buffer. Like the glReadPixels() does for OpenGL. I want to copy the data to a unsigned char* buffer. If I use IDirect3DDevice9::GetRenderTargetData or IDirect3DDevice9::GetBackBuffer the data have to be stored in a IDirect3DSurface9 object. Any tips on how I should do that? What I'm looking for is an Direct3D way to do this: unsigned char* buffer; glReadPixels(0,0,x,y,GL_RGBA,GL_UNSIGNED_BYTE,buffer);

Share this post


Link to post
Share on other sites
Advertisement
You can lock a surface, but that won't do colour conversion for you, and you'll have to compensate for the pitch yourself. As fas as I know you'd have the write a function to do the conversion yourself.

Share this post


Link to post
Share on other sites
I guess I'm screwed, but thanks alot for your help. I have no idea how to do the conversion myself. Doesn't that mean I have to know how IDirect3DSurface9 is built up? I could probably save the D3DSurface on a bitmap and then copy the bitmap to the buffer, but that would be too slow.

Share this post


Link to post
Share on other sites
Isn't reading off a locked surface pretty straight forward? Lock the surface get a pointer to the bits then read them into your (presumambly) array/buffer where you want to keep them? This would only be the raw values so to speak - you wouldn't be making another surface.

You have to be a bit careful about the pitch thing, it doesn'y exactly match the surfaces width or something, also if your surface is a 32 bit surface don't forget you'll be reading four bytes at a time into your buffer, ~the pointer from locked rect should be cast to match the surface etc.

I haven't got any working code to show (been a long time since I did this), Links which I just found by searching for D3DLOCKED_RECT on Google;

http://www.thehavok.co.uk/scene/32bits/tutorials/directx/thebasics/tut5drawing.php

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/D3DLOCKED_RECT.asp

http://nexe.gamedev.net/directKnowledge/default.asp?p=Texture

[Edited by - Stevieboy on July 28, 2006 4:35:06 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!