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

## Recommended Posts

When drawing text using LPD3DXFONT->DrawText() you specify a RECT in which the text should be. Generally this works fine except when the RECT.left or RECT.top parameters are negative, meaning the rect is (slightly) outside to the left or top of the screen. This clips away more of the text than it should. Screenshot: http://img25.imageshack.us/my.php?loc=img25&image=DrawTextError.jpg The flags I use are: DT_LEFT | DT_WORDBREAK | DT_NOPREFIX I've tried lots of other flag combos too (including DT_NOCLIP) but nothing helps. How do you make proper clipping when drawing outside the screen? (To the left and top. Right and bottom clipping works fine)

##### Share on other sites
I just used DT_WORDBREAK with a top and left of -5 and -5 and it seemed to work fine. Your link seems to redirect to the index3.php page. Can you post your pic somewhere else?

##### Share on other sites
Here is a test program. A text is displayed at the mouse's position. Move the mouse so the text goes outside to the left (or top) and you'll see that the text is weirdly slipped.

http://seiken.co.uk/mgp/MLibrary/BuggyDrawText.zip

##### Share on other sites
I don't see anything wrong:

Is this the right program?

##### Share on other sites
Ops, I accidently picked an earlier version. Here is the correct one, with text displayed at the mouse (same link as before):

http://seiken.co.uk/mgp/MLibrary/BuggyDrawText.zip

##### Share on other sites
I think what you want to do is cap the left and top to the bounds of the window. Instead of going negative, set to 0 so the text always stays in the window. Post the code where you update the rect and draw the text and maybe more people can help.

##### Share on other sites
Well, the point is I want to be able to render it outside the screen making only parts of it show.

Here is the method for rendering text:
//+-----------------------------------------------------------------------------//| Renders text on the screen//+-----------------------------------------------------------------------------BOOL Magos::DllMGraphics::RenderText(INT FontId, STRING Text, CONST MVector2D& Position, CONST MColor& TintColor){	//Data	DWORD Flags;	RECT TempRect;	std::string TempText = Text;	//Aborts if uninitialized	if(State == MGRAPHICS_UNINITIALIZED)	{		ErrorMessage = "Unable to render, MGraphics is uninitialized!";		return FALSE;	}	//Aborts if the font ID is invalid	if(!ValidFont(FontId))	{		ErrorMessage = "The given font ID is invalid!";		return FALSE;	}	//Aborts if no string is given (which causes a crash)	if(TempText == "") return TRUE;	//Sets the flags	Flags = DT_LEFT | DT_WORDBREAK | DT_NOPREFIX;	//Sets up the location rect	TempRect.left = Position.X;	TempRect.top = Position.Y;	TempRect.right = ScreenWidth;	TempRect.bottom = ScreenHeight;	//Renders the text	if(FontList[FontId].Font->DrawText(TempText.c_str(), TempText.length(), &TempRect, Flags, MCOLOR(TintColor)) == 0)	{		ErrorMessage = "Unable to render text!";		return FALSE;	}	//Returns success	return TRUE;}

##### Share on other sites
Try just DT_LEFT or DT_LEFT | DT_TOP. If you use DT_WORDBREAK, it will break between words. And I think DT_NOPREFIX isn't really used anymore. You can look at the current DrawText method and the archived DrawText method to see it isn't listed anymore.

##### Share on other sites
I've tried nearly every possible flag combo, and even no flags at all (0) but with no results. Has anyone successfully rendered text outside the screen? I'd really like to know that. If not I'm going to assume that this is a bug or miss by the DX implementers. Thanks for your help so far!

##### Share on other sites
Here I render "This text is rendered outside the window with top = left = -10."

I use rect.top = rect.left = -10;
My flag is just DT_WORDBREAK;

• 21
• 13
• 9
• 17
• 13