void COculusVR::EndDrawRender()
{
	// Clear screen
	wzUseRenderTarget(NULL);
	wzSetClearColor(0.0f,0.0f,0.0f,1.0f);
	wzSetViewport(0,0,0,0);	//Full
}
/*
 * アプリ初期化関数
 * ※returnに「0」以外を返すとエラー扱いになりプログラムが終了します。
 */
int Initialize()
{
	// Wizapplyライブラリを初期化
	wzInitCreateWizapply("Wizapply for Mac", APPSCREEN_WIDTH, APPSCREEN_HEIGHT, 0);

	/*------------------------------------------------------------------*/

	// 情報をセット
	wzSetClearColor(0.0f, 0.0f, 0.0f, 1.0f);                // クリア情報
	wzSetSpriteScSize(APPSCREEN_WIDTH, APPSCREEN_HEIGHT);	// スプライト設定
	wzSetCursorScSize(APPSCREEN_WIDTH, APPSCREEN_HEIGHT);	// 画面カーソル設定

	/*--------------------------------------

		****ゲームデータを初期化する****
	
	----------------------------------------*/
    sSceneManager->SetSceneFactory(new SceneFactory());
    sSceneManager->PushScene(SceneID_Title);
    sTextureManager->LoadTexture(0, "textures32.png");
    
	/*------------------------------------------------------------------*/

	// 関数をセット
	wzSetUpdateThread(60, UpdateFunc);	// 更新 -> UpdateFunc

	return 0;
}
//Draw
void COculusVR::DrawScreen()
{
	//clear
	wzClear();

	// Adjust eye position and rotation from controls, maintaining y position from HMD.
	static float BodyYaw(3.141592f);
	static Vector3f HeadPos(0.0f, 0.0f, -5.0f);
    static ovrTrackingState HmdState;
	static ovrPosef eyeRenderPose[2];

    ovrVector3f hmdToEyeViewOffset[2] = { EyeRenderDesc[0].HmdToEyeViewOffset, EyeRenderDesc[1].HmdToEyeViewOffset };
    ovrHmd_GetEyePoses(Hmd, 0, hmdToEyeViewOffset, eyeRenderPose, &HmdState);

	/* debug
		wzSetSpriteScSize(1920, 1080);
		wzSetSpritePosition(0.0f, 0.0f, 0.0f);
		wzSetSpriteColor(1.0f, 1.0f, 1.0f, 1.0f);
		wzSetSpriteTexCoord(0.0f, 0.0f, 1.0f, 1.0f);
		wzSetSpriteSizeLeftUp((float)1920, (float)1080);
		wzSetSpriteTexture(&m_screenTex);
		wzSpriteDraw();	//Draw
	*/

	// Setup shader
	wzUseShader(&LensShader);
	wzSetTexture("texture0", &m_screenTex, 0);

	for ( int eyeNum = 0; eyeNum < 2; eyeNum++ )
	{
		wzVector2 uvScale = {UVScaleOffset[eyeNum][0].x,-UVScaleOffset[eyeNum][0].y};
		wzVector2 uvOffset = {UVScaleOffset[eyeNum][1].x,UVScaleOffset[eyeNum][1].y};
		wzMatrix rotStart,rotEnd;
		wzUniformVector2("eyeToSourceUVscale", &uvScale);
		wzUniformVector2("eyeToSourceUVoffset", &uvOffset);

 		ovrMatrix4f timeWarpMatrices[2];
		ovrHmd_GetEyeTimewarpMatrices(Hmd, (ovrEyeType)eyeNum, eyeRenderPose[eyeNum], timeWarpMatrices);
		memcpy(&rotStart.m,&timeWarpMatrices[0],sizeof(ovrMatrix4f));
		memcpy(&rotEnd.m,&timeWarpMatrices[1],sizeof(ovrMatrix4f));
		wzUniformMatrix("eyeRotationStart", &rotStart);	//Nb transposed when set
		wzUniformMatrix("eyeRotationEnd", &rotEnd);
		
		//Draw Mesh
		wzDrawMesh(&MeshBuffer[eyeNum]);
	}

	//DK2 Latency Tester
	unsigned char latencyColor[3];
	ovrBool drawDk2LatencyQuad = ovrHmd_GetLatencyTest2DrawColor(Hmd, latencyColor);
	if(drawDk2LatencyQuad)
    {
		const int latencyQuadSize = 20; // only needs to be 1-pixel, but larger helps visual debugging
		wzSetViewport(Hmd->Resolution.w - latencyQuadSize, 0, latencyQuadSize, latencyQuadSize);
		wzSetClearColor(latencyColor[0] / 255.0f, latencyColor[1] / 255.0f, latencyColor[2] / 255.0f,0.0f);
		wzClear();
	}
}
//Pre-Renderer
void COculusVR::BeginDrawRender()
{
	ovrHmd_BeginFrameTiming(Hmd, 0); 

	//Chenge the render target
	wzUseRenderTarget(&m_screenRender);
	wzSetClearColor(0.0f,0.0f,0.0f,0.0f);
	wzClearBufferRenderTarget(&m_screenRender);
}