fork download
  1. // Project.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #define GLUT_DISABLE_ATEXIT_HACK
  6. #include<windows.h>
  7. #include <GL/gl.h>
  8. #include <GL/glut.h>
  9. #include<GL/GLU.h>
  10. #include <stdio.h>
  11. #include <math.h>
  12. #include<string>
  13. #include<iostream>
  14. #include<cstdlib>
  15.  
  16.  
  17. #define eps 1e-3
  18.  
  19. using namespace std;
  20. int cnt , f = -1 ;
  21.  
  22. GLfloat COLORS[6][3] = { { 1, 0, 0 }, { 0, 1, 0 }, { 1, 0, 1 }
  23. , { 1, 1, 0 }, { 0, 0, 1 }, { 0, 1, 1 } };
  24.  
  25. GLfloat WHITE[] = { 0.0, 0.0, 0, 0 };
  26.  
  27.  
  28. int done = 0;
  29.  
  30. void myStyleInit()
  31. {
  32. glClearColor(0.5, 0.5, 0.5, 1.0);//background color+ alpha object blending parameter
  33. glPointSize(4.0);
  34. glMatrixMode(GL_PROJECTION);
  35. glLoadIdentity();
  36. glOrtho(-600, 600, -600, 600, 0, -1);
  37. }
  38.  
  39.  
  40. class Camera {
  41. double theta;
  42. double y;
  43. double dTheta;
  44. double dy;
  45. public:
  46. Camera() : theta(0), y(3), dTheta(0.04), dy(0.2) {}
  47. double getX() { return 10 * cos(theta); }
  48. double getY() { return y; }
  49. double getZ() { return 10 * sin(theta); }
  50. void moveRight() { theta += dTheta; }
  51. void moveLeft() { theta -= dTheta; }
  52. void moveUp() { y += dy; }
  53. void moveDown() { if (y > dy) y -= dy; }
  54. };
  55.  
  56. class Balloons {
  57. double radius = 0.1 ;
  58. GLfloat* color;
  59. double y ;
  60. int rand1;
  61. double x ;
  62. char c;
  63. int idle = 1;
  64.  
  65. public:
  66. Balloons() {
  67. }
  68. void create()
  69. {
  70. x = (double)(rand() % 2);
  71. x *= f;
  72. rand1 = (double)(rand() % 26);
  73. c = 'a' + rand1 ;
  74. }
  75. void animate()
  76. {
  77. float xC = COLORS[cnt % 6][0], yC = COLORS[cnt % 6][1], zC = COLORS[cnt % 6][2];
  78.  
  79. while (fabs(y - 1.8) > eps)
  80. {
  81. y = y + 0.0005;
  82. //cout << y << endl;
  83. glMatrixMode(GL_MODELVIEW);
  84. glClear(GL_COLOR_BUFFER_BIT);
  85. glLoadIdentity();
  86. glTranslatef(x, y, -4.0);
  87. glColor3f(xC, yC, zC);
  88. //glScalef(1.0, 1.0, 1.0);
  89. glutSolidSphere(radius, 60, 60);
  90. glColor3f(1.0, 1.0, 1.0);
  91. glRasterPos3d(x, y,-4.0);
  92. glColor3f(0.0f, 0.0f, 0.0f);
  93. glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, c);
  94.  
  95. glFlush();
  96. glutSwapBuffers();
  97. }
  98. }
  99.  
  100. int getIdle()
  101. {
  102. return idle;
  103. }
  104. void setIdle(int X)
  105. {
  106. idle = X;
  107. }
  108.  
  109. void update(int X)
  110. {
  111. float xC = COLORS[X % 6][0], yC = COLORS[X % 6][1], zC = COLORS[X % 6][2];
  112. if (!idle)
  113. {
  114. y += 0.001;
  115. glMatrixMode(GL_MODELVIEW);
  116. glClear(GL_COLOR_BUFFER_BIT);
  117. glLoadIdentity();
  118. glTranslatef(x, y, -4.0);
  119. glColor3f(xC, yC, zC);
  120. //glScalef(1.0, 1.0, 1.0);
  121. glutSolidSphere(radius, 60, 60);
  122. glColor3f(1.0, 1.0, 1.0);
  123. glRasterPos3d(x, y, -4.0);
  124. glColor3f(0.0f, 0.0f, 0.0f);
  125. glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, c);
  126. glutPostRedisplay();
  127.  
  128.  
  129. glFlush();
  130. glutSwapBuffers();
  131. }
  132. else
  133. {
  134. y = -1.6 + 0.001;
  135. glMatrixMode(GL_MODELVIEW);
  136. glClear(GL_COLOR_BUFFER_BIT);
  137. glLoadIdentity();
  138. glTranslatef(x, y, -4.0);
  139. glColor3f(xC, yC, zC);
  140. //glScalef(1.0, 1.0, 1.0);
  141. glutSolidSphere(radius, 0, 0);
  142. glColor3f(1.0, 1.0, 1.0);
  143. glRasterPos3d(x, y, -4.0);
  144. glColor3f(0.0f, 0.0f, 0.0f);
  145. glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, c);
  146.  
  147. glutPostRedisplay();
  148.  
  149. glFlush();
  150. glutSwapBuffers();
  151. }
  152.  
  153. if (y > 1.8)
  154. {
  155. idle = 1;
  156. y = -1.6;
  157. }
  158.  
  159.  
  160. }
  161.  
  162.  
  163. };
  164.  
  165. Camera camera;
  166. Balloons balloons[10];
  167.  
  168. void display()
  169. {
  170. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  171. glLoadIdentity();
  172. gluLookAt(camera.getX(), camera.getY(), camera.getZ(), 4 , 0.0, 4 , 0.0, 1.0, 0.0);
  173. printf("x");
  174. for (int i = 0; i < 10 ; i++)
  175. {
  176. cout << balloons[i].getIdle() <<" " << i << endl;
  177. if (done && balloons[i].getIdle() )
  178. {
  179. balloons[i].create();
  180. balloons[i].setIdle(0);
  181. balloons[i].update(i);
  182. done = 0;
  183. }
  184. else if ( !balloons[i].getIdle())
  185. {
  186. balloons[i].update(i);
  187. }
  188. //balloon.animate() ;
  189. cnt++;
  190. f = -f;
  191. //cout << cnt << endl;
  192. }
  193. glFlush();
  194. glutSwapBuffers();
  195. }
  196.  
  197.  
  198.  
  199. void reshape(GLint w, GLint h) {
  200. glViewport(0, 0, w, h);
  201. glMatrixMode(GL_PROJECTION);
  202. glLoadIdentity();
  203. gluPerspective(40.0, GLfloat(w) / GLfloat(h), 1.0, 150.0);
  204. glMatrixMode(GL_MODELVIEW);
  205. }
  206.  
  207. void timer(int v) {
  208. glutPostRedisplay();
  209. glutTimerFunc(100, timer, v);
  210. }
  211.  
  212. void special(int key, int, int) {
  213. switch (key) {
  214. case GLUT_KEY_LEFT: camera.moveLeft(); break;
  215. case GLUT_KEY_RIGHT: camera.moveRight(); break;
  216. case GLUT_KEY_UP: camera.moveUp(); break;
  217. case GLUT_KEY_DOWN: camera.moveDown(); break;
  218. }
  219. glutPostRedisplay();
  220. }
  221.  
  222.  
  223. void keyboard(unsigned char ch, int x, int y)
  224. {
  225. if (ch == 'g') done = 1;
  226. else if(ch == 's') done = 0;
  227. }
  228.  
  229.  
  230. int main(int argc, char** argv)
  231. {
  232. glutInit(&argc, argv);
  233. glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  234. glutInitWindowSize(600, 600);
  235. glutInitWindowPosition(750, 50);
  236. glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  237. glClearColor(0.0, 0.0, 0.0, 0.0);
  238. glutCreateWindow("Welcome this funky game");
  239. glutDisplayFunc(display);
  240. glutReshapeFunc(reshape);
  241. glutKeyboardFunc(keyboard);
  242. glutSpecialFunc(special);
  243. myStyleInit();
  244. glutTimerFunc(5, timer, 0);
  245. glutMainLoop();
  246. return 0;
  247. }
  248.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:4:20: fatal error: stdafx.h: No such file or directory
 #include "stdafx.h"
                    ^
compilation terminated.
stdout
Standard output is empty