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.

182 lines
4.4 KiB

  1. /*
  2. * bgammon.c
  3. *
  4. * start easy, just have pieces...
  5. *
  6. */
  7. #include <windows.h>
  8. #include <gl.h>
  9. #include <glu.h>
  10. #include <glaux.h>
  11. GLvoid initialize(GLvoid);
  12. GLvoid drawScene(GLvoid);
  13. GLvoid resize(GLsizei, GLsizei);
  14. GLvoid drawLight(GLvoid);
  15. void polarView( GLdouble, GLdouble, GLdouble, GLdouble);
  16. GLfloat latitude, longitude, radius;
  17. void __cdecl main(void)
  18. {
  19. initialize();
  20. auxMainLoop( drawScene );
  21. }
  22. GLvoid resize( GLsizei width, GLsizei height )
  23. {
  24. GLfloat aspect;
  25. glViewport( 0, 0, width, height );
  26. aspect = (GLfloat) width / height;
  27. glMatrixMode( GL_PROJECTION );
  28. glLoadIdentity();
  29. gluPerspective( 45.0, aspect, 3.0, 7.0 );
  30. glMatrixMode( GL_MODELVIEW );
  31. }
  32. GLvoid initialize(GLvoid)
  33. {
  34. GLfloat maxObjectSize, aspect;
  35. GLdouble near_plane, far_plane;
  36. GLsizei width, height;
  37. GLfloat ambientProperties[] = {2.0, 2.0, 2.0, 1.0};
  38. GLfloat diffuseProperties[] = {0.8, 0.8, 0.8, 1.0};
  39. GLfloat specularProperties[] = {1.0, 4.0, 4.0, 1.0};
  40. width = 1024.0;
  41. height = 768.0;
  42. auxInitPosition( width/4, height/4, width/2, height/2);
  43. auxInitDisplayMode( AUX_RGBA | AUX_DEPTH16 | AUX_DOUBLE );
  44. auxInitWindow( "Rotating Shapes" );
  45. auxIdleFunc( drawScene );
  46. auxReshapeFunc( resize );
  47. glClearColor( 0.0, 0.0, 0.0, 1.0 );
  48. glClearDepth( 1.0 );
  49. glEnable(GL_DEPTH_TEST);
  50. glEnable(GL_LIGHTING);
  51. glLightfv( GL_LIGHT0, GL_AMBIENT, ambientProperties);
  52. glLightfv( GL_LIGHT0, GL_DIFFUSE, diffuseProperties);
  53. glLightfv( GL_LIGHT0, GL_SPECULAR, specularProperties);
  54. glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, 1.0);
  55. glEnable( GL_LIGHT0 );
  56. glMatrixMode( GL_PROJECTION );
  57. aspect = (GLfloat) width / height;
  58. gluPerspective( 45.0, aspect, 3.0, 7.0 );
  59. glMatrixMode( GL_MODELVIEW );
  60. near_plane = 3.0;
  61. far_plane = 7.0;
  62. maxObjectSize = 3.0;
  63. radius = near_plane + maxObjectSize/2.0;
  64. latitude = 0.0;
  65. longitude = 0.0;
  66. }
  67. void polarView(GLdouble radius, GLdouble twist, GLdouble latitude,
  68. GLdouble longitude)
  69. {
  70. glTranslated(0.0, 0.0, -radius);
  71. glRotated( -twist, 0.0, 0.0, 1.0 );
  72. glRotated( -latitude, 1.0, 0.0, 0.0);
  73. glRotated( longitude, 0.0, 0.0, 1.0);
  74. }
  75. GLvoid drawScene(GLvoid)
  76. {
  77. static GLfloat whiteAmbient[] = {0.3, 0.3, 0.3, 1.0};
  78. static GLfloat redAmbient[] = {0.3, 0.1, 0.1, 1.0};
  79. static GLfloat greenAmbient[] = {0.1, 0.3, 0.1, 1.0};
  80. static GLfloat blueAmbient[] = {0.1, 0.1, 0.3, 1.0};
  81. static GLfloat whiteDiffuse[] = {1.0, 1.0, 1.0, 1.0};
  82. static GLfloat redDiffuse[] = {1.0, 0.0, 0.0, 1.0};
  83. static GLfloat greenDiffuse[] = {0.0, 1.0, 0.0, 1.0};
  84. static GLfloat blueDiffuse[] = {0.0, 0.0, 1.0, 1.0};
  85. static GLfloat whiteSpecular[] = {1.0, 1.0, 1.0, 1.0};
  86. static GLfloat redSpecular[] = {1.0, 0.0, 0.0, 1.0};
  87. static GLfloat greenSpecular[] = {0.0, 1.0, 0.0, 1.0};
  88. static GLfloat blueSpecular[] = {0.0, 0.0, 1.0, 1.0};
  89. static GLfloat lightPosition0[] = {0.0, 0.0, 0.0, 1.0};
  90. static GLfloat angle = 0.0;
  91. glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  92. glPushMatrix();
  93. latitude += 6.0;
  94. longitude += 2.5;
  95. polarView( radius, 0, latitude, longitude );
  96. glPushMatrix();
  97. angle += 6.0;
  98. glRotatef(angle, 1.0, 0.0, 1.0);
  99. glTranslatef( 0.0, 1.5, 0.0);
  100. glLightfv(GL_LIGHT0, GL_POSITION, lightPosition0);
  101. drawLight();
  102. glPopMatrix();
  103. glPushAttrib(GL_LIGHTING_BIT);
  104. glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, redAmbient);
  105. glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, redDiffuse);
  106. glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, whiteSpecular);
  107. glMaterialf(GL_FRONT, GL_SHININESS, 100.0);
  108. auxSolidCone( 0.3, 0.6 );
  109. glPopAttrib();
  110. auxWireSphere(1.5);
  111. glPushAttrib(GL_LIGHTING_BIT);
  112. glMaterialfv(GL_BACK, GL_AMBIENT, greenAmbient);
  113. glMaterialfv(GL_BACK, GL_DIFFUSE, greenDiffuse);
  114. glMaterialfv(GL_FRONT, GL_AMBIENT, blueAmbient);
  115. glMaterialfv(GL_FRONT, GL_DIFFUSE, blueDiffuse);
  116. glMaterialfv(GL_FRONT, GL_SPECULAR, blueSpecular);
  117. glMaterialf(GL_FRONT, GL_SHININESS, 50.0);
  118. glPushMatrix();
  119. glTranslatef(0.8, -0.65, 0.0);
  120. glRotatef(30.0, 1.0, 0.5, 1.0);
  121. auxSolidCylinder( 0.3, 0.6 );
  122. glPopMatrix();
  123. glPopAttrib();
  124. glPopMatrix();
  125. auxSwapBuffers();
  126. }
  127. GLvoid drawLight(GLvoid)
  128. {
  129. glPushAttrib(GL_LIGHTING_BIT);
  130. glDisable(GL_LIGHTING);
  131. glColor3f(1.0, 1.0, 1.0);
  132. auxSolidDodecahedron(0.1);
  133. glPopAttrib();
  134. }