Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am working my way through Jack Hoxleys DirectX9 (http://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

Posted

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...

 

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...

Posted

DirectX 9.0c requires you to use a sprite argument.

MY class looks something like this

 

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

My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!)

vbprogramming.8k.com

My Project (Need VB.NET Programmers)

http://workspaces.gotdotnet.com/ResolutionRPG

Posted

Ah crap. Forums messed up my code again (squished the blue words together).

Yo Xebec - how'd 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.

My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!)

vbprogramming.8k.com

My Project (Need VB.NET Programmers)

http://workspaces.gotdotnet.com/ResolutionRPG

Posted

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...

Erutangis a si tahw
Posted (edited)

yup, 2003 :p

 

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

 

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

Edited by Loffen
Erutangis a si tahw
Posted

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

 


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();
}
}
}
[/Code]

Glenn "Mykre" Wilson, DirectX MVP

Inner Realm

Managed DirectX and Game Programming Resources

Posted (edited)

I tried the VB.NET code above, and it just doesn't 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 don't 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 won't work, but it just doesn't draw anything.

Edited by Aragorn7
Posted
I tried the code above, and it just doesn't 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 don't 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 won't work, but it just doesn't draw anything.

 

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

Glenn "Mykre" Wilson, DirectX MVP

Inner Realm

Managed DirectX and Game Programming Resources

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

 

Yes, the "null" doesn't work with VB.NET. I am sorry if I came across as saying that. I use VB.NET, and NULL doesn't work. You have to include a valid sprite object as a parameter.

Posted
"NULL" in C# = "Nothing" in VB.NET :).

Ya, both don't work. Nothing and Null are both worthless. I am running the latest of DirectX9c and VB.NET. Don't ask me why it doesn't, 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 can't understand why it isn't working. Apparently it works for some, but for me it didn't. You absolutely don't have to use a Rectangle to render text.)

Posted
Ya, both don't work. Nothing and Null are both worthless. I am running the latest of DirectX9c and VB.NET. Don't ask me why it doesn't, 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 can't understand why it isn't working. Apparently it works for some, but for me it didn't. You absolutely don't 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 what's 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 i'll switch to C# for my next project. I'm 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.

Posted
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. ;)
Posted
Email microsoft for their stupidity? :-P

 

Ahh...but someone probably already found the bug and we would end up looking stupid. Either way, it is more fun talking about it on the forums than it is to send a bug report to microsoft. :p

  • 1 month later...
Posted (edited)

DrawText (Alternative)

 

When I converted to DirectX 9.0c ran into the same problem with DrawText, it's very strict with parameters, while working with font declarations I finally got it to work as expected, when I finally got it down to where the syntax worked, the program ran but didn't display text, I later found this to be because of the DrawTextFormat settings, some settings will render the font while others won't. I've moved onto other things and now I can't find the class I made to work with DrawText easier, but even when things were going well I realized DrawText was incredibly impacting my frame rates slowing down and not doing well with memory performance, and the more text displayed the worse it was so I went in search of an alternative and considered using a generated text mesh, and behold it works like a charm.

 

Basically it's setup like this:

 

'Global Variables.

Private mesh3DText As Mesh = Nothing 'Mesh to draw 3d text.

Private fontName As String = "Arial" 'Name of the font you wish to use.

Private FontSize As Integer = 10 'Size of the font.

Private textMaterial As Material 'Material to color text.

Private matFont As Matrix = Matrix.Identity 'Matrix to position and scale. text.

Private currentFont As System.Drawing.Font 'Variable that stores the font.

 

'Put this code where your Direct3D device is initialized.

'Create a new font using the given parameters..

currentFont = New System.Drawing.Font(fontName, FontSize)

 

'Create 3D Text Mesh.

mesh3DText = Mesh.TextFromFont(mobjDX9, currentFont, "This is a test message...", 0.001F, 0.4F)

 

'Create the material that will be used for the mesh.

textMaterial = New Material

textMaterial.AmbientColor = New ColorValue(0, 16, 180, 255)

textMaterial.DiffuseColor = New ColorValue(0, 16, 180, 255)

 

'Now put this in the render portion of the program to render the text.

'Set text mesh rotation.

Dim matRot As New Matrix

matRot.RotateYawPitchRoll(0, 0, 0) 'XYZ

 

'Set text mesh scale.

Dim matScale As New Matrix

matScale.Scale(5.0F, 5.0F, 1.0F) 'XYZ (Note: To change font depth change Z, a higher value will result in more 3D look while lower results in a flatter 2D look.)

 

'Set text mesh position.

Dim matPos As New Matrix

matPos.Translate(-20, -10, 0) 'XYZ

 

'Combine all matrix calculations.

mobjDX9.Transform.World = Matrix.Multiply(Matrix.Multiply(matRot, matScale), matPos)

 

mobjDX9.Material = textMaterial 'Set material for render.

mesh3DText.DrawSubset(0) 'Render Mesh/DrawText.

 

:cool:

:D

Edited by Knight Chat X
  • 1 month later...
Posted
Good News! If you download the new December Update of the SDK and bind to the 1.0.2903.0 version of Microsoft.DirectX.Direct3DX the no overload most specific problem goes away.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...