WPARAM MainLoop() { MSG msg; while(1) // Do our infinite loop { // Check if there was a message if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if(msg.message == WM_QUIT) // If the message wasn't to quit break; TranslateMessage(&msg); // Find out what the message does DispatchMessage(&msg); // Execute the message } else // if there wasn't a message { if(AnimateNextFrame(60)) // Make sure we only animate 60 FPS { g_Camera.Update(); // Update the camera information RenderScene(); // Render the scene every frame } else { Sleep(1); // Let other processes work } } } DeInit(); // Clean up and free all allocated memory return(msg.wParam); // Return from the program }
WPARAM MainLoop() { MSG msg; while(1) // Do our infinite loop { // Check if there was a message if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if(msg.message == WM_QUIT) // If the message wasn't to quit break; TranslateMessage(&msg); // Find out what the message does DispatchMessage(&msg); // Execute the message } else // If there wasn't a message { if(AnimateNextFrame(60)) // Make sure we only render 60 frames per second { RenderScene(); // Render the scene } } } DeInit(); // Clean up and free all allocated memory return(msg.wParam); // Return from the program }
WPARAM MainLoop() { MSG msg; while(1) // Do our infinite loop { // Check if there was a message if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if(msg.message == WM_QUIT) // If the message wasn't to quit break; TranslateMessage(&msg); // Find out what the message does DispatchMessage(&msg); // Execute the message } else // if there wasn't a message { if(AnimateNextFrame(60)) // Make sure we only animate 60 FPS { g_Camera.Update(); // Update the camera info RenderScene(); // Render the scene every frame } else { Sleep(1); // Let other processes work } } } /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * // Go through all the objects in the scene and free them for(int i = 0; i < g_World.numOfObjects; i++) { // Free the faces, normals, vertices, and texture coordinates. delete [] g_World.pObject[i].pFaces; delete [] g_World.pObject[i].pNormals; delete [] g_World.pObject[i].pVerts; delete [] g_World.pObject[i].pTexVerts; delete [] g_World.pObject[i].pIndices; } // When using display lists, we need to free them when we are finished using // the ID's. This OpenGL function does just that. We pass in the base ID and // the total ID's we used. glDeleteLists(g_Octree.GetDisplayListID(), g_EndNodeCount); /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * DeInit(); // Clean up and free all allocated memory return(msg.wParam); // Return from the program }
WPARAM MainLoop() { MSG msg; while(1) // Do our infinate loop { // Check if there was a message if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if(msg.message == WM_QUIT) // If the message wasnt to quit break; TranslateMessage(&msg); // Find out what the message does DispatchMessage(&msg); // Execute the message } else // if there wasn't a message { if(AnimateNextFrame(60)) // Make sure we only animate 60 FPS { RenderScene(); // Render the scene every frame } else { Sleep(1); // Let other processes work } } } //////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** //////////////////// // When we are done, we need to free all the model data // We do this by walking through all the objects and freeing their information // Go through all the objects in the scene for(int i = 0; i < g_3DModel.numOfObjects; i++) { // Free the faces, normals, vertices, and texture coordinates. delete [] g_3DModel.pObject[i].pFaces; delete [] g_3DModel.pObject[i].pNormals; delete [] g_3DModel.pObject[i].pVerts; delete [] g_3DModel.pObject[i].pTexVerts; } //////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** //////////////////// DeInit(); // Clean up and free all allocated memory return(msg.wParam); // Return from the program }
WPARAM MainLoop() { MSG msg; while(1) // Do our infinite loop { // Check if there was a message if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if(msg.message == WM_QUIT) // If the message wasn't to quit break; TranslateMessage(&msg); // Find out what the message does DispatchMessage(&msg); // Execute the message } else // if there wasn't a message { /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * // We added a way to clamp our frame rate so the water moves smoothly if(AnimateNextFrame(60)) // Make sure we only render 60 frames per second { g_Camera.Update(); // Update the camera data RenderScene(); // Render the scene every frame } /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// * } } DeInit(); // Clean up and free all allocated memory return(msg.wParam); // Return from the program }
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) // Anyway, so here is our "main()" for windows. Must Have this for a windows app. { // Create the handle to the window. HWND hwnd; // Create the variable to hold the window messages MSG msg; // Create the structure that holds the attributes of the window. // I just crammed them in like this to save space because we know what they do. WNDCLASSEX wndclass = {sizeof (wndclass), CS_HREDRAW | CS_VREDRAW, WndProc, 0, 0, hInstance, LoadIcon (NULL, IDI_WINLOGO), LoadCursor (NULL, IDC_ARROW), (HBRUSH) GetStockObject (WHITE_BRUSH), NULL, "Window Class", LoadIcon (NULL, IDI_WINLOGO)}; // Register the window class with the operating system RegisterClassEx (&wndclass); // Now, we actually create the window hwnd = CreateWindow ("Window Class", // window class name "Animation", // window's Title WS_OVERLAPPEDWINDOW, // window style CW_USEDEFAULT, // initial x position CW_USEDEFAULT, // initial y position WIDTH, // Here we pass in our desired width (800) HEIGHT, // Here we pass in our desired height (600) NULL, // This is the parent window handle. NULL, // This is the window menu handle hInstance, // This is the programs instance handle. NULL); // We don't want to pass any extra data in, so NULL // This shows our window. ShowWindow (hwnd, iCmdShow); // This pretty much paints our window to the screen. UpdateWindow (hwnd); // Here is our main loop. while (1) { // *We use PeekMessage() instead of GetMessage() to see if there is a message // from windows, if not, then we want to animate when nothing is going on.* // Check if there is a window message and remove it from the queue if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { // If the message was to quit, break out of the while loop if(msg.message == WM_QUIT) break; // This Translates messages so windows understands them. TranslateMessage (&msg); // This sends the messages to the WndProc(). DispatchMessage (&msg); } else { // *Now we do the computationally expensive stuff in this else* // Check if we want to animate the next frame of animation if(AnimateNextFrame(FRAME_RATE)) { // Animate the first water sprite AnimateSprite(&gBuffer, &gSprite); // Animate the second water sprite AnimateSprite(&gBuffer, &gSprite2); // Now swap the backbuffer to display it to the front and clear the screen SwapBackBuffer(&gBuffer, TRUE); } } } // Unregister the window class with the operating system UnregisterClass("Window Class",hInstance); // Quit the program return msg.wParam ; }