Hyper.cpp
上传用户:sz83729876
上传日期:2013-03-07
资源大小:4140k
文件大小:6k
源码类别:

OpenGL

开发平台:

Windows_Unix

  1. //
  2. // a64ki
  3. // Copyright (c) 2002 Henrik Carlgren
  4. // http://ziruz.cjb.net
  5. // ziruz@hotpop.com
  6. //
  7. #include <windows.h>
  8. #include <glgl.h>
  9. #include "misc.h"
  10. #include "texture.h"
  11. #include "vector.h"
  12. #include "PQTorus.h"
  13. extern GLuint texture[TEXTURE_COUNT];
  14. void hyperCycle(float a_fTime, float a_fDelta)
  15. {
  16. int i;
  17. a_fTime += 10000.0f;
  18. glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
  19. glClearStencil(0);
  20. glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
  21. glDisable(GL_DEPTH_TEST);
  22. glEnable(GL_BLEND);
  23. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  24. // Background Layer 1
  25. {
  26. ortho();
  27. glEnable(GL_TEXTURE_2D);
  28. glBindTexture(GL_TEXTURE_2D, texture[TEXTURE_ENV1]);
  29. glColor4f(1.0f, 1.0f, 1.0f, 0.1f);
  30. glBegin(GL_QUADS);
  31. glTexCoord2i(0, 0); glVertex2i(0, 0);
  32. glTexCoord2i(0, 1); glVertex2i(0, 600);
  33. glTexCoord2i(1, 1); glVertex2i(800, 600);
  34. glTexCoord2i(1, 0); glVertex2i(800, 0);
  35. glEnd();
  36. glDisable(GL_TEXTURE_2D);
  37. }
  38. // Background Layer 2
  39. {
  40. ortho();
  41. glMatrixMode(GL_TEXTURE);
  42. glPushMatrix();
  43. glLoadIdentity();
  44. glTranslatef(a_fTime * 0.00005f, a_fTime * 0.0001f, 0.0f);
  45. glRotatef(sinf(a_fTime * 0.001f) * a_fTime * 0.002f, 0.0f, 0.0f, 1.0f);
  46. glEnable(GL_TEXTURE_2D);
  47. glBlendFunc(GL_SRC_ALPHA, GL_ONE);
  48. glBindTexture(GL_TEXTURE_2D, texture[TEXTURE_ENV1]);
  49. glColor4f(1.0f, 1.0f, 1.0f, 0.003f + 0.002f * cosf(a_fTime * 0.0003f));
  50. glBegin(GL_QUADS);
  51. glTexCoord2i(0, 0); glVertex2i(0, 0);
  52. glTexCoord2i(0, 1); glVertex2i(0, 600);
  53. glTexCoord2i(1, 1); glVertex2i(800, 600);
  54. glTexCoord2i(1, 0); glVertex2i(800, 0);
  55. glEnd();
  56. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  57. glDisable(GL_TEXTURE_2D);
  58. glPopMatrix();
  59. glMatrixMode(GL_MODELVIEW);
  60. }
  61. // Background Layer 3
  62. {
  63. ortho();
  64. glMatrixMode(GL_TEXTURE);
  65. glPushMatrix();
  66. glLoadIdentity();
  67. glTranslatef(-a_fTime * 0.00002f,-a_fTime * 0.0002f, 0.0f);
  68. glRotatef(sinf(a_fTime * 0.0004f) * a_fTime * 0.001f, 0.0f, 0.0f, 1.0f);
  69. glEnable(GL_TEXTURE_2D);
  70. glBlendFunc(GL_SRC_ALPHA, GL_ONE);
  71. glBindTexture(GL_TEXTURE_2D, texture[TEXTURE_ENV1]);
  72. glColor4f(1.0f, 1.0f, 1.0f, 0.001f + 0.001f * sinf(a_fTime * 0.0001f));
  73. glBegin(GL_QUADS);
  74. glTexCoord2i(0, 0); glVertex2i(0, 0);
  75. glTexCoord2i(0, 20); glVertex2i(0, 600);
  76. glTexCoord2i(20, 20); glVertex2i(800, 600);
  77. glTexCoord2i(20, 0); glVertex2i(800, 0);
  78. glEnd();
  79. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  80. glDisable(GL_TEXTURE_2D);
  81. glPopMatrix();
  82. glMatrixMode(GL_MODELVIEW);
  83. }
  84. // PQTorus
  85. {
  86. static VECTOR oPosition(1024.0f, 0.0f, -96.0f);
  87. static VECTOR oRotation;
  88. float fStencilLine1 = 0.0f;
  89. float fStencilLine2 = 0.0f;
  90. if(a_fTime >= 15000.0f)
  91. {
  92. fStencilLine1 = 0.05f * (a_fTime - 15000.0f);
  93. }
  94. if(a_fTime >= 20000.0f)
  95. {
  96. fStencilLine2 = 0.05f * (a_fTime - 20000.0f);
  97. }
  98. glEnable(GL_TEXTURE_GEN_S);
  99. glEnable(GL_TEXTURE_GEN_T);
  100. glEnable(GL_STENCIL_TEST);
  101. glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
  102. glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
  103. ortho();
  104. glStencilOp(GL_KEEP, GL_INCR, GL_INCR);
  105. glStencilMask(0xff);
  106. glStencilFunc(GL_ALWAYS, 0x0, 0xff);
  107. glColor4f(0.0f, 0.0f, 0.0f, 0.1f);
  108. glBegin(GL_QUADS);
  109. glVertex2i(0, 0);
  110. glVertex2i(0, int(fStencilLine1));
  111. glVertex2i(800, int(fStencilLine1));
  112. glVertex2i(800, 0);
  113. glEnd();
  114. glBegin(GL_QUADS);
  115. glVertex2i(0, 0);
  116. glVertex2i(0, 600);
  117. glVertex2i(int(fStencilLine2), 600);
  118. glVertex2i(int(fStencilLine2), 0);
  119. glEnd();
  120. perspective();
  121. glTranslatef(oPosition.x, oPosition.y, oPosition.z);
  122. if(a_fTime <= 15000.0f)
  123. {
  124. oPosition.x = 1024.0f - (1000.0f / 15000.0f) * a_fTime;
  125. }
  126. else
  127. {
  128. oPosition.x = 24.0f + 8.0f * sinf(a_fTime * 0.004f);
  129. }
  130. oPosition.y = 8.0f * sinf(a_fTime * 0.006f);
  131. if(a_fTime >= 10000.0f)
  132. {
  133. float fSmoothSpeed;
  134. if(a_fTime <= 20000.0f)
  135. {
  136. fSmoothSpeed = ( 1.0f / 10000.0f ) * ( a_fTime - 10000.0f );
  137. }
  138. else
  139. {
  140. fSmoothSpeed = 1.0f;
  141. }
  142. glRotatef(oRotation.x * fSmoothSpeed, 1.0f, 0.0f, 0.0f);
  143. glRotatef(oRotation.y * fSmoothSpeed, 0.0f, 1.0f, 0.0f);
  144. glRotatef(oRotation.z * fSmoothSpeed, 0.0f, 0.0f, 1.0f);
  145. oRotation.x += a_fDelta * 0.1f;
  146. oRotation.y += a_fDelta * 0.2f;
  147. oRotation.z += a_fDelta * 0.1f;
  148. }
  149. glEnable(GL_TEXTURE_2D);
  150. glBindTexture(GL_TEXTURE_2D, texture[TEXTURE_CWL0]);
  151. glColor4f(1.0f, 1.0f, 1.0f, 0.1f);
  152. glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  153. glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
  154. glStencilMask(0xff);
  155. glStencilFunc(GL_EQUAL, 0x0, 0xff);
  156. glBegin(GL_TRIANGLES);
  157. for(i = 0; i < sizeof(PQTorus_vidx)/sizeof(long); i++)
  158. {
  159. glNormal3d( PQTorus_normal[ PQTorus_nidx[i] ].x,
  160. PQTorus_normal[ PQTorus_nidx[i] ].y,
  161. PQTorus_normal[ PQTorus_nidx[i] ].z);
  162. glVertex3d( PQTorus_vertex[ PQTorus_vidx[i] ].x,
  163. PQTorus_vertex[ PQTorus_vidx[i] ].y,
  164. PQTorus_vertex[ PQTorus_vidx[i] ].z);
  165. }
  166. glEnd();
  167. glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  168. glStencilFunc(GL_EQUAL, 0x1, 0xff);
  169. glBegin(GL_TRIANGLES);
  170. for(i = 0; i < sizeof(PQTorus_vidx)/sizeof(long); i++)
  171. {
  172. glNormal3d( PQTorus_normal[ PQTorus_nidx[i] ].x,
  173. PQTorus_normal[ PQTorus_nidx[i] ].y,
  174. PQTorus_normal[ PQTorus_nidx[i] ].z);
  175. glVertex3d( PQTorus_vertex[ PQTorus_vidx[i] ].x,
  176. PQTorus_vertex[ PQTorus_vidx[i] ].y,
  177. PQTorus_vertex[ PQTorus_vidx[i] ].z);
  178. }
  179. glEnd();
  180. glStencilFunc(GL_EQUAL, 0x2, 0xff);
  181. glBindTexture(GL_TEXTURE_2D, texture[TEXTURE_ENV1]);
  182. glBegin(GL_TRIANGLES);
  183. for(i = 0; i < sizeof(PQTorus_vidx)/sizeof(long); i++)
  184. {
  185. glNormal3d( PQTorus_normal[ PQTorus_nidx[i] ].x,
  186. PQTorus_normal[ PQTorus_nidx[i] ].y,
  187. PQTorus_normal[ PQTorus_nidx[i] ].z);
  188. glVertex3d( PQTorus_vertex[ PQTorus_vidx[i] ].x,
  189. PQTorus_vertex[ PQTorus_vidx[i] ].y,
  190. PQTorus_vertex[ PQTorus_vidx[i] ].z);
  191. }
  192. glEnd();
  193. glDisable(GL_TEXTURE_2D);
  194. glDisable(GL_STENCIL_TEST);
  195. glDisable(GL_TEXTURE_GEN_T);
  196. glDisable(GL_TEXTURE_GEN_S);
  197. }
  198. glDisable(GL_BLEND);
  199. glEnable(GL_DEPTH_TEST);
  200. //
  201. // SOFT INTRO
  202. //
  203. if(a_fTime < 12500.0f)
  204. {
  205. fadeOut(2500.0f, 12500.0f - a_fTime);
  206. }
  207. SwapBuffers(wglGetCurrentDC());
  208. }