chap4_2 手动档

/*------------------------------------------------------------
	main.cpp -- achieve manual
			(c) Seamanj.2013/7/21
------------------------------------------------------------*/

#include "Ogre.h"
#include <iostream>

#if defined(WIN32)
#include <windows.h>
#endif

using namespace Ogre;

#if defined(WIN32)
INT WINAPI WinMain (
					HINSTANCE hInstance,
					HINSTANCE hPrevInstance,
					LPSTR lpCmdLine,
					int nCmdShow
					)
#else
int main(int argc, char *argv[]) 
#endif
{

	// tell Root not to load from any plugins or settings file
	Root *root = new Root("", "");

	// Load feature plugins. Scene managers will register 
	// themselves for all scene types they support
	root->loadPlugin("Plugin_CgProgramManager_D");
	root->loadPlugin("Plugin_OctreeSceneManager_D");

	// load rendersystem plugin(s). The order is important in that GL
	// should be available on on platforms, while D3D9 would be available 
	// only on Windows -- the try/catch will intercept the exception in this
	// case where D3D9 is not available and continue gracefully.
	try {
		root->loadPlugin("RenderSystem_GL_D");
		root->loadPlugin("RenderSystem_Direct3D9_D");
	}
	catch (...) {}

	try {
		// We'll simulate the selection of a rendersystem on an arbirtary basis; normally
		// you would have your own code to present the user with options and select the
		// rendersystem on that basis. Since a GUI is beyond the scope of this example, we'll
		// just assume the user selected OpenGL.
		const RenderSystemList *rList = &(root->getAvailableRenderers());
		RenderSystemList::const_iterator it = rList->begin();
		RenderSystem *rSys = 0;

		while (it != rList->end()) {

			rSys = *(it++);
			if (rSys->getName().find("OpenGL")) {

				root->setRenderSystem(rSys);
				break;
			}
		}

		// check to see if a render system was selected; if we reached the end of the list
		// without selecting a render system then none was found.
		if (rSys == 0) {
			delete root;
			std::cerr << "No RenderSystem available, exiting..." << std::endl;
			return -1;
		}

		// We can initialize Root here if we want. "false" tells Root NOT to create
		// a render window for us
		root->initialise(false);

		// set up the render window with all default params
		RenderWindow *window = rSys->_createRenderWindow(
			"Manual Ogre Window",	// window title
			800,					// window width, in pixels
			600,					// window height, in pixels
			false,					// fullscreen or not 
			0);						// use defaults for all other values

		// from here you can set up your camera and viewports as normal
		// get a pointer to the default base scene manager -- sufficient for our purposes
		SceneManager *sceneMgr = root->createSceneManager(ST_GENERIC);

		// create a single camera, and a viewport that takes up the whole window (default behavior)
		Camera *camera = sceneMgr->createCamera("MainCam");
		Viewport *vp = window->addViewport(camera);
		vp->setDimensions(0.0f, 0.0f, 1.0f, 1.0f);
		camera->setAspectRatio((float)vp->getActualWidth() / (float) vp->getActualHeight());
		camera->setFarClipDistance(1000.0f);
		camera->setNearClipDistance(5.0f);

		// Run the manual render loop. Since we are not using a frame listener in this case, we
		// will count to 15 seconds and then instead of exiting, we'll change the render window settings 
		// and re-initialize it.
		bool renderLoop = true;
		Timer *timer = &Timer();
		timer->reset();
		float s = 0.0f;

		while (renderLoop /*&& window->isActive()*/) {

			renderLoop = root->renderOneFrame();
			
			// accumulate total elapsed time
			s = (float)timer->getMilliseconds() / 1000.0f;

			// if greater than 5 seconds, break out of the loop
			if (s >= 5.0f)
				renderLoop = false;

			// we must call the windowing system's message pump each frame to 
			// allow Ogre to process messages,or there will not be any reflection 
			//when users click the close button
			WindowEventUtilities::messagePump();
			//当窗口被关闭时,我们需要返回false退出循环,否则会出现窗口不在但是进程还在的情况
			if(window->isClosed())
				return false;
		}
	}
	catch (Exception &e) {
		std::cerr << e.getFullDescription() << std::endl;
	}

	delete root;
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值