Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h> //Wymagane dla implementacji OpenGL w Visual Studio.
- #include "gl\gl.h"
- #include "gl\glut.h"
- #include "stdio.h" //Przydatne do wypisywania komunikatów na konsoli
- #include "glm\glm.hpp"
- #include "glm\gtc\matrix_transform.hpp"
- #include "glm\gtc\type_ptr.hpp"
- using namespace glm;
- float speed = 100;
- int lastTime = 0;
- float angle;
- void displayFrame(void) {
- glClearColor(0.122, 0.412, 0.414, 0);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- mat4 M = mat4(1.0f);
- mat4 V = lookAt(
- vec3(0.0f, 0.0f, -5.0f),
- vec3(0.0f, 0.0f, 0.0f),
- vec3(0.0f, 1.0f, 0.0f) );
- mat4 P = perspective(50.0f, 1.0f, 1.0f, 50.0f);
- mat4 R = rotate(M, angle - sin(angle), vec3(1.0f, 0.0f, 1.0f));
- mat4 T = translate(M, vec3(1.0f, 1.0f, 0.0f));
- M = R*T;
- glMatrixMode(GL_PROJECTION);
- glLoadMatrixf(value_ptr(P));
- glMatrixMode(GL_MODELVIEW);
- glLoadMatrixf(value_ptr(V*M));
- glColor3b(200, 50, 100);
- glutSolidTorus(0.7, 1.5, 50, 30);
- glutSwapBuffers();
- }
- void nextFrame(void) {
- int actTime = glutGet(GLUT_ELAPSED_TIME);
- int interval = actTime - lastTime;
- lastTime = actTime;
- angle += speed * interval / 1000.0;
- if (angle > 360) angle -= 360;
- glutPostRedisplay();
- }
- int main(int argc, char* argv[]) {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
- glutInitWindowSize(800,800);
- glutInitWindowPosition(0,0);
- glutCreateWindow("Program OpenGL");
- glutDisplayFunc(displayFrame);
- glutIdleFunc(nextFrame);
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
- glEnable(GL_DEPTH_TEST);
- glEnable(GL_COLOR_MATERIAL);
- //Tutaj kod inicjujący
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement