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

OpenGL

开发平台:

Windows_Unix

  1. //
  2. // a64ki
  3. // Copyright (c) 2002 Henrik Carlgren
  4. // http://ziruz.cjb.net
  5. // ziruz@hotpop.com
  6. //
  7. //
  8. // INCLUDE FILES
  9. //
  10. #include "intro.h"
  11. #include "particle.h"
  12. #include "texture.h"
  13. #include "misc.h"
  14. #include <windows.h>
  15. #include <glgl.h>
  16. //
  17. // GLOBAL VARIABLES
  18. //
  19. const int particleCount = 2048;
  20. VECTOR targetPosition;
  21. VECTOR targetVelocity;
  22. VECTOR targetImpulse;
  23. PARTICLE particle[particleCount];
  24. extern GLuint texture[TEXTURE_COUNT];
  25. //
  26. // FUNCTION: introStartup
  27. //
  28. void introStartup(void)
  29. {
  30. //
  31. // PARTICLE SYSTEM
  32. //
  33. targetVelocity.x = 0.0f;
  34. targetVelocity.y = -0.002f;
  35. targetVelocity.z = 0.0f;
  36. for(int i = 0; i < particleCount; i++)
  37. {
  38. particle[i].targetPosition = &targetPosition;
  39. particle[i].targetVelocity = &targetVelocity;
  40. particle[i].targetImpulse = &targetImpulse;
  41. particle[i].ageRangeMinimum = 1000;
  42. particle[i].ageRangeMaximum = 2000;
  43. particle[i].color.x = 1.0f; // red
  44. particle[i].color.y = 0.68f; // green
  45. particle[i].color.z = 0.32f; // blue
  46. particle[i].birth();
  47. }
  48. generateTextures();
  49. }
  50. //
  51. // FUNCTION: introCleanup
  52. //
  53. void introCleanup(void)
  54. {
  55. }
  56. //
  57. // FUNCTION: introStartup
  58. //
  59. void introCycle(long double time, long double delta)
  60. {
  61. float particleSize = 0.16f;
  62. int particleUsage = particleCount;
  63. //
  64. // PRE
  65. //
  66. glClear(GL_DEPTH_BUFFER_BIT);
  67. //
  68. // BACKGROUND
  69. //
  70. ortho();
  71. glMatrixMode(GL_TEXTURE);
  72. glPushMatrix();
  73. glTranslatef((float)time*-0.0001f, 0.0f, 0.0f);
  74. glRotatef((float)time*-0.01f, 1.0f, 0.0f, 0.0f);
  75. glRotatef((float)time*-0.02f, 0.0f, 1.0f, 0.0f);
  76. glRotatef((float)time*-0.03f, 0.0f, 0.0f, 1.0f);
  77. glEnable(GL_BLEND);
  78. glDisable(GL_DEPTH_TEST);
  79. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  80. glEnable(GL_TEXTURE_2D);
  81. glBindTexture(GL_TEXTURE_2D, texture[TEXTURE_BG1]);
  82. glColor4f(0.5f, 0.5f, 1.0f, (float)delta*0.01f);
  83. glBegin(GL_QUADS);
  84. glTexCoord2i(0, 0);
  85. glVertex2i(0, 0);
  86. glTexCoord2i(1, 0);
  87. glVertex2i(800, 0);
  88. glTexCoord2i(1, 1);
  89. glVertex2i(800, 600);
  90. glTexCoord2i(0, 1);
  91. glVertex2i(0, 600);
  92. glEnd();
  93. glPopMatrix();
  94. glMatrixMode(GL_MODELVIEW);
  95. //
  96. // PARTICLE SYSTEM
  97. //
  98. float timeScale = 0.005f;
  99. targetPosition.x = 2.0f * cosf((float)time * timeScale);
  100. targetPosition.y = sinf((float)time * timeScale) + 0.8f;
  101. targetPosition.z = cosf((float)time * (timeScale / 2.0f)) - 1.0f;
  102. targetImpulse.x = 0.005f * sinf((float)time * timeScale);
  103. targetImpulse.y = 0.005f * -cosf((float)time * timeScale);
  104. targetImpulse.z = 0.005f * (sinf((float)time * (timeScale / 2.0f)));
  105. perspective();
  106. glTranslatef(0.0f,0.0f,-2.75f);
  107. glEnable(GL_BLEND);
  108. glDisable(GL_DEPTH_TEST);
  109. glBlendFunc(GL_SRC_ALPHA, GL_ONE);
  110. glEnable(GL_TEXTURE_2D);
  111. glBindTexture(GL_TEXTURE_2D, texture[TEXTURE_PARTICLE]);
  112. for(int i = 0; i < particleUsage; i++)
  113. {
  114. particle[i].update(delta);
  115. glColor4f( particle[i].color.x-0.16f,
  116. particle[i].color.y-0.16f,
  117. particle[i].color.z-0.16f,
  118. (1.0f - (float)particle[i].currentAge/(float)particle[i].maximumAge)*0.1f*(float)delta);
  119. glBegin(GL_QUADS);
  120. glTexCoord2d(0,0);
  121. glVertex3f( particle[i].position.x - particleSize,
  122. particle[i].position.y - particleSize,
  123. particle[i].position.z);
  124. glTexCoord2d(1,0);
  125. glVertex3f( particle[i].position.x + particleSize,
  126. particle[i].position.y - particleSize,
  127. particle[i].position.z);
  128. glTexCoord2d(1,1);
  129. glVertex3f( particle[i].position.x + particleSize,
  130. particle[i].position.y + particleSize,
  131. particle[i].position.z);
  132. glTexCoord2d(0,1);
  133. glVertex3f( particle[i].position.x - particleSize,
  134. particle[i].position.y + particleSize,
  135. particle[i].position.z);
  136. glEnd();
  137. }
  138. //
  139. // SOFT WIDESCREEN
  140. //
  141. ortho();
  142. glEnable(GL_BLEND);
  143. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  144. glDisable(GL_DEPTH_TEST);
  145. glDisable(GL_TEXTURE_2D);
  146. glBegin(GL_QUADS);
  147. glColor4f(0.0f, 0.0f, 0.0f, 0.1f*(float)delta);
  148. glVertex2d(0, 0);
  149. glVertex2d(800, 0);
  150. glColor4f(0.0f, 0.0f, 0.0f, 0.0);
  151. glVertex2d(800, 100);
  152. glVertex2d(0, 100);
  153. //
  154. glVertex2d(0, 500);
  155. glVertex2d(800, 500);
  156. glColor4f(0.0f, 0.0f, 0.0f, 0.1f*(float)delta);
  157. glVertex2d(800, 600);
  158. glVertex2d(0, 600);
  159. glEnd();
  160. //
  161. // FADEOUT
  162. //
  163. if(time > 22500.0)
  164. {
  165. fadeOut(2500.0, time-22500.0);
  166. }
  167. //
  168. // END
  169. //
  170. SwapBuffers(wglGetCurrentDC());
  171. }