Archived

This topic is now archived and is closed to further replies.

SikCiv

D3DX Init Problems.

Recommended Posts

Im trying to get some 3D in my game so ive implemented D3DX from the Sprite.cpp sample. Ive pretty much copied and pasted the init code without changing it at all, but when I run it in my game, it spews at the D3DXCreateContext() function, saying: "DirectDraw does not have enough memory to perform the operation" I run Sprite.exe (D3DX sample) and it runs perfect. What could be the problem? Im using the same LIB and H files. Im not creating the DirectDraw7 Object first either. Is it possible to have D3DX drawing objects over a DirectDraw primary Surface, along with 2D blits drawing various sprites? I also have about 6 640x480x16bit DDraw7surfaces. Is this ok? Also, what does #define D3D_OVERLOADS do? (refer to sprite.cpp)

Share this post


Link to post
Share on other sites
You might be out of memory because of the size of all your directdrawsurfaces. Also if your using D3DX you dont need to do any of the DirectDraw initialization either. Once you get your context from D3DXCreateContext you can call GetDD(). You also need to make sure you call D3DXInitialize().

Share this post


Link to post
Share on other sites
Im initing D3DX ''before'' DirectDraw, thats why im stumped.

My program''s DoInit function is like so..
1) Create the app.
2) Create the hWnd Window.
3) Load my default settings for my sprites etc..
4) Call D3DX init. (This is where it fails).
5) Call DDraw init (create surfaces)

in 3) i memalloc a 640x200 array, and I have about 5K of struct arrays, but still, this shouldnt affect the amount of D3DX memory? The system has 64MB of memory, so there is loads of mem available.

Is there any source I can D/L where the app/game inits D3DX then some DDraw surfaces?

The Micrasoft samples are only ''little'' sample apps without any additional DDraw surfaces used, so I dont have much to learn off.

Share this post


Link to post
Share on other sites
Does the program fail on D3DXInitialize() or D3DXCreateContext()?

After you have created the context you create your directdraw surfaces as usual by getting the DirectDraw interface from the context with GetDD().

#define D3D_OVERLOADS lets you use the operator overloads that are defined for the D3D vectors, matrices etc. These include initialization and mathematical operators.

Share this post


Link to post
Share on other sites
Have you tryed using D3DXGetErrorString to return the exact error HRESULT? Also, where is the "DirectDraw does not have enough memory to perform the operation" error message coming from? I''m wondering, because if it''s from your own App then you might be incorrect about the actual error (I''ve done that accidently a couple of times ).

Oh yeah, how much memory does you video card have? I know that the Sprite sample runs in a pretty small window -- so it''s probably not using as much memory as your app is.

--TheGoop

-------------------------
If cities were built like software is built, the first woodpecker to come along would level civilization

Share this post


Link to post
Share on other sites
The error is from the CreateContext function, ive tried the app on a Desktop with 8MB VidMem and all is ok, but when i try it on a laptop with 2.5MB, it says not enough memory.
How do I work around this problem?

Also, does the getDD() function create the DD7 interface, or do u have to create the DD7 before you call GetDD()?

I used GetDD to create the interface, but when I try to create the Co-op level for DD7 to fullscreen, it says "already in exclusive mode, window mode works ok.
I took the co-op set function out, it works, but what when I create the back buffer, it returns with an error.

How do I get a pointer to the back buffer created by GetDD()?

Can u mix 2D surface drawing with D3DX?

what I need to do is blit the background in 2D, then draw some 3D objects over it. Is this possible? or do I need to convert all my background drawing to 3D blitting using D3DXDrawSpriteSimple?



Share this post


Link to post
Share on other sites
quote:
Original post by SikCiv

The error is from the CreateContext function, ive tried the app on a Desktop with 8MB VidMem and all is ok, but when i try it on a laptop with 2.5MB, it says not enough memory.
How do I work around this problem?




In a previous post in this thread you said you allocated 6 640x480x16bit pages. Some maths

640x480 = 307200 pixels @ 16-bpp = 614400 bytes = 600K
6 of these pages = 3600K = (approx) 3.6Mb

So you have already allocated all of the laptop''s video ram before you initialise D3DX.

By default DirectDraw and Direct3D will allocate surfaces in video ram unless specifically requested otherwise. D3DX will create a front buffer, at least one back buffer and a depth buffer. All of which it will try and allocate in video memory for optimal performance, but since you don''t have any video memory left you get your error.

The solution is to first create D3DX and then allocate your 640x480 surfaces one at a time in video memory until you run out of memory and then allocate the remaining in system memory (use the flag DDSCAPS_SYSTEMMEMORY when you CreateSurface() ).

However if you video card cannot render directly from system memory then rendering calls whose source is a system memory surface will fail. The alternative is to perform some kind of surface management. DirectX 6 and above provides in built texture management (although its only half decent in DX7). Look up texture management in the SDK help, its a flag you specify when you create the surface.

In addition I would reduce the size of your surfaces from 640x480 to say 256x256. Some video hardware might not be able to render from non-power of 2 size surfaces (check the device caps). It will also help reduce (but not eliminate!) the cost of any texture management cache misses.

quote:

Also, does the getDD() function create the DD7 interface, or do u have to create the DD7 before you call GetDD()?



No you should use D3DX in this kind of fashion

1) D3DXInitialise()
2) D3DXCreateContext() or D3DXCreateContextEx()
3) If all succeeded then you use the following methods to
retrieve the various interfaces created by D3DX

i) GetDD() - Retrieves a pointer to the IDirectDraw7
interface.
ii) GetD3D() - Retrieves a pointer to the IDirect3D7
interface.
iii) GetD3DDevice() - pointer to a IDirect3DDevice7
interface.
iv) GetPrimary() - pointer to the front buffer.
v) GetBackBuffer( int n ) - pointer to the n''th back
buffer (usually supplying 0 is sufficient).
vi) GetZBuffer() - pointer to the z-buffer.

Note that all the Get functions will increase the reference counts of the interfaces, so be sure to Release the interfaces you are given when you finish with them at the end of your app, otherwise you will get resource leaks.

quote:

Can u mix 2D surface drawing with D3DX?

what I need to do is blit the background in 2D, then draw some 3D objects over it. Is this possible? or do I need to convert all my background drawing to 3D blitting using D3DXDrawSpriteSimple?






Unfortunately I can''t help you with this since I haven''t used D3DX''s sprite drawing functions.

HTH

Chris


Chris Killpack : ckillpack@eaeurope.com
Technology Group : Bullfrog Productions Ltd

Share this post


Link to post
Share on other sites