Jump to content
  • Advertisement
Sign in to follow this  
allbabel

Render image

This topic is 4412 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

I am beginner with DirectX. I am trying to render a bitmap with DirectX 9 and I am little lost in how to achieve this. I have managed to display a simple bitmap by creating a surface writing data to it and then updating the back buffer with my new surface that I have written data to. My goal is to eventually display YUV data but I am now thinking that the method I am using isn't the correct way. I had a look over the documentation and should I not use a texture instead to achieve what I am trying to do? Is there now tutorials for DirectX 9 out there? I have had a look around and they all seem to be for DirectX 8. Thanks

Share this post


Link to post
Share on other sites
Advertisement
If you're using Direct3D, you want to avoid locking the backbuffer at all costs, and avoid copying directly to it as much as possible. The general way to do it is to use a textured quad. D3DX can load a BMP onto a surface for you (See the D3DXCreateTExtureFromFile and D3DXCreateTextureFromFileEx functions), and then drawing it is just a case of rendering a quad (2 triangles).

Share this post


Link to post
Share on other sites
Thanks for the tips. I am using DirectX to display a video stream so the bmp will be in memory - So all I need to do is create a texture and copy this data to it?
Sorry for the dubm questions I just beginning...

Share this post


Link to post
Share on other sites
I forget the details (not on my dev machine, so dont have stuff available) but IDirect3DDevice9::StretchRect() can be used for copying video (e.g. YUV format) to renderable textures (e.g. RGB) and performing any necessary resizing/stretching. It should also be hardware accelerated, which is A Good Thing™.

Dont create a texture for each frame - that'll really hurt. Instead create a single texture and re-use it for each frame; if that doesn't work smoothly a bounded-buffer approach might be beneficial.

Its a bit of a grey area (unsupported and might require black magic to understand/use) but you might want to check out DirectShow in the PSDK (think its now called the "Windows SDK"). DShow is designed for video playback and it has (or had) a couple of samples for getting it to interact with Direct3D - admittedly they never worked well for me but it could be worth checking.

hth
Jack

Share this post


Link to post
Share on other sites
Thanks Jack, So I would need to:
a) Create a texture
b) Create a surface
c) Write to my surface from b)
d) Use StretchRect to copy this to the texture
I looked at DirectShow and it seemed way over complicated for what I wanted to do.
Also, I have noticed that D3DXCreateTexture() works rather than CreateTexture() with the same params, why is this???
Andy

Share this post


Link to post
Share on other sites
I can't find the web page where I learned this, but here's how I do 2d in DX9


// START: OnCreateDevice
DXUTFindDXSDKMediaFileCch( str, MAX_PATH, filename );
D3DXCreateTextureFromFile( pd3dDevice, str, &d3dtexture );
D3DXCreateSprite( pd3dDevice, &ppSprite );
// END: OnCreateDevice

// START: OnFrameRender
ppSprite->Begin(D3DXSPRITE_ALPHABLEND);

// Trans is the x and y coords where you want the texture painted
D3DXMATRIX Mat;
D3DXMatrixTransformation2D(&Mat, NULL, 0, NULL, NULL, 0, Trans );
ppSprite->SetTransform(&Mat);
ppSprite->Draw(d3dtex, NULL, NULL, NULL, 0xFFFFFFFF);

ppSprite->End();
// END: OnFrameRender


You're also going to need a ppSprite->OnResetDevice(), ppSprite->OnReleaseDevice, and ppSprite->OnLostDevice() in their proper locations.

I hope this helps

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!