Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. #include <GL/glut.h>
  2.  
  3. double angle = 0;
  4. int color1=1;
  5.  
  6. void InitGL(void)
  7. {
  8. glClearColor(0.0, 0.8, 0.8, 0.0);
  9. glClearDepth( 1.0 );
  10. glEnable( GL_DEPTH_TEST ); //rysowanie z glebią ekranu
  11. }
  12.  
  13. void Idle(void){
  14. angle +=5;
  15. glutPostRedisplay();
  16. }
  17. void text(char*string)
  18. {
  19. char*p;
  20. for(p=string; *p;p++)
  21. glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *p);
  22. }
  23.  
  24. void reshape(int w, int h)
  25. {
  26. GLdouble aspect = (GLdouble) w / h;
  27. glViewport (0, 0, (GLsizei) w, (GLsizei) h);
  28. glMatrixMode(GL_PROJECTION); //macierz projekcji
  29. glLoadIdentity(); //zerowanie macierzy
  30. if (w <= h)
  31. glOrtho(-250.0, 250, -250./ aspect, 250.0/ aspect, -100, 100);
  32. else
  33. glOrtho (-250.*aspect, 250.*aspect, -250, 250, -100.0, 100);
  34. glMatrixMode(GL_MODELVIEW); //macierz wyglądu
  35. glLoadIdentity();
  36. }
  37.  
  38. void displayCallBack(void)
  39. {
  40. glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); //czyszczenie buforów
  41.  
  42. glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  43. glColor3d(0.1,0.3,0);
  44. glRotatef(15, 1, 1, 0);
  45. glRotatef(15,0,1,0);
  46. glutSolidCube(100);
  47.  
  48. glLoadIdentity();
  49. glColor3d(0,0,0);
  50. glRasterPos2f(-200,200);
  51. text("BLABLLABLA");
  52.  
  53.  
  54. glColor3d(1,0,0);
  55. glRotatef(angle,1.0,0.0,0.0);
  56. glRotatef(15.0,0.0,1.0,0.0);
  57. glFlush();
  58.  
  59. glutSwapBuffers(); //zamienia bufory
  60.  
  61. if(color1 == 1) glColor3d(1,0,0);
  62. if(color1 == 2) glColor3d(1,1,0);
  63. }
  64.  
  65. void Keyboard(unsigned char key, int x, int y)
  66. {
  67. switch(key)
  68. {
  69. case '1':
  70. color1 = 1;
  71. break;
  72. case '2':
  73. color1 = 2;
  74. break;
  75. case 27: case 'q':
  76. exit(0);
  77. break;
  78. }
  79. }
  80.  
  81. void main(int argc, char** argv)
  82. {
  83. glutInit(&argc, argv);
  84.  
  85. glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE );
  86. glutInitWindowSize(600, 600);
  87. glutCreateWindow("Program_1");
  88.  
  89.  
  90. InitGL();
  91.  
  92. float pos[4] = { 1.50F, 3.50F, 0.25F, 0.00F };
  93. float dir[3] = {-1, -1, -1};
  94. glEnable(GL_COLOR_MATERIAL);
  95. glEnable(GL_LIGHTING);
  96. glEnable(GL_LIGHT0);
  97.  
  98. glLightfv(GL_LIGHT0, GL_POSITION, pos);
  99. glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, dir);
  100.  
  101.  
  102. glutReshapeFunc(reshape);
  103. glutDisplayFunc(displayCallBack);
  104. glutMainLoop();
  105.  
  106. glutIdleFunc(Idle);
  107. glutMainLoop();
  108. float pos[4] = {0.90F, 0.90F, 2.25F, 0.00F};
  109. glutKeyboardFunc(Keyboard);
  110. glutIdleFunc(Idle);
  111.  
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement