Render image

Started by
4 comments, last by valles 17 years, 9 months ago
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
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).
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...
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

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

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
I can't find the web page where I learned this, but here's how I do 2d in DX9

// START: OnCreateDeviceDXUTFindDXSDKMediaFileCch( str, MAX_PATH, filename );D3DXCreateTextureFromFile( pd3dDevice, str, &d3dtexture );D3DXCreateSprite( pd3dDevice, &ppSprite );// END: OnCreateDevice// START:  OnFrameRenderppSprite->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

This topic is closed to new replies.

Advertisement