epsilon_ro

Hi all. First of all, I'm new to DirectX.
I'm trying to load an image into a PictureBox component (C#) using DirectX. The problem is that I'm working with large pictures (for ex. 4021x3123) and can't use the Windows GDI, because the picture takes a lot of memory and it flickers when I move the scrollbars. That's why I was thinking of using DirectX.
I've linked the DirectX Device with the PictureBox:

Device device = new Device(0, DeviceType.Hardware, pictureBox1, CreateFlags.SoftwareVertexProcessing, presentParams);

The problem is that I don't know how to load the image as a backgroud image using DirectX (i need to do some drawing on it after it loads). Is there a way to load it and prevent the flickering when i move the PictureBox's scrollbars Thanks.


Re: Game Technologies: Graphics loading large image using DirectX

BLANC Guillaume

Directx might help you doing what you want : load a texture and render it on a back buffer. That back buffer can cover a hwnd, but I'm not sure you'll be able to do something else but Directx rendering on that hwnd (you can still have a try).
If it's what you want to do, then you'll have to do something like:
- create a device
- load a texture
- render the texture on a full screen quad and offset texture coordinates to simulate scrolling. You can also render a quad completly mapped qith the texture and then scroll quad 2d coordinates.

For more details on each operations, see the Direct3D tutorials that cover those areas. Be carreful that your gfx card driver might not support such big textures (especialy non square and non power of two textures) and thus you'll need to subdivide your big image into smallest compatible textures and render each separatly.





Re: Game Technologies: Graphics loading large image using DirectX

epsilon_ro

Thanks for your reply. One of the problems is: can I load a texture which is not a power of 2 Because that's what I've read.. to load a texture, its size has to be a power of 2. Any links/tutorials for loading a texture in Directx

And how can I subdivide my picture intro smaller ones and only render that part of the picture that is displayed on screen Because I think it's useless to render even the parts that are not currently displayed.





Re: Game Technologies: Graphics loading large image using DirectX

bcristian

Actually, using Direct3D is not the best choice for your want, even more so if you want to edit the image. As a side note, it is possible to use the GPU for image editing and get better performance than using the CPU, but that's really an advanced topic.

First of all, using D3D will make the memory problem worse, much worse in fact, for at least 2 reasons:

  • the D3D system will eat some memory itself;
  • the image data that gets rendered to the screen is not directly accessible by the CPU (there are exceptions, but again this is not simple stuff), so you end up with at least 2 copies of the image.

Also, the performance would not be great either, because of the additional overhead of passing the data back and forth between the CPU and the GPU - readbacks from the GPU are particularly slow.

And if that's not enogh, please take my word on it that learning D3D programming to the level where you can write even a decent (not production-ready) image editor or advanced presentation layer using it is not going to be a one-week business.

On a more optimistic note, a better way to do this would be to stick to the Windows GDI+ API - at least that's how I would do it. Obviously, having a huge image in one piece and moving it around will be really slow, so you need to cut it in smaller pieces and display those of them that actually are visible. For really big images, you might even want to implement a streaming mechanism so that you don't stall the application while reading 10+ MB of data from the disk. Oh, and yeah, this is another reason you might want to stay away from D3D for this app: for virtually all the cards around, the texture size limit is 4096x4096, or even 2048x2048 for older ones.





Re: Game Technologies: Graphics loading large image using DirectX

epsilon_ro

Thanks for your complete reply. I've understood what you said and decided on not using DirectX anymore, especially that it doesn't support very large textures. I will try to use GDI instead. Thanks again.