Archived

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

DocKode

DirectX 9 & VB .NET: I need help with 3DText sample from SDK!

Recommended Posts

Hello everyone... I am using VB .NET Standard I was able to atleast do and understand (mostly) the 6 tutorials provided in the DirectX 9 SDK but I got to the samples, Text3D... yikes... I've never programmed in it with VB .NET! I've messed around with DX8 and VC++ 6 but I don't really like C++... I bought Jim Adams book: Programming Role Playing Games with DirectX. I like it... But I would prefer a language I'm more comfortable with. My C++ is rather weak. So that is why I selected VB .NET. I've browsed through a few other DirectX books and sites as well but no documentation seems to be out for DX9 and VB .NET except that from MS. I am upset with Microsoft for providing such a complex example... I mean it is super confusing, I just wan't a simple 'Draw this String to Screen' and that is all. Nothing fancy like rotating 3d mesh text or 5 strings being displayed all at once. Also a seperate example explaining Stationary 3D Text might also be useful... though not necessary. So... I know you have better things to do, but I would really appreciate some help with this. I'm completely lost with 2D and 3D text. Thanks in Advance... I Really appreciate this really... DocKode Why sleep? You can do that when your dead. [edited by - DocKode on December 26, 2002 4:55:44 PM] [edited by - DocKode on December 26, 2002 6:17:12 PM] [edited by - DocKode on December 26, 2002 6:19:10 PM] [edited by - DocKode on December 26, 2002 6:20:38 PM]

Share this post


Link to post
Share on other sites
Oops! Forgot to ask something...

Please give me an example I can use in a single class (like MyProject.vb), I don't want to reference several other classes.

The example given in the SDK is divided up into several classes, each with different abilities like changing the font through menu's etc.

However I do not want to do all that is being done in that particular example. Only the most simple absolutely basic stuff.
I don't understand what it is I have to have absolutely and what is not necessary (just fancy extras for changing fonts and adding menus).

Thanks again!
DocKode

Why sleep? You can do that when your dead.

[edited by - DocKode on December 26, 2002 6:03:07 PM]

Share this post


Link to post
Share on other sites
Included in the D3DFont.vb file is the GraphicsFont class which has a number of text displaying functions. I''m sure you''ve already seen this, but if you just want to draw regular text, use it like this (my code''s actually C#, but the two languages are very similar syntax-wise, so you should be able to follow; just drop the semicolons):

Create your font object:

FontObject = new GraphicsFont(new System.Drawing.Font("Sans Serif", 10, FontStyle.Regular, GraphicsUnit.Pixel));
FontObject.InitializeDeviceObjects(device);

Then to draw your simple text, use:

FontObject.DrawText(ScreenCoordX, ScreenCoordY, Color.White, "Your text here");

And that''s it. Make sure you call DrawText before the EndScene call on your device. Note that the coordinates are actually the coordinates as they would appear on your screen, not those that you would use in your 3D environment.

I haven''t even bothered with 3D text yet, so I can''t give any pointers there.

Hope that helps.


Current Projects:
- Ariene GE (90%): Released as beta.

Share this post


Link to post
Share on other sites
I understand the code for it now... however I''m getting errors all over D3DFont.vb, note it is the only class I referenced I left the other''s from the example out, I don''t know If it would help to put them in too.

There are several errors all saying:

An unhandled exception of type ''System.NullReferenceException'' occurred in CreateDevice.exe

Additional information: Object reference not set to an instance of an object.

So what should I do to fix D3DFont.vb so it no longer does this. It never did it in the example.

It was also doing it with your code until I modified it to this:

''//This is the Font Object I created
Private myFont As GraphicsFont = Nothing
Private ourFont As New System.Drawing.Font("Arial", 18, System.Drawing.FontStyle.Bold)

''//This is in my Public Sub New()
myFont = New GraphicsFont(ourFont)
myFont.InitializeDeviceObjects(device)

''//This is right before the endscene()
myFont.DrawText(500, 500, Color.Blue, "This is a test")

So I had to make minor changes so it didn''t make that error.
Any help here I need Thanks for all your help so far Tri!
DocKode

Why sleep? You can do that when your dead.

Share this post


Link to post
Share on other sites
With respect to your null errors it sounds like you don''t have your device created. You''ll need to tie in the D3DApp class at least so you can create it (or at the very least, steal some init code from there). You need to create the device before you call InitializeDeviceObjects for your font.

Share this post


Link to post
Share on other sites
The problem is I do have my device created... If I remove the font code and the D3DFont.vb file from my project it produces the spinning 3d banana pipe from tutorial 5.

I'll try it though... I think...
Anymore help would also be useful, thanks for your help so far Tri! I appreciate it .

DocKode

Why sleep? You can do that when your dead.

[edited by - DocKode on December 29, 2002 7:53:46 PM]

Share this post


Link to post
Share on other sites
Tri, I figured it out!
What was happening before was I had put the InitializeDeviceObjects() code before I had actually created the device. I guess I wasn''t paying attention. Anyways I moved the code to a point after the the creation of the device and works!

It''s beautiful... Thanks for all your help Tri! I had no idea C# was so similar to VB .NET! Well Thanks again...! Really!

Greatfully,
DocKode

Why sleep? You can do that when your dead.

Share this post


Link to post
Share on other sites
Is there anyone who can help me out with alpha blending the 2D text? A small example would be nice... If not, I guess I can figure it out on my own with time.

Thanks in advance...
DocKode

Why sleep? You can do that when your dead.

Share this post


Link to post
Share on other sites
When you call DrawText(), you have to pass a Color parameter. This could be something you created already, or just accessed via Color.whatever. If you want to make your text transparent, make sure the Alpha component is less than 255. Ex:

FontObject.DrawText(X, Y, Color.FromARGB(128, 0, 0, 255), "My text")

That will draw the text using a solid blue, but it will only be at a 50% transparency (128/255 ~ 50%) level so it will be mixed with parts of the stuff behind it.

Hope that helps.

Share this post


Link to post
Share on other sites
Thanks again Tri!
The text is now alpha blended, but I was wondering... Once I reduce it's opacity the text becomes more dull looking... Is there some way to make it brighter? I actually would like to achieve an effect similar to glowing.

I'll keep playing around with the code to see if I can figure it out.
Again, thanks for your help .
DocKode

Why sleep? You can do that when your dead.

[edited by - DocKode on December 29, 2002 10:30:25 PM]

Share this post


Link to post
Share on other sites
Glowing is an affect I have yet to master :D. But I can offer a couple of thoughts for you:

- In specific regards to the text stuff, you could hack DrawText(float xpos, float ypos, Color color, string text, RenderFlags flags) to use CustomVertex.TransformTextured instead of CustomVertex.TransformedColoredTextured and set device.Material.Emissive = Color.whatever. Emissive materials tend to be very bright.

- The only other place I''ve seen glows are in Vertex Shaders. There''s a Glow sample in the C++ samples directory to look at.

I can''t be of any more help there since I haven''t tested any of these, so you''ll have some experimenting to do.

Have fun!

Share this post


Link to post
Share on other sites