• Advertisement
Sign in to follow this  

Render image

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