Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.2 KiB

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <time.h>
  4. #include <windows.h>
  5. #include <gl\gl.h>
  6. #include "skeltest.h"
  7. #include "square.h"
  8. SquareTest::SquareTest()
  9. {
  10. static BOOL b = FALSE;
  11. if (!b) {
  12. srand((unsigned)time(NULL));
  13. b = TRUE;
  14. }
  15. td.swapbuffers = FALSE;
  16. td.iDuration = 10000;
  17. td.iX = 0;
  18. td.iY = 0;
  19. td.iW = 640;
  20. td.iH = 480;
  21. sprintf(td.acName,"Bouncing Square (demo only)");
  22. bd.cColorBits = 8;
  23. bd.cDepthBits = 16;
  24. iRsize = 50;
  25. fXstep = 1.0f;
  26. fYstep = 1.0f;
  27. }
  28. void SquareTest::INITFUNCTION()
  29. {
  30. // Prevent a divide by zero, when window is too short
  31. // (you cant make a window of zero width).
  32. if(h == 0) h = 1;
  33. fX1 = (GLfloat) rand()/100.0f;
  34. fY1 = (GLfloat) rand()/150.0f;
  35. // Set the viewport to be the entire window
  36. glViewport(0, 0, w, h);
  37. // Reset the coordinate system before modifying
  38. glLoadIdentity();
  39. // Keep the square square, this time, save calculated
  40. // width and height for later use
  41. if (w <= h) {
  42. fWindowHeight = 250.0f*h/w;
  43. fWindowWidth = 250.0f;
  44. } else {
  45. fWindowWidth = 250.0f*w/h;
  46. fWindowHeight = 250.0f;
  47. }
  48. // Set the clipping volume
  49. glOrtho(0.0f, fWindowWidth, 0.0f, fWindowHeight, 1.0f, -1.0f);
  50. }
  51. void SquareTest::IDLEFUNCTION()
  52. {
  53. // Reverse direction when you reach left or right edge
  54. if(fX1 > fWindowWidth-iRsize || fX1 < 0)
  55. fXstep = -fXstep;
  56. // Reverse direction when you reach top or bottom edge
  57. if(fY1 > fWindowHeight-iRsize || fY1 < 0)
  58. fYstep = -fYstep;
  59. // Check bounds. This is incase the window is made
  60. // smaller and the rectangle is outside the new
  61. // clipping volume
  62. if(fX1 > fWindowWidth-iRsize)
  63. fX1 = fWindowWidth-iRsize-1;
  64. if(fY1 > fWindowHeight-iRsize)
  65. fY1 = fWindowHeight-iRsize-1;
  66. // Actually move the square
  67. fX1 += fXstep;
  68. fY1 += fYstep;
  69. }
  70. void SquareTest::RENDFUNCTION()
  71. {
  72. // Set background clearing color to blue
  73. glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
  74. // Clear the window with current clearing color
  75. glClear(GL_COLOR_BUFFER_BIT);
  76. // Set drawing color to Red, and draw rectangle at
  77. // current position.
  78. glColor3f(1.0f, 0.0f, 0.0f);
  79. glRectf(fX1, fY1, fX1+iRsize, fY1+iRsize);
  80. glFlush();
  81. }