Application setup

Every application that uses HNP must instantiate an HPS::World object before any HPS API calls are made. Additionally, this World object must stay in scope for the application’s lifetime. In CHPSApp.cpp, you can see that the World object is initialized with the license key. This is an essential step which must not be missed - the application will not work without it!

	// Initialize HPS::World
	_world = new HPS::World(HOOPS_LICENSE);
	_world->SetMaterialLibraryDirectory("../../samples/data/materials");
	this->setFontDirectory("../../samples/fonts");

Additionally, notice the material library and font directory locations are set above. These settings are not required, but they do set up the default locations where HNP will look for materials and fonts.

See more about application setup here.

Next, you need to connect your application to HNP so that HNP can render into it. This is typically accomplished by passing a window handle to an HPS::ApplicationWindowKey object, as shown in CHPSView.cpp:

		// Setup to use the DX11 driver
		HPS::ApplicationWindowOptionsKit		windowOpts;
		windowOpts.SetDriver(HPS::Window::Driver::Default3D);

		// Create our Sprockets Canvas with the specified driver
		_canvas = HPS::Factory::CreateCanvas(reinterpret_cast<HPS::WindowHandle>(m_hWnd), "mfc_sandbox_canvas", windowOpts);

Notice that we are creating the window and immediately assigning it to an HPS::Canvas object. This happens during the initial update made by MFC. From now on, any rendering calls made by HNP will be sent to this canvas, which in turn passes it into the lower-level graphics hardware. The HPS::Canvas object is part of the view hierarchy, explained in the next section.