Advertisement
patryk

GKiW_LAB02

Mar 17th, 2015
515
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.73 KB | None | 0 0
  1. #include <windows.h> //Wymagane dla implementacji OpenGL w Visual Studio.
  2. #include "gl\gl.h"
  3. #include "gl\glut.h"
  4. #include "stdio.h" //Przydatne do wypisywania komunikatów na konsoli
  5. #include "glm\glm.hpp"
  6. #include "glm\gtc\matrix_transform.hpp"
  7. #include "glm\gtc\type_ptr.hpp"
  8.  
  9. using namespace glm;
  10.  
  11. float speed = 100;
  12. int lastTime = 0;
  13. float angle;
  14.  
  15. void displayFrame(void) {
  16.         glClearColor(0.122, 0.412, 0.414, 0);
  17.         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  18.  
  19.         mat4 M = mat4(1.0f);
  20.         mat4 V = lookAt(
  21.             vec3(0.0f, 0.0f, -5.0f),
  22.             vec3(0.0f, 0.0f, 0.0f),
  23.             vec3(0.0f, 1.0f, 0.0f) );
  24.         mat4 P = perspective(50.0f, 1.0f, 1.0f, 50.0f);
  25.  
  26.         mat4 R = rotate(M, angle -  sin(angle), vec3(1.0f, 0.0f, 1.0f));
  27.         mat4 T = translate(M, vec3(1.0f, 1.0f, 0.0f));
  28.         M = R*T;
  29.         glMatrixMode(GL_PROJECTION);
  30.         glLoadMatrixf(value_ptr(P));
  31.         glMatrixMode(GL_MODELVIEW);
  32.         glLoadMatrixf(value_ptr(V*M));
  33.  
  34.         glColor3b(200, 50, 100);
  35.         glutSolidTorus(0.7, 1.5, 50, 30);
  36.         glutSwapBuffers();
  37. }
  38.  
  39. void nextFrame(void) {
  40.  
  41.  
  42.     int actTime = glutGet(GLUT_ELAPSED_TIME);
  43.     int interval = actTime - lastTime;
  44.     lastTime = actTime;
  45.     angle += speed * interval / 1000.0;
  46.     if (angle > 360) angle -= 360;
  47.     glutPostRedisplay();
  48. }
  49.  
  50. int main(int argc, char* argv[]) {
  51.         glutInit(&argc, argv);
  52.         glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
  53.         glutInitWindowSize(800,800);
  54.         glutInitWindowPosition(0,0);
  55.         glutCreateWindow("Program OpenGL");        
  56.         glutDisplayFunc(displayFrame);
  57.         glutIdleFunc(nextFrame);
  58.         glEnable(GL_LIGHTING);
  59.         glEnable(GL_LIGHT0);
  60.         glEnable(GL_DEPTH_TEST);
  61.         glEnable(GL_COLOR_MATERIAL);
  62.        
  63.         //Tutaj kod inicjujący
  64.  
  65.         glutMainLoop();
  66.         return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement