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.
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.
You will now see your default form in front of you. This will suffice for our first program.
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.
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.
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.
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!!!!!