Beispiel #1
0
/**
 * WinMain function to get the thing started.
 */
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance,
	LPSTR lpCmdLine, int nCmdShow) {
	WNDCLASSEX	wndclass;
	HRESULT     hr;
	HWND		   hWnd;
	MSG			msg;

	// Set up window attributes
	wndclass.cbSize = sizeof(wndclass);
	wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS;
	wndclass.lpfnWndProc = MsgProc;
	wndclass.cbClsExtra = 0;
	wndclass.cbWndExtra = 0;
	wndclass.hInstance = hInst;
	wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
	wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW);
	wndclass.lpszMenuName = NULL;
	wndclass.lpszClassName = g_szAppClass;
	wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

	if (RegisterClassEx(&wndclass) == 0)
		return 0;

	// create window
	if (!(hWnd = CreateWindowEx(NULL, g_szAppClass,
		"ZFXEngine - Demo Application",
		WS_OVERLAPPEDWINDOW | WS_VISIBLE,
		GetSystemMetrics(SM_CXSCREEN) / 2 - 400,
		GetSystemMetrics(SM_CYSCREEN) / 2 - 300,
		800, 600, NULL, NULL, hInst, NULL)))
		return 0;

	ShowWindow(hWnd, SW_HIDE);

	g_hWnd = hWnd;
	g_hInst = hInst;


	int SwitchAPI = 1;
	std::string chAPI;
	switch (SwitchAPI)
	{
	case 0:
		chAPI.assign("Direct3D");
		break;
	case 1:
		chAPI.assign("OpenGL");
		break;
	default:
		chAPI.assign("Direct3D");
		break;
	}

	

	// try to start the engine
	if (FAILED(hr = ProgramStartup(chAPI.c_str())))
	{
		GetLogger().Print(LOG_DEBUG,log_file,"error: ProgramStartup() failed\n");
		g_bDone = true;
	}
	else if (hr == ZFX_CANCELED)
	{
		GetLogger().Print(LOG_DEBUG,log_file,"error: ProgramStartup() canceled by user \n");
		g_bDone = true;
	}
	else
	{
		GetLogger().Print(LOG_DEBUG,log_file,"ProgramStartup Success");
		g_pDevice->SetClearColor(1, 1, 1);

		ShowWindow(hWnd, SW_SHOW);

		LoadModel();

	}

	//DrawVertex();

	InitTriangleExam();
	InitFont();
	//InitLightExam();

	InitGlyphTex();

	GetTimer()->Reset();

	while (!g_bDone)
	{
		while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}

		if (g_bIsActive)
		{
			UpdateFPS();


			//DrawGlyphTex();

			//DrawLightExam();


			//ProgramTick();
			
			IShaderManager* sm = g_pDevice->GetShaderManager();
			sm->EnableShader(false);
			//DrawTriangle(sm);
			
			//DrawS3DModel();

			
			DrawString("Life is cool");

			/*if (g_pDevice->IsWindowed())
			{
				g_pDevice->UseWindow(1);
				g_pDevice->SetView3D(vU*-1.0f, vR, vD, vP);
				ProgramTick();

				g_pDevice->UseWindow(2);
				g_pDevice->SetView3D(vR*-1.0f, vU*-1, vD, vP);
				ProgramTick();

				g_pDevice->UseWindow(3);
				g_pDevice->SetView3D(vU, vR*-1, vD, vP);
				ProgramTick();
			}*/
		}
	}

	// cleanup stuff
	ProgramCleanup();

	UnregisterClass(g_szAppClass, hInst);

	// return back to windows
	return (int)msg.wParam;
} // WinMain
Beispiel #2
0
/**
 * WinMain function to get the thing started.
 */
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, 
                   LPSTR lpCmdLine, int nCmdShow) {
   WNDCLASSEX	wndclass;
   HRESULT     hr;
   HWND		   hWnd;
   MSG			msg;
   
   // Set up window attributes
   wndclass.cbSize         = sizeof(wndclass);
   wndclass.style          = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS;
   wndclass.lpfnWndProc    = MsgProc;
   wndclass.cbClsExtra     = 0;
   wndclass.cbWndExtra     = 0;
   wndclass.hInstance      = hInst;
   wndclass.hIcon          = LoadIcon(NULL, IDI_APPLICATION);
   wndclass.hCursor        = LoadCursor(NULL, IDC_ARROW);
   wndclass.hbrBackground  = (HBRUSH)(COLOR_WINDOW);
   wndclass.lpszMenuName   = NULL;
   wndclass.lpszClassName  = g_szAppClass;
   wndclass.hIconSm        = LoadIcon(NULL, IDI_APPLICATION);
    
   if(RegisterClassEx(&wndclass) == 0)
      return 0;

   // create window
   if (!(hWnd = CreateWindowEx(NULL, g_szAppClass,
	   		                   "Crancking up ZFXEngine...",
				                   WS_OVERLAPPEDWINDOW | WS_VISIBLE,
			 	                   GetSystemMetrics(SM_CXSCREEN)/2 -190,
                               GetSystemMetrics(SM_CYSCREEN)/2 -140,
				                   380, 280, NULL, NULL, hInst, NULL)))
      return 0;
     
   g_hWnd  = hWnd;
   g_hInst = hInst;

   pLog = fopen("log_main.txt", "w");

   // try to start the engine
   if (FAILED( hr = ProgramStartup("Direct3D"))) {
      fprintf(pLog, "error: ProgramStartup() failed\n");
      g_bDone = true;
      }
   else if (hr == ZFX_CANCELED) {
      fprintf(pLog, "error: ProgramStartup() canceled by user \n");
      g_bDone = true;
      }
   else 
      g_pDevice->SetClearColor(0.1f, 0.3f, 0.1f);

   while (!g_bDone)
      {
      while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
	      {
		 	TranslateMessage(&msg);
			DispatchMessage(&msg);
         }

      if (g_bIsActive)
         {  
         if (g_pDevice->IsRunning()) {
            g_pDevice->BeginRendering(true,true,true);
            g_pDevice->EndRendering();
            }
         }
      }
   
   // cleanup stuff
   ProgramCleanup();

   UnregisterClass(g_szAppClass, hInst);
   
   // return back to windows
   return (int)msg.wParam;
   } // WinMain