outdated: 4.Rotation

修改部分位于双行星号内。

  1 #include <windows.h>
  2 #include <gl/glew.h>
  3 #include <gl/glut.h>
  4 #include <GL/GLAUX.H>
  5
  6 /*
  7  *  Every OpenGL program is linked to a Rendering Context.
  8  *  A Rendering Context is what links OpenGL calls to the Device Context.
  9  *  In order for your program to draw to a Window you need to create a Device Context.
 10  *  The DC connects the Window to the GDI (Graphics Device Interface).
 11  */
 12
 13 HGLRC     hRC = NULL;         // Permanent rendering context
 14 HDC       hDC = NULL;         // Private GDI device context
 15 HWND      hWnd = NULL;        // Holds our window handle
 16 HINSTANCE hInstance;          // Holds the instance of the application
 17
 18 /*
 19  *  It‘s important to make this global so that each procedure knows if
 20  *  the program is running in fullscreen mode or not.
 21  */
 22
 23 bool keys[256];         // Array used for the keyboard routine
 24 bool active = TRUE;     // Window active flag set to TRUE by default
 25 bool fullscreen = TRUE; // Fullscreen flag set to fullscreen mode by default
 26 /******************************************************************************************************************************************/
 27 /******************************************************************************************************************************************/
 28 GLfloat rtri;           // Angle for the triangle (new)
 29 GLfloat rquad;          // Angle for the quad (new)
 30 /******************************************************************************************************************************************/
 31 /******************************************************************************************************************************************/
 32
 33
 34 /*
 35  *  CreateGLWindow() has a reference to WndProc() but WndProc() comes after CreateGLWindow().
 36  */
 37
 38 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration for WndProc
 39
 40 /*
 41  *  The job of the next section of code is to resize the OpenGL scene
 42  *  whenever the window (assuming you are using a Window rather than fullscreen mode) has been resized.
 43  */
 44
 45 GLvoid ReSizeGLScene(GLsizei width, GLsizei height)   // Resize and initialize the GL window
 46 {
 47     if (height == 0) {                                // Prevent a divide by zero by
 48         height = 1;                                   // Making height equal one
 49     }
 50
 51     glViewport(0, 0, width, height);                  // Reset the current viewport
 52
 53     /*
 54      *  The following lines set the screen up for a perspective view.
 55      *  Meaning things in the distance get smaller. This creates a realistic looking scene.
 56      *  The perspective is calculated with a 45 degree viewing angle based on
 57      *  the windows width and height. The 0.1f, 100.0f is the starting point and
 58      *  ending point for how deep we can draw into the screen.
 59      *
 60      *  The projection matrix is responsible for adding perspective to our scene.
 61      *  glLoadIdentity() restores the selected matrix to it‘s original state.
 62      *  The modelview matrix is where our object information is stored.
 63      *   Lastly we reset the modelview matrix.
 64      */
 65
 66     glMatrixMode(GL_PROJECTION);                      // Select the projection matrix
 67     glLoadIdentity();                                 // Reset the projection matrix
 68
 69                                                       // Calculate the aspect ratio of the window
 70     gluPerspective(45.0f, (GLfloat)width / (GLfloat)height, 0.1f, 100.0f);
 71
 72     glMatrixMode(GL_MODELVIEW);                       // Seclet the modelview matrix
 73     glLoadIdentity();                                 // Reset the modelview matrix
 74 }
 75
 76 int InitGL(GLvoid)                                    // All setup for OpenGL goes here
 77 {
 78     /*
 79      *  Smooth shading blends colors nicely across a polygon, and smoothes out lighting.
 80      */
 81
 82     glShadeModel(GL_SMOOTH);                          // Enables smooth shading
 83
 84     glClearColor(0.0f, 0.0f, 0.0f, 0.0f);             // Black background
 85
 86     /*
 87      *  Think of the depth buffer as layers into the screen.
 88      *  The depth buffer keeps track of how deep objects are into the screen.
 89      */
 90
 91     glClearDepth(1.0f);                               // Depth buffer setup
 92     glEnable(GL_DEPTH_TEST);                          // Enable depth testing
 93     glDepthFunc(GL_LEQUAL);                           // The typr of depth test to do
 94
 95     /*
 96      *  Next we tell OpenGL we want the best perspective correction to be done.
 97      *  This causes a very tiny performance hit, but makes the perspective view look a bit better.
 98      */
 99
100     glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);   // Really nice perspective calculations
101
102     return TRUE;
103 }
104
105 /*
106  *  For now all we will do is clear the screen to the color we previously decided on,
107  *  clear the depth buffer and reset the scene. We wont draw anything yet.
108  */
109 /******************************************************************************************************************************************/
110 /******************************************************************************************************************************************/
111 int DrawGLScene(GLvoid)                                  // Here‘s where we do all the drawing
112 {
113     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  // Clear the screen and the depth buffer
114     glLoadIdentity();                                    // Reset the current modelview matrix
115
116     /*
117      *  When you do a glLoadIdentity() what you are doing is moving back to
118      *  the center of the screen with the X axis(轴) running left to right,
119      *  the Y axis moving up and down, and the Z axis moving into, and out of the screen.
120      */
121     /*
122      *  glTranslatef(x, y, z) moves along the X, Y and Z axis, in that order.
123      *  When you translate, you are not moving a set amount from the center of the screen,
124      *  you are moving a set amount from wherever you currently were on the screen.
125      */
126     glTranslatef(-1.5f, 0.0f, -6.0f);                    // Move left 1.5 units and into the screen 6.0
127
128     glRotatef(rtri, 0.9f, 0.6f, 0.9f);                   // Rotate the triangle on the Y axis (new)
129
130 //    glColor3f(0.5f, 0.5f, 1.0f);                         // Set the color to a nice blue shade
131     glBegin(GL_TRIANGLES);                               // Drawing using traingles
132         glColor3f(1.0, 0.0, 0.0);                        // Set the color to red
133         glVertex3f(0.0f, 1.0f, 0.0f);                    // Top
134         glColor3f(0.0, 1.0, 0.0);                        // Set the color to green
135         glVertex3f(-1.0f, -1.0f, 0.0f);                  // Bottom left
136         glColor3f(0.0, 0.0, 1.0);                        // Set the color to blue
137         glVertex3f(1.0f, -1.0f, 0.0f);                   // Bottom right
138     glEnd();                                             // Finished drawing the traingles
139
140     /*
141      *  By drawing in a clockwise order, the square will be drawn as a back face.
142      *  Meaning the side of the quad we see is actually the back.
143      *  Objects drawn in a counter clockwise order will be facing us.
144      */
145
146     glLoadIdentity();                                    // Reset (new)
147     glTranslatef(1.5f, 0.0f, -6.0f);                      // Move left 3 units
148     glRotatef(rquad, 0.5f, 0.5f, 0.5f);                  // Rotate the quad on the x axis (new)
149
150     glBegin(GL_QUADS);                                   // Draw a quad
151         glColor3f(0.75, 0.0, 0.0);
152         glVertex3f(-1.0f, 1.0f, 0.0f);                   // Top left
153         glColor3f(1.0, 0.5, 0.0);
154         glVertex3f(1.0f, 1.0f, 0.0f);                    // Top right
155         glColor3f(1.0, 1.0, 0.25);
156         glVertex3f(1.0f, -1.0f, 0.0f);                   // Bottom right
157         glColor3f(1.0, 0.0, 1.0);
158         glVertex3f(-1.0f, -1.0f, 0.0f);                  // Bottom left
159     glEnd();                                             // Done drawing the quad
160
161     rtri += 0.2f;                                        // Increase the rotation variable for the triangle (new)
162     rquad += 0.15f;                                      // Decrease the rotation variable for the quad (new)
163     return TRUE;                                         // everthing went OK
164 }
165 /******************************************************************************************************************************************/
166 /******************************************************************************************************************************************/
167 /*
168  *  The job of KillGLWindow() is to release the Rendering Context,
169  *  the Device Context and finally the Window Handle.
170  */
171
172 GLvoid KillGLWindow(GLvoid)                              // Properly kill the window
173 {
174     if (fullscreen) {                                    // Are we in fullscreen mode
175
176         /*
177          *  We use ChangeDisplaySettings(NULL,0) to return us to our original desktop.
178          *  After we‘ve switched back to the desktop we make the cursor visible again.
179          */
180
181         ChangeDisplaySettings(NULL, 0);                  // if so switch back to the desktop
182         ShowCursor(TRUE);                                // Show mouse pointer
183     }
184
185     if (hRC) {                                           // Do we have a rendering context
186         if (!wglMakeCurrent(NULL, NULL)) {                // Are we able to release the DC and RC contexts
187             MessageBox(NULL, "Release of DC and RC failed.", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
188         }
189
190         if (!wglDeleteContext(hRC)) {                     // Are we able to delete the RC
191             MessageBox(NULL, "Release rendering context failed.", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
192             hRC = NULL;                                  // Set RC to NULL
193         }
194
195         if (hDC && !ReleaseDC(hWnd, hDC)) {              // Are we able to release the DC
196             MessageBox(NULL, "Release device context failed.", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
197             hDC = NULL;                                  // Set DC to NULL
198         }
199         if (hWnd && !DestroyWindow(hWnd)) {              // Are we able to destroy the window
200             MessageBox(NULL, "Could not release hWnd.", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
201             hWnd = NULL;                                 // Set hWnd to NULL
202         }
203
204         if (!UnregisterClass("OpenGL", hInstance)) {     // Are we able to unregister class
205             MessageBox(NULL, "Could not register class.", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
206             hInstance = NULL;                            // Set hInstance to NULL
207         }
208     }
209 }
210
211 /*
212  * The next section of code creates our OpenGL Window.
213  */
214
215 BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag)
216 {
217     /*
218      * Find  a pixel format that matches the one we want
219      */
220     GLuint PixelFormat;                                  // Holds the result after serching for a match
221
222     /*
223      * Before you create a window, you MUST register a Class for the window
224      */
225     WNDCLASS wc;                                         // Windows class structure
226
227     /*
228      *  dwExStyle and dwStyle will store the Extended and normal Window Style Information.
229     */
230     DWORD dwExStyle;                                     // Window extend style
231     DWORD dwStyle;                                       // Window style
232
233     RECT WindowRect;                                     // Grabs rectangle upper left/lower right values
234     WindowRect.left = (long)0;                           // Set left value to 0
235     WindowRect.right = (long)width;                      // Set right value to requested width
236     WindowRect.top = (long)0;                            // Set top value to 0
237     WindowRect.bottom = (long)height;                    // Set bottom value to requested height
238
239     fullscreen = fullscreenflag;                         // Set the global fullscreen flag
240
241     /*
242      *  The style CS_HREDRAW and CS_VREDRAW force the Window to redraw whenever it is resized.
243      *  CS_OWNDC creates a private DC for the Window. Meaning the DC is not shared across applications.
244      *  WndProc is the procedure that watches for messages in our program.
245      *  No extra Window data is used so we zero the two fields. Then we set the instance.
246      *  Next we set hIcon to NULL meaning we don‘t want an ICON in the Window,
247      *  and for a mouse pointer we use the standard arrow. The background color doesn‘t matter
248      *  (we set that in GL). We don‘t want a menu in this Window so we set it to NULL,
249      *  and the class name can be any name you want. I‘ll use "OpenGL" for simplicity.
250      */
251     hInstance = GetModuleHandle(NULL);                   // Grab an instance for our window
252     wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;       // Redraw on move, and own DC for window
253     wc.lpfnWndProc = (WNDPROC)WndProc;                   // WndProc handles message
254     wc.cbClsExtra = 0;                                   // No extra window date
255     wc.cbWndExtra = 0;                                   // No extra window date
256     wc.hInstance = hInstance;                            // set the instance
257     wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);              // Load the default icon
258     wc.hCursor = LoadCursor(NULL, IDC_ARROW);            // Load the arrow pointer
259     wc.hbrBackground = NULL;                             // No background requried for GL
260     wc.lpszMenuName = NULL;                              // We don‘t want a menu
261     wc.lpszClassName = "OpenGL";                         // set the class name
262
263     if (!RegisterClass(&wc)) {                           // Attempt to register the window class
264         MessageBox(NULL, "Failed to register the window class.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
265         return FALSE;                                    // Exit and return false
266     }
267
268     if (fullscreen) {                                    // attempt fullsreen model
269
270         /*
271         T*  here are a few very important things you should keep in mind when switching to full screen mode.
272          *  Make sure the width and height that you use in fullscreen mode is the same as
273          *  the width and height you plan to use for your window, and most importantly,
274          *  set fullscreen mode BEFORE you create your window.
275          */
276         DEVMODE dmScreenSettings;                        // Device mode
277         memset(&dmScreenSettings, 0, sizeof(dmScreenSettings)); // Make sure memory‘s cleared
278         dmScreenSettings.dmSize = sizeof(dmScreenSettings);     // Size of devmode structure
279         dmScreenSettings.dmPelsWidth = width;            // Select window width
280         dmScreenSettings.dmPelsHeight = height;          // Select window height
281         dmScreenSettings.dmBitsPerPel = bits;            // Select bits per pixel
282         dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
283
284         /*
285          *  In the line below ChangeDisplaySettings tries to switch to a mode that matches
286          *  what we stored in dmScreenSettings. I use the parameter CDS_FULLSCREEN when switching modes,
287          *  because it‘s supposed to remove the start bar at the bottom of the screen,
288          *  plus it doesn‘t move or resize the windows on your desktop when you switch to
289          *  fullscreen mode and back.
290          */
291         //Try to set selected mode and get results. Note: CDS_FULLSCREEN gets rid of start bar
292         if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) {
293             //If the mode fails, offer two options. Quit or run in a window
294             if (MessageBox(NULL, "The requested fullscreen mode is not supported by\n your video card. Use"
295                 "windowed mode instead?", "GL", MB_YESNO | MB_ICONEXCLAMATION) == IDYES)
296             {
297                 fullscreen = FALSE;                       // Select windowed mode (fullscreen=FLASE)
298             }
299             else {
300                 // Pop up a message box letting user know the programe is closing.
301                 MessageBox(NULL, "Program will now close.", "ERROR", MB_OK | MB_ICONSTOP);
302                 return FALSE;                             // Exit and return FALSE
303             }
304         }
305     }
306
307     if (fullscreen) {                                     // Are we still in fullscreen mode
308
309         /*
310          *  If we are still in fullscreen mode we‘ll set the extended style to WS_EX_APPWINDOW,
311          *  which force a top level window down to the taskbar once our window is visible.
312          *  For the window style we‘ll create a WS_POPUP window.
313          *  This type of window has no border around it, making it perfect for fullscreen mode.
314
315          *  Finally, we disable the mouse pointer. If your program is not interactive,
316          *  it‘s usually nice to disable the mouse pointer when in fullscreen mode. It‘s up to you though.
317          */
318         dwExStyle = WS_EX_APPWINDOW;                      // Window extended style
319         dwStyle = WS_POPUP;                               // Window style
320         ShowCursor(FALSE);                                // Hide mosue pointer
321     }
322     else {
323
324         /*
325          *  If we‘re using a window instead of fullscreen mode,
326          *  we‘ll add WS_EX_WINDOWEDGE to the extended style. This gives the window a more 3D look.
327          *  For style we‘ll use WS_OVERLAPPEDWINDOW instead of WS_POPUP.
328          *  WS_OVERLAPPEDWINDOW creates a window with a title bar, sizing border,
329          *  window menu, and minimize / maximize buttons.
330          */
331         dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;   // Window extended style
332         dwStyle = WS_OVERLAPPEDWINDOW;                    // Window style
333     }
334
335     /*
336      *  By using the AdjustWindowRectEx command none of our OpenGL scene will be covered up by the borders,
337      *  instead, the window will be made larger to account for the pixels needed to draw the window border.
338      *  In fullscreen mode, this command has no effect.
339      */
340     AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);  // Adjust window to true resqusted
341
342     /*
343      *  WS_CLIPSIBLINGS and WS_CLIPCHILDREN are both REQUIRED for OpenGL to work properly.
344      *  These styles prevent other windows from drawing over or into our OpenGL Window.
345      */
346     if (!(hWnd = CreateWindowEx(dwExStyle,                // Extended style for the window
347         "OpenGL",                                         // Class name
348         title,                                            // Window title
349         WS_CLIPSIBLINGS |                                 // Requried window style
350         WS_CLIPCHILDREN |                                 // Requried window style
351         dwStyle,                                          // Select window style
352         0, 0,                                             // Window position
353         WindowRect.right - WindowRect.left,               // Calculate adjusted window width
354         WindowRect.bottom - WindowRect.top,               // Calculate adjusted window height
355         NULL,                                             // No parent window
356         NULL,                                             // No menu
357         hInstance,                                        // Instance
358         NULL)))                                           // Don‘t pass anything to WM_CREATE
359     {
360         KillGLWindow();                                   //Reset the display
361         MessageBox(NULL, "Window creation error.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
362         return FALSE;                                     // Retrurn FALSE;
363     }
364
365     /*
366      *  aside from the stencil buffer and the (slow) accumulation buffer
367      */
368     static PIXELFORMATDESCRIPTOR pfd =                    // pfd tells windows how we want things to be
369     {
370         sizeof(PIXELFORMATDESCRIPTOR),                    // Size of this pixel format descriptor
371         1,                                                // Version number
372         PFD_DRAW_TO_WINDOW |                              // Format must support window
373         PFD_SUPPORT_OPENGL |                              // Format must support OpenGL
374         PFD_DOUBLEBUFFER,                                 // Must support double buffer
375         PFD_TYPE_RGBA,                                    // Request an RGBA format
376         bits,                                             // Select our color depth
377         0, 0, 0, 0, 0, 0,                                 // Color bits ignored
378         0,                                                // No alpha buffer
379         0,                                                // shift bit ignored
380         0,                                                // No accumulation buffer
381         0, 0, 0, 0,                                       // Accumulation bits ignored
382         16,                                               // 16Bits Z_Buffer (depth buffer)
383         0,                                                // No stencil buffer
384         0,                                                // No auxiliary buffer
385         PFD_MAIN_PLANE,                                   // Main drawing layer
386         0,                                                // Reserved
387         0, 0, 0                                           // Layer makes ignored
388     };
389
390     if (!(hDC = GetDC(hWnd))) {                           // Did we get a device context
391         KillGLWindow();                                   // Reset the display
392         MessageBox(NULL, "Can‘t create a GL device context.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
393         return FALSE;                                     // Return FALSE
394     }
395
396     if (!(PixelFormat = ChoosePixelFormat(hDC, &pfd))) {  // Did window find a matching pixel format
397         KillGLWindow();                                   // Reset the display
398         MessageBox(NULL, "Can‘t find a suitable pixelformat.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
399         return FALSE;                                     // Return FALSE;
400     }
401
402     if (!SetPixelFormat(hDC, PixelFormat, &pfd)) {        // Are we able to set the pixel format
403         KillGLWindow();                                   // Reset the display
404         MessageBox(NULL, "Can‘t set the pixelformat.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
405         return FALSE;                                     // Return FALSE;
406     }
407
408     if (!(hRC = wglCreateContext(hDC))) {                 // Are we able to rendering context
409         KillGLWindow();                                   // Reset the display
410         MessageBox(NULL, "Can‘t create a GL rendering context.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
411         return FALSE;                                     // Return FASLE;
412     }
413
414     if (!wglMakeCurrent(hDC, hRC)) {                      // Try to activate the rendering context
415         KillGLWindow();                                   // Reset the display
416         MessageBox(NULL, "Can‘t activate the GL rendering context.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
417         return FALSE;                                     // Return FALSE
418     }
419
420     /*
421      *  ReSizeGLScene passing the screen width and height to set up our perspective OpenGL screen.
422      */
423     ShowWindow(hWnd, SW_SHOW);                            // Show the window
424     SetForegroundWindow(hWnd);                            // slightly higher priority
425     SetFocus(hWnd);                                       // Sets keyboard focus to the window
426     ReSizeGLScene(width, height);                         // Set up our perspective GL screen
427
428     /*
429      *  we can set up lighting, textures, and anything else that needs to be setup in InitGL().
430      */
431     if (!InitGL()) {                                      // Initialize our newly created GL window
432         KillGLWindow();                                   // Reset the display
433         MessageBox(NULL, "Initialize Failed.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
434         return FALSE;                                     // Return FALSE
435     }
436     return TRUE;
437 }
438
439 LRESULT CALLBACK WndProc(HWND hWnd,                       // Handle for this window
440     UINT uMsg,                                            // Message for this window
441     WPARAM wParam,                                        // Additional message information
442     LPARAM lParam)                                        // Additional message information
443 {
444     switch (uMsg) {                                       // Check for window message
445         case WM_ACTIVATE: {                               // Check minimization state
446             if (!HIWORD(wParam)) {
447                 active = TRUE;                            // Program is active
448             }
449             else {
450                 active = FALSE;                           // Program is no longer active
451             }
452             return 0;                                     // Return to the message loop
453         }
454         case WM_SYSCOMMAND: {                             // Intercept system commands
455             switch (wParam) {                             // Check system calls
456                 case SC_SCREENSAVE:                       // Screensaver trying to start
457                 case SC_MONITORPOWER:                     // Monitor trying to enter powersave
458                 return 0;                                 // Prevent form happening
459             }
460             break;                                        // Exit
461         }
462         case WM_CLOSE: {                                  // Did we receive a close message
463             PostQuitMessage(0);                           // Send a quit message
464             return 0;
465         }
466         case WM_KEYDOWN: {                                // Is a key being held down
467             keys[wParam] = TRUE;                          // if so, mark it as TRUE
468             return 0;                                     // Jump back
469         }
470         case WM_KEYUP: {                                  // Has a key been released
471             keys[wParam] = FALSE;                         // if so, mark it as FALSE
472             return 0;                                     // Jump back
473         }
474         case WM_SIZE: {                                   // Resize the OpenGL window
475             ReSizeGLScene(LOWORD(lParam), HIWORD(lParam));   // LoWord = width HiWord = height
476             return 0;                                     // Jump back
477         }
478     }
479     return DefWindowProc(hWnd, uMsg, wParam, lParam);     // Pass all unhandled message to DefWindwProc
480 }
481
482 int WINAPI WinMain(HINSTANCE hInstance,                   // Instance
483     HINSTANCE hPrevInstance,                              // Previous instance
484     LPSTR lpCmdLine,                                      // Command line parameters
485     int nCmdShow)                                         // Window show state
486 {
487     MSG msg;                                              // Window message structure
488     BOOL done = FALSE;                                    // Bool variable to exit loop
489                                                           // Ask the user which screen mode they prefer
490     if (MessageBox(NULL, "Would you like to run in fullscreen mode?",
491         "Start fullscreen?", MB_YESNO | MB_ICONQUESTION) == IDNO)
492     {
493         fullscreen = FALSE;                               // Window mode
494     }
495                                                           // Create our OpenGL window
496     if (!CreateGLWindow("Rotation", 640, 480, 16, fullscreen)) {  // (Modified)
497         return 0;                                         // Quit if window was not create
498     }
499
500     while (!done) {                                       // Loop that runs until donw = TRUE
501         if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {   // Is there a message wating
502             if (msg.message == WM_QUIT) {                 // Havw we received a quit message
503                 done = TRUE;                              // if so done  = TRUE
504             }
505             else {                                        // If not, deal with window message
506                 TranslateMessage(&msg);                   // Translate message
507                 DispatchMessage(&msg);                    // Dispatch message
508             }
509         }
510         else {
511             // Draw the scene. Watch for ESC key and quit message from DrawGLScene()
512             if (active) {                                 // Program active
513                 if (keys[VK_ESCAPE]) {                    // Was ESC pressed
514                     done = TRUE;                          // ESC signalled a quit
515                 }
516                 else {                                    // Not time to quit, update screen
517                     DrawGLScene();                        // Draw scene
518                     SwapBuffers(hDC);                     // Swap buffers (double buffering)
519                 }
520             }
521
522             /*
523              *  It allows us to press the F1 key to switch from fullscreen mode to
524              *  windowed mode or windowed mode to fullscreen mode.
525              */
526             if (keys[VK_F1]) {                            // Is F1 being pressed
527                 keys[VK_F1] = FALSE;                      // If so make key FASLE
528                 KillGLWindow();                           // Kill our current window
529                 fullscreen = !fullscreen;                 // Toggle fullscreen / window mode
530                 //Recreate our OpenGL window(modified)
531                 if (!CreateGLWindow("Rotation", 640, 480, 16, fullscreen)) {
532                     return 0;                             // Quit if window was not create
533                 }
534             }
535         }
536     }
537     // Shutdown
538     KillGLWindow();                                       // Kill the window
539     return (msg.wParam);                                  // Exit the program
540 }

图是动态旋转的。

时间: 2024-10-16 12:16:47

outdated: 4.Rotation的相关文章

outdated: 48.ArcBall Rotation

认认真真地把这教程过一遍还真是费事啊... 终于到最后一章了,鼠标拖动可实现物体旋转. 下面为代码, #ifndef _ArcBall_h #define _ArcBall_h // Only support assertions in debug builds #ifdef _DEBUG #include <assert.h> #else #define assert(x) { } #endif // _DEBUG #include <GL\glut.h> #include &l

(IDA*)POJ 2286 The Rotation Game

The rotation game uses a # shaped board, which can hold 24 pieces of square blocks (see Fig.1). The blocks are marked with symbols 1, 2 and 3, with exactly 8 pieces of each kind. Initially, the blocks are placed on the board randomly. Your task is to

HDU 4708 Rotation Lock Puzzle (贪心+模拟)

Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1668    Accepted Submission(s): 530 Problem Description Alice was felling into a cave. She found a strange door with a number

hduoj 4708 Rotation Lock Puzzle 2013 ACM/ICPC Asia Regional Online —— Warmup

http://acm.hdu.edu.cn/showproblem.php?pid=4708 Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description Alice was felling into a cave. She found a strange door with a number square m

【HackerRank】Game Of Rotation

题目连接:Game Of Rotation Mark is an undergraduate student and he is interested in rotation. A conveyor belt competition is going on in the town which Mark wants to win. In the competition, there's A conveyor belt which can be represented as a strip of 1

Centos 7周期性任务、日志rotation、过滤和core压缩的实现

Centos 7周期性任务日志rotation.过滤和core压缩的实现 1.centos7中cron脚本及其调用脚本的实现示例 [[email protected] cron.d]# pwd /etc/cron.d [[email protected] cron.d]# cat syslog # Run mysys activity accounting tool every 10 minutes */5 * * * * root /usr/sbin/mysyslog.sh 2>&1 &g

POJ2286 The Rotation Game

The Rotation Game Time Limit: 15000MS   Memory Limit: 150000KB   64bit IO Format: %I64d & %I64u Description The rotation game uses a # shaped board, which can hold 24 pieces of square blocks (see Fig.1). The blocks are marked with symbols 1, 2 and 3,

outdated: 32.Picking, Alpha Blending, Alpha Testing, Sorting

一个射击类的小demo.分为三个文件,Previous.h.Previous.cpp和Main.cpp. 在Previous.cpp的CreateWindowGL中新增了AdjustWindowRectEx()函数,可以根据客户端的期望大小计算窗口大小,矩形通过函数创建一个理想大小的窗口. ChoosePixelFormat()函数试图匹配一个最接近的像素格式通过上下文给的像素格式规格. 在Mian.cpp文件的Selection()函数中,glGetIntegerv()函数返回一个选定后的参数

codeforces 612B HDD is Outdated Technology

B. HDD is Outdated Technology HDD hard drives group data by sectors. All files are split to fragments and each of them are written in some sector of hard drive. Note the fragments can be written in sectors in arbitrary order. One of the problems of H