direct draw, windowed mode, garbage

Started by
3 comments, last by fireking 21 years, 6 months ago
im clearing the back buffer, then blt''n the back buffer to the primary, but i still get garbage(about 3 pixels tall at the top of the window), here are the routines
  
int ffengine::Clear(){
	DDBLTFX fx;

	fx.dwSize=sizeof(fx);
	fx.dwFillColor=RGB(0,0,0);
	if(FAILED(backbuffer->Blt(NULL,NULL,NULL,DDBLT_COLORFILL,&fx))){
		return FALSE;
	}
	return TRUE;
}
long ffengine::Render(){
	long val;
	POINT p;
	RECT dest_rect;
	RECT src_rect;

	p.x=0;p.y=0;
	ClientToScreen(hwnd,&p);
	GetClientRect(hwnd,&dest_rect);
	OffsetRect(&dest_rect,p.x,p.y);
	SetRect(&src_rect,0,0,pwidth,pheight);
	val=primary->Blt(&dest_rect,backbuffer,&src_rect,NULL,NULL);
	return val;
}
  
Please help... Fireking --Fireking Owner/Leader Genetics 3rd Dimension Development
--FirekingOwner/LeaderFiregames Development &Blackdragon Studios
Advertisement
no one answered the reply, thanks a lot people, but i found a solution for anyone that has this problem and doesnt know why

its because i put the same clipper on the primary on the back buffer, dont put a clipper on the back buffer, or it will cause garbage in windowed mode

also, if you need to clip something manuall(a surface being drawn to the back buffer), you need to use the following routine...


  //ffbitmap is a class//ffengine holds a directdraw object (dd)//primary is the primary surface in the class//backbuffer is the backbuffer surface in the class//this is in windowed modeint ffbitmap::Render(ffengine *e,long x,long y,long srcx,long srcy,long width,long height){	RECT dest_rect;	RECT src_rect;	SetRect(&dest_rect,x,y,x+width,y+height);	SetRect(&src_rect,srcx,srcy,srcx+width,srcy+height);	//Error Checking	//Sets the rectangles acting as a clipper	if(dest_rect.left<0){		src_rect.left-=dest_rect.left;		dest_rect.left=0;	}	if(dest_rect.top<0){		src_rect.top-=dest_rect.top;		dest_rect.top=0;	}	if(dest_rect.right>e->width){		src_rect.right-=dest_rect.right-e->width;		dest_rect.right=e->width;	}	if(dest_rect.bottom>e->height){		src_rect.bottom-=dest_rect.bottom-e->height;		dest_rect.bottom=e->height;	}	if(FAILED(e->backbuffer->Blt(&dest_rect,src,&src_rect,DDBLT_KEYSRC,NULL))){		return FALSE;	}	return TRUE;}  


this code effectively, will still draw your surface, even if its part of the way off of the screen.

hope i helped someone...

--Fireking

Owner/Leader
Genetics 3rd Dimension Development
--FirekingOwner/LeaderFiregames Development &Blackdragon Studios
The problem is not that you have a clipper on your backbiffer. It is more likely related to the fact that you were using the same clipper for back and front. Without seeing your window setup code, here''s my guess on what was going on - you weren''t adjusting the client area when you created the window, but you were using the client rect to set the backbuffer.

If you create a window with the dimensions 800x600, you will not get an 800x600 client area. Part of that space will be taken up by the titlebar and any menu bars you may have. This reduces the actual amount of client area you can draw to. To solve this, you have to call AdjustWindowRect (or AdjustWindowRectEx) when you create the window and use the modified dimensions. This will ensure that you have a client area of the exact size you requested.

This is a stab in the dark, but it sounds like that''s what was going on here. Since you were using the same clipper with both surfaces, the backbuffer was actually getting cheated out of a few pixels at the top. I don''t know offhand what else it could be - but I promise you it is okay to use a clipper on front and back.
I tried making a new clipper for the back buffer (bbclipper), but i figured setting it to the same hwnd will be exactley the same as having the same clipper on the primary and back buffer...

i dont know, its all so confusing! why didnt the sdk make it more clear about window styles and how they should be set up...

i hope when i do the revision of my ddraw wrapper class and ddraw surface wrapper class, that this doesnt show up again...

quote:Original post by Aldacron
The problem is not that you have a clipper on your backbiffer. It is more likely related to the fact that you were using the same clipper for back and front. Without seeing your window setup code, here''s my guess on what was going on - you weren''t adjusting the client area when you created the window, but you were using the client rect to set the backbuffer.

If you create a window with the dimensions 800x600, you will not get an 800x600 client area. Part of that space will be taken up by the titlebar and any menu bars you may have. This reduces the actual amount of client area you can draw to. To solve this, you have to call AdjustWindowRect (or AdjustWindowRectEx) when you create the window and use the modified dimensions. This will ensure that you have a client area of the exact size you requested.

This is a stab in the dark, but it sounds like that''s what was going on here. Since you were using the same clipper with both surfaces, the backbuffer was actually getting cheated out of a few pixels at the top. I don''t know offhand what else it could be - but I promise you it is okay to use a clipper on front and back.




--Fireking

Owner/Leader
Genetics 3rd Dimension Development
--FirekingOwner/LeaderFiregames Development &Blackdragon Studios
You can have the same clipper without a problem - you just have to make sure that the desired area you wish to draw to and the available client area are the same size. Take a look at the sample code base in the DX SDK, in particular the window creation code. You will see how the client area is adjusted appropriately. You can also find this in LaMothe''s Tricks of the Windows Game Programming Gurus - and more than likely in other books on DirectX. Even OpenGL code should use this trick, and there is and example of it online at nehe.gamedev.net in the tutorial on setting up OpenGL in windows. What you are looking for is the use of AdjustRect.

This topic is closed to new replies.

Advertisement