Archived

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

True Edge

Blt Fill Problem

Recommended Posts

DDBLTFX ddbltfx;
	RECT dest_rect;

	memset(&ddbltfx,0,sizeof(ddbltfx));

	ddbltfx.dwSize = sizeof(ddbltfx);
	ddbltfx.dwFillColor = RGB16(rand()%256,rand()%256,rand()%256);

	unsigned short y1 = rand()%SCREEN_HEIGHT;
	unsigned short y2 = rand()%SCREEN_HEIGHT;
	unsigned short x1 = rand()%SCREEN_WIDTH;
	unsigned short x2 = rand()%SCREEN_WIDTH;

	dest_rect.bottom = y2;
	dest_rect.top = y1;
	dest_rect.left = x1;
	dest_rect.right = x2;

	lpddsprimary->Blt(&dest_rect,NULL,NULL,DDBLT_COLORFILL | DDBLT_WAIT,&ddbltfx);
ok, what it''s telling me is that there are negative values for the coordinates. The program still works without crashing but when you exit it gives you the "this program now has to close" message which is annoying . I made the variables unsigned, shouldn''t that make the negatives go away? Direct3D9: (ERROR) :Invalid destination dimensions: Zero/Negative Heights and/or Widths not allowed Direct3D9: (ERROR) :Erroneous dest dimensions were: (wid -285, hgt -270) I don''t know what Direct3d is doing there.

Share this post


Link to post
Share on other sites
BTW, if this affects my predicament: I''m using Tricks of the Windows Game Programming Gurus. And I believe this book uses DirectX 4? I''m using DirectX 9. I copied exactly what his code said. (Understanding it too)When I''m typing the Blt function, Visual Studio gives you the parameters while you''re typing and for some reason the prototype is:

Blt(THIST_LPRECT,LPDIRECDRAWSURFACE7)

even though the book gives a couple more parameters.

Share this post


Link to post
Share on other sites
If you have the first edition, you're programming in DX 6.1, and in the second edition, you're drawing with DX 7.0.

If it's giving you Blt(THIST_LPRECT,LPDIRECDRAWSURFACE7), you must have a IDirectDrawSurface7 interface pointer. DirectDraw stopped at DX 7.0, so you're getting the latest interface.

From what I remember, he writes LPDIRECTDRAWSURFACE instead of LPDIRECTDRAWSURFACE4. It'll give you the wrong pointer for the code if you do it the first way. Flip forward a couple pages and see if his interface pointers change in the example code.

Other than that, check the source code.

[edited by - Weston on July 25, 2003 9:41:41 PM]

Share this post


Link to post
Share on other sites
I think the problem is indicated by the error messages... negative width/height.

Take your code...
unsigned short y1 = rand()%SCREEN_HEIGHT;
unsigned short y2 = rand()%SCREEN_HEIGHT;
unsigned short x1 = rand()%SCREEN_WIDTH;
unsigned short x2 = rand()%SCREEN_WIDTH;
dest_rect.bottom = y2;
dest_rect.top = y1;
dest_rect.left = x1;
dest_rect.right = x2;

and ask yourself what if y1>y2 or x1>x2?

I''d suggest sorting your coords...

if y2>y1 then swap y1,y2 ... etc before applying them to the rect

Hope this helps




Stevie

Don''t follow me, I''m lost.

Share this post


Link to post
Share on other sites
stevie56: that makes so much sense but unfortunately it didn't fix the problem. :-
oh wait, yes it did. Thanks!

(I just have to make it so the width and height aren't 0. )

[edited by - True Edge on July 25, 2003 10:04:56 PM]

[edited by - True Edge on July 25, 2003 10:05:13 PM]

Share this post


Link to post
Share on other sites