#### Archived

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

# Blt Fill Problem

This topic is 5325 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites
Oops, didn't read it correctly. I'll get back to you if I figure it out.

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

##### 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 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 on other sites
You see, the thing is, I chose to code with DirectX 9. I was afraid something like this might happen. But that wasn''t my original question anyways...how do i fix the negatives?

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

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?

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

Hope this helps

Stevie

##### 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]