TV3D Beta - Getting started with C++ using VS.NET

This tutorial was written by Anti-Gremlin and posted on the forums.

Setting up the Project

Before you can start programming using the TV3D Engine you must first set up your project. This process is fairly simple but is very important to be able to properly run the engine within your project.

  • Create a project of the type “Win32 Project” (Refer to figure 01). Name the project, for example “Tutorial 01”, then click OK. Before proceeding any further, you should place a copy of the TV3D65.dll into your ‘Debug’ folder of the project. Once the project has loaded, You need to make some changes to the configuration of the project.
    (Figure 01):
  • In the Solution Explorer, Right click on your project name (make sure you do not right click on the Solution, but the project which is just under it), and select “Properties” (Refer to figure 02). This brings up the configuration settings for your project.
    (Figure 02):
  • In the C/C++ Folder, under “General” sub section. The field “Additional Include Directories” needs to be set with the include files for both DirectX and TV3D (Refer to figure 03)
    The default value for this is: C:\DXSDK\Include;C:\TV3DSDK\Include
    The warning level should be set to Level 4 (Not required, but better standard to use as things will be more strict)
    (Figure 03):
  • You now need to include the TV3D Library to your project (Refer to figure 04), this file is used by TV3D to reference between the DLL and your application.
    (Figure 04):

Loading the Engine

Setting up the header files

The StdAfx.h file is used for loading up all required include header files for your project. To start off with, we need to add windows.h (needed by TV3D) and the TV3D header files. The example below loads up all available header files from TV3D. Realistically you only need to load up the header files that you will actually use within your application.

Sample (StdAfx.h):

// Windows Header Files
#include < windows.h > 
 
// TrueVision3D Header Files (For Reference) 
#include "CTVActor.h" 
#include "CTVAI.h" 
#include "CTVAtmosphere.h" 
#include "CTVBitmapParts.h" 
#include "CTVCamera.h" 
#include "CTVCameraFactory.h" 
#include "CTVCollisionResult.h" 
#include "CTVDeviceInfo.h" 
#include "CTVEngine.h" 
#include "CTVGameController.h" 
#include "CTVGameControllers.h" 
#include "CTVGlobals.h" 
#include "CTVGraphicEffect.h" 
#include "CTVInputEngine.h" 
#include "CTVInternalObjects.h" 
#include "CTVLandscape.h" 
#include "CTVLightEngine.h" 
#include "CTVMaterialFactory.h" 
#include "CTVMathLibrary.h" 
#include "CTVMesh.h" 
#include "CTVMiniMesh.h" 
#include "CTVNode.h" 
#include "CTVOctree.h" 
#include "CTVParticleSystem.h" 
#include "CTVPath.h" 
#include "CTVPhysics.h" 
#include "CTVRenderSurface.h" 
#include "CTVScene.h" 
#include "CTVScreen2DImmediate.h" 
#include "CTVScreen2DText.h" 
#include "CTVShader.h" 
#include "CTVTextureFactory.h" 
#include "CTVTileMap.h" 
#include "CTVViewport.h" 
#include "HelperFunctions.h" 
#include "tv_types.h" 

Loading TV3D into your form

Below is a sample of how to create the basic elements of your appilcation to use TV3D. This sample is usually sufficient as is, but you are more than welcome to change it to your needs.

Sample (Tutorial 01.h):

int LoadTV3D(); 
void GameLoop(); 
 
CTVEngine *pEngine; 
CTVScene *pScene; 
CTVInputEngine *pInput; 
bool bDoLoop; 
HWND frmHWND;

Inside the function BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) you will have to add under the line

   if (!hWnd) 
   { 
      return FALSE; 
   }

this:

   frmHWND = hWnd;

This is essential if you want your engine to correctly load up.

Sample (Tutorial 01.cpp):

int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) 
{ 
  // TODO: Place code here. 
  MSG msg; 
  HACCEL hAccelTable; 
 
  // Initialize global strings 
  LoadString( hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING ); 
  LoadString( hInstance, IDC_TUTORIAL01, szWindowClass, MAX_LOADSTRING ); 
  MyRegisterClass( hInstance ); 
 
  // Perform application initialization: 
  if( !InitInstance( hInstance, nCmdShow ) ) 
  { 
    return FALSE; 
  } 
 
  hAccelTable = LoadAccelerators( hInstance, (LPCTSTR)IDC_TUTORIAL01 ); 
 
  LoadTV3D(); 
 
  // Main message loop: 
  while( bDoLoop ) 
  { 
    // Render Loop 
    if( GetFocus() == frmHWND ) 
    { 
      pEngine->Clear( false ); 
        // Render Everything 
        pScene->RenderAll( true ); 
      pEngine->RenderToScreen(); 
 
      // If the ESC key is pressed stop the application. 
      if( pInput->IsKeyPressed( cTV_KEY_ESCAPE ) ) 
      { 
        SendMessage( frmHWND, WM_DESTROY, 0, 0 ); 
 
      } 
    } 
    else 
    { 
      // So we dont process the messages to many times if we are not rendering. 
      Sleep( 100 ); 
    } 
 
    BOOL peek = PeekMessage( &msg, NULL, 0, 0, TRUE ); 
 
    if( !TranslateAccelerator( msg.hwnd, hAccelTable, &msg ) ) 
    { 
      TranslateMessage( &msg ); 
      DispatchMessage( &msg ); 
    } 
  } 
 
  return (int) msg.wParam; 
} 
 
 
int LoadTV3D() 
{ 
  // Create the pTV Interface first: 
  pEngine = new CTVEngine(); 
 
  // Set the debug file/options. 
  // Do this before the 3D init so it can log any errors found during init. 
  pEngine->SetDebugMode( true, true ); 
  pEngine->SetDebugFile( "C:\\debugfile.txt" ); 
 
  // Set your beta-key/license: 
  // pTV->SetLicenseKey(TV_LICENSE_COMMERCIAL, "username", "key"); 
  pEngine->SetBetaKey( "UserName", "BETA-CODE-GOES-IN-HERE" ); 
 
  // After setting the beta-key/license its time to init the engine: 
  pEngine->Init3DWindowed( frmHWND, true ); 
 
  // Something good to do is to enable the auto-resize feature: 
  // Get the default viewport and set autoresize to true for it: 
  pEngine->GetViewport()->SetAutoResize( true ); 
 
  // Lets display the FPS: 
  pEngine->DisplayFPS( true ); 
 
  // Set the prefered angle system: 
  pEngine->SetAngleSystem( cTV_ANGLE_DEGREE ); 
 
  // Now after we are done initializing the TVEngine component lets continue: 
  // Create any other components after pTV init-> 
  pScene = new CTVScene(); 
  
  // Input has an additional init method to call-> 
  pInput = new CTVInputEngine(); 
  // Lets init both keyboard and mouse: 
  pInput->Initialize( true, true ); 
  
  // Setup the boolean for the loop. 
  bDoLoop = true; 
 
  return 0; 
}


Cleaning up.

Last but not least, we must make sure we clean up after ourselves to stop any form of memory leaks occuring. In doing so, you are successfully unloading everything that you have loaded. Every good programmer cleans up their objects.

Sample (Tutorial 01.cpp :: WndProc()):

  case WM_DESTROY: 
 
    // Stop the loop. 
    bDoLoop = false; 
 
    // Clean up the scene 
    if( pScene ) 
    { 
      pScene->DestroyAllMeshes(); 
      delete( pScene ); 
      pScene = NULL; 
    } 
 
    // Destroy the engine last 
    if( pEngine ) 
    { 
      delete( pEngine ); 
      pEngine = NULL; 
    } 
 
    // Continue normal application quit 
    PostQuitMessage(0); 
    break;
 
tv3dbeta/getting_started_with_c_using_vs.net.txt · Last modified: 2013/11/22 13:31