/******************************************************************* * WinMain *******************************************************************/ int APIENTRY _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow ) { //set up the application window if ( !initWindow(hWnd, hInstance, 800 , 600)) return -1; //initialize raw input if ( !InitializeRawInput() ) return -1; //create renderer if (!renderer.Initialize(&hWnd) ) return -1; //initialize test scene if (!renderer.InitializeScene() ) return -1; renderer.SetShadowMapBias( smBias); //camera setup float eye[3] = {0, 10, -10}, fp[3] = {9,9,0}, u[3] = {0,1,0}; camera.PositionCamera(eye, fp, u); camera.SetPerspectiveProjectionLH( 0.785f, 4.0f/3, 1.0f, 1000.0f); camera.SetMovementSpeed( 10.0f ); camera.Update(); //show first frame and welcome message renderer.RenderFrame(); MessageBox( hWnd, L"T = Toggle Shadow Map Filtering\nY = Toggle Shadow Map Resolution\nU = Toggle Shadow Map Generation Method\n +/- = Adjust shadow map bias", L"DirectX10 Tutorial 10 - Shadow Mapping", MB_ICONINFORMATION ); //frame timer HRTimer fTimer; fTimer.Reset(); //main message loop MSG msg = {0}; while (WM_QUIT != msg.message) { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) == TRUE) { TranslateMessage(&msg); DispatchMessage(&msg); } else { //limit FPS to 60FPS - hack to reduce GPU squealing while ( fTimer.GetElapsedTimeMilliseconds() < 16 ); renderer.RenderFrame(); camera.Update(); fTimer.Reset(); } } //cleanup return 0; }
// // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) // // PURPOSE: Processes messages for the main window. // // WM_COMMAND - process the application menu // WM_PAINT - Paint the main window // WM_DESTROY - post a quit message and return // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... timer.StartTimer(); if (parallel) DrawSetParallel(hWnd); else DrawSet(hWnd); UpdateStatusBarTime(hWnd, timer.StopTimer()); EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; case WM_RBUTTONDOWN: parallel = !parallel; SendMessage(GetDlgItem(hWnd, IDC_STATUS), SB_SETTEXT, 2, (LPARAM)(parallel ? _T(" Right-click for serial execution") : _T(" Right-click for parallel execution"))); InvalidateRect(hWnd, NULL, TRUE); UpdateWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
/** * @note Test file for checking random numbers produced by Mersenne Twister * @author Onur Bostanci * @data Dec. 2011 * @par how to use * -# get singleton object by using getInstance * -# change seed by changeSeed if you want * -# get random number by calling getFloat or getDouble functions * -# call release finally only at once * ******************************************************************************/ int RandomTest() { HRTimer *hrTimer = new HRTimer(); hrTimer->startTimer(); // get random number generator singleton Random* pRandomNumberGenerator = Random::getInstance(); if (NULL == pRandomNumberGenerator) { return -1; } pRandomNumberGenerator->changeSeed(rand()+time(NULL)); // get double type random number // std::cout.precision(30); for(int i=0;i<10000000;i++){ double dValue = pRandomNumberGenerator->getDouble(); //std::cout<<dValue<<std::endl; } hrTimer->stopTimer(); std::cout<<std::endl<<"Time elapsed: "<<hrTimer->getElapsedTime()<<" seconds."<<std::endl; /*FILE* fpLog = fopen("log.txt", "w"); if (NULL != fpLog) { // check for random number we got fprintf(fpLog, "%f\n", dValue); fclose (fpLog); fpLog = NULL; }*/ if (NULL != pRandomNumberGenerator) { // destroy singleton object pRandomNumberGenerator->release(); pRandomNumberGenerator = NULL; } std::cin.get(); return 0; }
/******************************************************************* * WinMain *******************************************************************/ int APIENTRY _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow ) { RedirectIOToConsole(); // Set up the application window if (!InitWindow( hInstance, nCmdShow, hWnd)) return 0; //set up direct x manager if (!dx.initialize(&hWnd , &hInstance)) return 0; // showing cursor: //ShowCursor(TRUE); //hTimer.StartTimer(); // Main message loop hTimer.Reset(); MSG msg = {0}; while (WM_QUIT != msg.message) { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) == TRUE) { TranslateMessage(&msg); DispatchMessage(&msg); } else { //hTimer. hTimer.UpdateTime(); dx.renderScene(&hTimer); } } return (int) msg.wParam; }
int main() { #ifdef _DEBUG _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); _CrtDumpMemoryLeaks(); #endif srand((unsigned int)time(NULL)); _wmkdir(L"TempFiles"); //ContructExample(); printf("Timer is started!\n"); timer.Reset(); if (!FirstStep()) { printf("First step: error occured!\n"); _getch(); return 0; } if (!SecondStep()) { printf("Second step: error occured!\n"); _getch(); return 0; } #ifdef DEBUG_INFO FILE *pFile = nullptr; fopen_s(&pFile, "task2result.txt", "rb"); if (!pFile) { printf("task2result file hasn't readed: error occured!\n"); _getch(); return 0; } int *pTempArray = new int[MAX_ELEMS_IN_MEM]; while (!feof(pFile)) { int nNumReadedNumbs = 0; if (!(nNumReadedNumbs = fread_s(pTempArray, MAX_ELEMS_IN_MEM * 4, 4, MAX_ELEMS_IN_MEM, pFile))) break; for (int i = 0; i < nNumReadedNumbs; i++) { printf("%d ", pTempArray[i]); } } printf("\n\n"); delete[] pTempArray; fclose(pFile); #endif //printf("Test: %d\n", i); printf("The task has done!\n"); printf("Time: %0.5f\n", timer.GetElapsed()); //_getch(); return 0; }