Sign in to follow this  

draw byte() with direct3d

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

Hello, I wrote in another post (http://www.gamedev.net/community/forums/topic.asp?topic_id=528110) that i get a byte() image from a camera and i have to paint it. Until now i do it with GDI but the use of CPU is too high so i think if i program it with directDraw it would be better. Aardvajk told me to work with Direct3D i look for samples, and now i have some doubts because there are too many concepts. [1.] I have a changing byte() image (the image from de camera 25fps) that will be a surface or a sprite? [1a.]if the image is a sprite my surface would be the pictureBox? [2.] im really confused with the steps i need, it seems to be easy i only have to paint a byte() bitmap(jpeg) in a pictureBox but i dont know how to do it with direct3d. Thanks.

Share this post


Link to post
Share on other sites
In such a situation the bottleneck would be transferring the image data from the CPU (RAM) to the GPU (VRAM) for rendering. I doubt that you can speedup your app by using another renderer because the bottleneck of updating the image when it changes is still there.

However, using Direct3D it would be best to create a texture and fill your image data into the texture by locking it. Then you render a textured rectangle with this image on the screen.

Share this post


Link to post
Share on other sites
Hi Waterwalker,

Im still a newbie with programation. I know i have a problem with this line:

aBitmap = Bitmap.FromStream(mStream, False, True)

(where mStream is a memoryStream which contains the byte() bitmap frame)

which works with a lot of CPU, and i thought if i could paint it more efficiently the problem wouldnt make so much "noise". I think we are talking of the same thing when you said "the bottleneck would be transferring the image data from the CPU (RAM) to the GPU (VRAM)".

How could i fix that?

Now i think using direc3d would not change anything, am i right?

Share this post


Link to post
Share on other sites
If this stream is linked to the camera and provides the image data you want to display then, actually, no. Using DirectX (either DDraw or D3D) won't help you there. So it seems the bottleneck is requiring the image from the camera, not transfering it to the VRAM (the graphics card) to display it.

Share this post


Link to post
Share on other sites
I think i dont understand.

I get an jpeg format images (one by one) from the camera in a byte(), which i convert to memoryStream, and then to bitmap so i can paint a pictureBox.

If i can "work" and render directly with the byte() i think the neckbottle wont exist. But can this be done with direct3d?

Thanks for your patience!

Share this post


Link to post
Share on other sites
Ah okay. You can directly load jpg files to Direct3D textures or surfaces. Check the DX reference for the functions D3DXCreateTextureFromFile(InMemory) or D3DXLoadSurfaceFromFile(InMemory). Those functions handle jpg format as well and pump the image data into either a texture or a surface.

If you are not experienced with DX I would recommend using a surface first which should be easier for you to draw on the screen.

edit: Further reading http://msdn.microsoft.com/en-us/library/bb219683(VS.85).aspx

Share this post


Link to post
Share on other sites
So it can be done, without bottleneck?

I found some difficulties, im a newbie and i dont know where i have to begin...

1. i look for the functions you told me about and it seems that it works with a jpeg file not with a byte().. i could i use a temp file to save the byte() into a file but im looking for a better option...

HRESULT D3DXCreateTextureFromFile(
LPDIRECT3DDEVICE9 pDevice,
LPCTSTR pSrcFile,
LPDIRECT3DTEXTURE9 * ppTexture
);Parameters
pDevice
[in] Pointer to an IDirect3DDevice9 interface, representing the device to be associated with the texture.
pSrcFile
[in] Pointer to a string that specifies the filename. If the compiler settings require Unicode, the data type LPCTSTR resolves to LPCWSTR. Otherwise, the string data type resolves to LPCSTR. See Remarks.
ppTexture
[out] Address of a pointer to an IDirect3DTexture9 interface, representing the created texture object.

2. which step do i need to do the application?

Thanks!

Share this post


Link to post
Share on other sites
Look at the declaration of D3DXCreateTextureFromFileInMemory as mentioned above. However, this involves creating a new texture each time you need to update the data. Usually you have raw bitmap data that you feed your texture. But it is worth a try how fast D3DXCreateTextureFromFileInMemory can convert the jpg data and create a new texture instance. You can easily call this function once in your code and do performance comparison against your stream conversion. If it is faster that's the way to go.

But as you will understand I won't go into more details of an actual implementation unless there are specific questions. If you have never done DX before you won't get it going today. Just jump on the DX tutorials and get the DX basics first, then.

Share this post


Link to post
Share on other sites
Quote:
Original post by cgillopez
Hello,

I wrote in another post (http://www.gamedev.net/community/forums/topic.asp?topic_id=528110) that i get a byte() image from a camera and i have to paint it.

Until now i do it with GDI but the use of CPU is too high so i think if i program it with directDraw it would be better.

Aardvajk told me to work with Direct3D i look for samples, and now i have some doubts because there are too many concepts.

[1.] I have a changing byte() image (the image from de camera 25fps) that will be a surface or a sprite?

[1a.]if the image is a sprite my surface would be the pictureBox?

[2.] im really confused with the steps i need, it seems to be easy i only have to paint a byte() bitmap(jpeg) in a pictureBox but i dont know how to do it with direct3d.

Thanks.



i suspect this might have been interpreted wrongly... i think maybe what he's saying is that he's trying to read literally from a camera (webcam maybe?) and wants to show that on the screen. GDI will therefore be hell slow if he is trying to read each individual byte of data for the image from the camera and then colour each individual pixel in the 'picturebox' (which i take to mean literally a picturebox component on the program form).

if this is the case then i assume DX can do this a million times better than trying to hack something together using GDI, which in the end will work but will be slow due to the nature of going through windows drawing routines and the black magic that windows does to draw on a canvas/form.

Share this post


Link to post
Share on other sites
Thanks both for your answer.

maybe my first post was a little ambiguous, as i explained:

"I get an jpeg format images (one by one) from the camera in a byte(), which i convert to memoryStream, and then to bitmap so i can paint a pictureBox."

so, what i want to do is render the byte()...

Now i know something like that could be done, i will study some tutorials.. any advice on this?

Share this post


Link to post
Share on other sites

This topic is 3194 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this