drawtext errors and sprites

davidrobin

Active member
Joined
Jun 24, 2003
Messages
41
I am working my way through Jack Hoxleys DirectX9 (www.directx4VB.com) example. When I try and compile the application I get this error:

Overload resolution failed because no accessible DrawText accepts this number of arguments.

The line of code giving me this error is this:

fntOut.DrawText(sDevInfo, _
New Drawing.Rectangle(5, 5, 0, 0), _
DrawTextFormat.Left Or DrawTextFormat.Top, _
Drawing.Color.FromArgb(255, 200, 128, 64))

fntOut declaration is this:
Private fntOut As Font

When I look at the declaration for the drawtext method of the font object the first parameter is always a sprite. It also says sprite can be null (which is what I want). How do you specify null in VB?

I have searched google for examples of this method but have not found a single example that uses the sprite object.

Can anyone help
 
From what i can see in the sdk, you dont seem to be passing anykind of sprite in, null or otherwise

if this is the call your after

public int DrawText(Sprite, string, ref Rectangle, DrawTextFormat, Color);

and sDevInfo is your string to be displayed you would still need a sprite of some sort

soo...

Code:
Dim MySprite as Microsoft.DirectX.Direct3d.Sprite
..
MySprite = new Microsoft.DirectX.Direct3d.Sprite(d3ddevice)
...
fntOut.DrawText(MySprite, _
sDevInfo, _
New Drawing.Rectangle(5, 5, 0, 0), _
DrawTextFormat.Left Or DrawTextFormat.Top, _
Drawing.Color.FromArgb(255, 200, 128, 64))

where d3ddevice is a valid device, might be the sort of thing your after - might not even have to initilise MySprite either (ie replacing second line with MySprite = nothing, or removing it all together maybe what the sdk is referingto by null)

- havnt dabbled with the DrawText routines myself yet...
 
DirectX 9.0c requires you to use a sprite argument.
MY class looks something like this

Code:
[size=2][color=#0000ff]Public[/color][/size][size=2] [/size][size=2][color=#0000ff]Class[/color][/size][size=2] clsText

[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] TheFont [/size][size=2][color=#0000ff]As[/color][/size][size=2] Microsoft.DirectX.Direct3D.Font = [/size][size=2][color=#0000ff]Nothing

[/color][/size][size=2][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] rect [/size][size=2][color=#0000ff]As[/color][/size][size=2] [/size][size=2][color=#0000ff]New[/color][/size][size=2] Rectangle(0, 0, 0, 0)

[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] x [/size][size=2][color=#0000ff]As[/color][/size][size=2] Microsoft.DirectX.Vector3

[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] y [/size][size=2][color=#0000ff]As[/color][/size][size=2] Microsoft.DirectX.Vector3

[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] s [/size][size=2][color=#0000ff]As[/color][/size][size=2] Microsoft.DirectX.Direct3D.Sprite

[/size][size=2][color=#0000ff]Public[/color][/size][size=2] [/size][size=2][color=#0000ff]Sub[/color][/size][size=2] [/size][size=2][color=#0000ff]New[/color][/size][size=2]([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] d3ddev [/size][size=2][color=#0000ff]As[/color][/size][size=2] Microsoft.DirectX.Direct3D.Device, [/size][size=2][color=#0000ff]Optional[/color][/size][size=2] [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] fontname [/size][size=2][color=#0000ff]As[/color][/size][size=2] [/size][size=2][color=#0000ff]String[/color][/size][size=2] = "Courier", [/size][size=2][color=#0000ff]Optional[/color][/size][size=2] [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] Size [/size][size=2][color=#0000ff]As[/color][/size][size=2] [/size][size=2][color=#0000ff]Integer[/color][/size][size=2] = 10)

TheFont = [/size][size=2][color=#0000ff]New[/color][/size][size=2] Microsoft.DirectX.Direct3D.Font(d3ddev, [/size][size=2][color=#0000ff]New[/color][/size][size=2] System.Drawing.Font(fontname, Size))

s = [/size][size=2][color=#0000ff]New[/color][/size][size=2] Microsoft.DirectX.Direct3D.Sprite(d3ddev)

[/size][size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]Sub

[/color][/size][size=2][/size][size=2][color=#0000ff]Public[/color][/size][size=2] [/size][size=2][color=#0000ff]Sub[/color][/size][size=2] Drawtext([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] text [/size][size=2][color=#0000ff]As[/color][/size][size=2] [/size][size=2][color=#0000ff]String[/color][/size][size=2], [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] cColor [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.Drawing.Color)

[/size][size=2]s.Begin(Microsoft.DirectX.Direct3D.SpriteFlags.AlphaBlend)[/size]
[size=2]TheFont.DrawText(s, text, 0, 0, cColor)
s.End()
[/size][size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]Sub[/color][/size]
[size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]Class[/color][/size]
[size=2][color=#0000ff]
[/color][/size]
 
Ah crap. Forums messed up my code again (squished the blue words together).
Yo Xebec - howd you get your code to appear in "Black And White"..
i used [ code ] tags.. it appears in color and double spaces and squishes em together.
 
Are you sure your text class works?? I cant even compile it:

Spriteflags is not a member of Direct3D
s.Begin(Microsoft.DirectX.Direct3D.SpriteFlags.AlphaBlend)

Overload resolution failed because no accessible DrawText acceps this number of arguments:
TheFont.DrawText(s, text, 0, 0, cColor)

I tested with both 9.0b and 9.0c...
 
yup, 2003 :p

BTW: I wrote(ehrr.. modified a not working class) a working text class:

Code:
Imports Microsoft.DirectX
Imports Microsoft.DirectX.Direct3D
Imports Microsoft.DirectX.Direct3D.D3DX
Imports System.Math

Public Class clsLoffText
    Private pDevice As Device

    Dim TheFont As Font = Nothing
    Dim rect As New Rectangle(0, 0, 0, 0)

    Dim s As Direct3D.Sprite

    Public Sub New(ByVal pDevice As Device, Optional ByVal FontName As String = "Courier", Optional ByVal Size As Integer = 10)

        TheFont = New Font(pDevice, New System.Drawing.Font(FontName, Size))

        s = New Sprite(pDevice)

    End Sub

    Public Sub Drawtext(ByVal text As String, ByVal cColor As System.Drawing.Color, ByVal rect As System.Drawing.Rectangle)

        s.Begin()
        TheFont.DrawText(text, rect, 0, cColor)
        s.End()
    End Sub
End Class
 
Last edited by a moderator:
Converted to C#

For anyone who is interested, I have converted the Code to C# as this is the main language that I am using and this class looks like it could come in handy

Code:
using System;
using System.Drawing;

using Microsoft.DirectX;
using mDxDirect3D = Microsoft.DirectX.Direct3D;

namespace mDx3D_TextSample
{
	/// <summary>
	/// Summary description for mDx3DText.
	/// </summary>
	public class mDx3DText
	{
		private Device mDevice;
		private mDxDirect3D.Font mD3DFont;
		private Rectangle mRect = new System.Drawing.Rectangle(0,0,0,0);

		private Sprite mD3DSprite;

		public mDx3DText()
		{
			//
			// TODO: Add constructor logic here
			//
		}

		public mDx3DText(Device mDx3DDevice, string FontName, int Size)
		{
			mDevice = mDx3DDevice;
			mD3DFont = new mDxDirect3D.Font(mDx3DDevice, new System.Drawing.Font(FontName,Size));
			mD3DSprite = new Sprite(mDevice);
		}
		public void DrawText(string MessageText,System.Drawing.Color FontColor,System.Drawing.Rectangle Rect)
		{
			mD3DSprite.Begin(0);
			mD3DFont.DrawText(null,MessageText,Rect,0,FontColor);
			mD3DSprite.End();
		}
	}
}
 
I tried the VB.NET code above, and it just doesnt work. The problem was with the fact that there are two overloaded functions that are exactly the same (take the same parameter). One uses "ByRef RECT as Rectangle" and the other uses "RECT as Rectangle". I dont know why MS did this, but the solution is to just use x and y coordinates to draw the text.

Also, make sure you use a VALID sprite object, I have no clue why an invalid one wont work, but it just doesnt draw anything.
 
Last edited by a moderator:
Aragorn7 said:
I tried the code above, and it just doesnt work. The problem was with the fact that there are two overloaded functions that are exactly the same (take the same parameter). One uses "ByRef RECT as Rectangle" and the other uses "RECT as Rectangle". I dont know why MS did this, but the solution is to just use x and y coordinates to draw the text.

Also, make sure you use a VALID sprite object, I have no clue why an invalid one wont work, but it just doesnt draw anything.

You can set the sprite object to NULL. (C# Code above) and it works.
 
Mykre said:
You can set the sprite object to NULL. (C# Code above) and it works.

Yes, the "null" doesnt work with VB.NET. I am sorry if I came across as saying that. I use VB.NET, and NULL doesnt work. You have to include a valid sprite object as a parameter.
 
ThePentiumGuy said:
"NULL" in C# = "Nothing" in VB.NET :).
Ya, both dont work. Nothing and Null are both worthless. I am running the latest of DirectX9c and VB.NET. Dont ask me why it doesnt, but I found that using the (X,Y) overloaded function seems to solve it.

(This is mainly for anyone else that was reading and was confused or cant understand why it isnt working. Apparently it works for some, but for me it didnt. You absolutely dont have to use a Rectangle to render text.)
 
Aragorn7 said:
Ya, both dont work. Nothing and Null are both worthless. I am running the latest of DirectX9c and VB.NET. Dont ask me why it doesnt, but I found that using the (X,Y) overloaded function seems to solve it.

(This is mainly for anyone else that was reading and was confused or cant understand why it isnt working. Apparently it works for some, but for me it didnt. You absolutely dont have to use a Rectangle to render text.)

Thank God. Finally I found a forum which discuss this problem. I encountered this problem when migrating from dx9b to dx9c. Well, below is my experience:
1. Working with x and y only, is indeed working, but you cannot enjoy the Format option, such as Center or Right. In my application these two options are real important.
2. The code is working in C# but not in vb.net. I do not know whats wrong with microsoft. Prove this by running the sample included in the SDK. I found it strange, MS do not include vb.net and c++ sample coding anymore. All are C# sample. Try running the 3D Text Sample and examine the code. The parameters are same but with the same parameter format, you will get the mentioned error in VB.NET.

I think ill switch to C# for my next project. Im dying wanna use the dx9c, but alot of center and right alignment need to be done. Anyone has the solution for me? In returns, I can post some of my research on how to improve the dx application performance (reading thru the Tom Miller Managed DX Book)

Thank you.
 
You could make your own alignment functions. If you have programmed your classes in an object oriented way, make sure each "element" has a width and height that can be used in centering text. Either way, it will definitely take a lot of work. ;)
 
Back
Top