Getting Started With Visual Basic .NET

Notice: This tutorial assumes that you have a basic level of knowledge in Visual Basic .NET, and are able to do some programming in it. If you are not at least somewhat skilled in VB.NET, please consult a .NET programming manual. This tutorial assumes that you are working in Visual Studio .NET 2003 or 2002.

Getting Started

This tutorial will cover the step-by-step processing of creating a simple first program with TrueVision3D. The finished files are available here for your reference.

  • Create a new Windows Application, give it any name you would like.

You will now see your default form in front of you. This will suffice for our first program.

  • In the menu, click Project, then click Add Reference.

To include TrueVision3D into your project, you will need to add a reference to the files that came in the TV3D package. If installation was successful, you will see “TV3DSDK 6.2 - TV3DEngine” in the checkbox-list, under the “COM” tab. Check this box, and click OK. Visual Studio will now link the engine to your project.

  • Now, double click on your form to see your code for your default form.

Creating the Engine

To do anything with TV3D, we need to create the engine in the computer’s memory before we can use it. Start by adding the following above the line that reads “Private Sub Form1_Load”

  Dim TV As TrueVision3D.TVEngine
  Dim SText As TrueVision3D.TVScreen2DText
  Dim Input As TrueVision3D.TVInputEngine

These two lines will pave the way for you to create both the base TV3D engine, and also an object you can use to draw to the screen with it. Now that the objects are created, we will need to initialize them before we can use them. Add the following within the Form1_Load sub:

      TV = New TrueVision3D.TVEngine
      SText = New TrueVision3D.TVScreen2DText
      If TV.Init3DWindowedMode(Me.Handle.ToInt32) = False Then
          End
      End If
      Input = New TrueVision3D.TVInputEngine
      Input.Initialize()

The first two lines will create our two objects in memory. Declaring them in the first part only created the space in the computer’s memory where they will be, it did not actually create them.

The last bit calls the Init3DWindowedMode method in the engine, telling it to create a window in our current form (represented by Me.Handle). The engine will return false if an error occurs. In our program, we will tell the program to exit if the engine cannot, for some reason, be created.

The second last line will create our TV3D input engine, which monitors the keyboard and mouse, so that we can see if the user presses any keys while our program is running.

The last line initializes the Input Engine.

The Main Loop

In all games and real-time applications, there is a main loop. Since a game is always updating itself, it needs to loop infinitely. We will use a while loop to do 25this. Add the following code directly below where you were:

      Me.Show()
      Dim Running As Boolean = True
      While Running = True
          TV.Clear()
          SText.TextureFont_DrawText("Hello World!", 10, 10, &HFFFFFFFF)
          TV.RenderToScreen()
          If Input.IsKeyPressed(TrueVision3D.CONST_TV_KEY.TV_KEY_ESCAPE) Then
              Running = False
          End If
          Application.DoEvents()
      End While
      End

The first line, “Me.Show”, will force your window to the top of the user’s focus, so that your game isn’t hidden some other window the user may have open at the moment.

Then we create a variable called “Running”. As long as Running is true, our program will continue to run. If it becomes false, the program will quit. It’s a good idea to create any loop with some way to get out of it - or else you’d be stuck forever!

Now that we have our loop set up, we can get to the engine using. Notice that we call “TV.Clear”. You must do this every time you run through the loop, since it’ll clear your screen and let you draw to a blank screen. Imagine if we don’t clear the screen every time!

Now we call our “TextureFont_DrawText” method, this is a part of the engine that lets us draw any text message we want onto the screen. We want to draw “Hello World” at coordinates (10,10) - measured from the top left - and we want it to be white (&HFFFFFFFF, in complicated computer lingo).

Once we are done drawing to the screen, we must call “TV.RenderToScreen” to tell the engine we are done for now. The engine will now happily do its own thing.

This next segment allows us to quit our program when we want.

          If Input.IsKeyPressed(TrueVision3D.CONST_TV_KEY.TV_KEY_ESCAPE) Then
              Running = False
          End If

In simplified English, this means “If the escape key is held down, quit the program!”. Always very useful to have a way to quit your program.

The last line “Application.DoEvents()” is very important. This function lets your application call the internal delegates that will draw any changes to the form, as well as handle any form events, such as key presses.

Conclusion

There you have it. Your first program in TrueVision3D. It’s simple, but it is a base from where you can work. Good luck in your future TV3D endeavors!!!!!

==== Update for VS 2012 .Net 4.x

Some slight code changes:

This will be the FULL listing of the Form1.vb File, Be sure to Add the correct DLL as a Reference :(<Your TV3D Install Foldr>\TV3D SDK 6.5\sdk\dotnet\MTV3D65.dll)

’ Imports TV3D65

Public Class Form1

  Dim TV As TVEngine
  Dim SText As TVScreen2DText
  Dim Input As TVInputEngine
  Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
      TV = New TVEngine
      SText = New TVScreen2DText
      If TV.Init3DWindowed(Me.Handle.ToInt32) = False Then
          End
      End If
      Input = New TVInputEngine
      Input.Initialize()
      Me.Show()
      Dim Running As Boolean = True
      While Running = True
          TV.Clear()
          SText.TextureFont_DrawText("Hello World!", 10, 10, &HFFFFFFFF)
          TV.RenderToScreen()
          If Input.IsKeyPressed(CONST_TV_KEY.TV_KEY_ESCAPE) Then
              Running = False
          End If
          Application.DoEvents()
      End While
      End
  End Sub

End Class ’

By:mkiessli AT gmail DOT com

 
tv3d/getting_started_with_visual_basic.net.txt · Last modified: 2013/11/22 13:30