Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define GLUT_DISABLE_ATEXIT_HACK
- #include <GL/gl.h>
- #include <GL/glu.h>
- #include <GL/glut.h>
- #include <stdio.h>
- #include <stdlib.h>
- int screenWidth = 600;
- int screenHeight = 600;
- int fps = 60;
- GLdouble cameraPos[] = {0.0, 0.0, 25.0};
- double baserotation = 180.0;
- double rotation = 0.0;
- GLfloat lightAmb[] = {0.1, 0.1, 0.1, 1.0};
- GLfloat lightDif[] = {0.7, 0.7, 0.7, 1.0};
- GLfloat lightPos[] = {0, 0, 800, 1.0};
- GLfloat lightSpec[] = {1, 1, 1, 1};
- GLfloat points[4][3] = {
- {-5.0, 5.0, 0.0},
- {0.0, 0.0, 0.0},
- {5.0, -2.0, 0.0},
- {7.0, 4.0, 0.0}
- };
- GLuint activePoint = 0;
- void init(){
- glEnable(GL_DEPTH_TEST);
- glEnable(GL_POINT_SMOOTH);
- glEnable(GL_MAP1_VERTEX_3);
- }
- void display() {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glClearColor(0.0, 0.0, 0.0, 1.0);
- glLoadIdentity ();
- gluLookAt(cameraPos[0], cameraPos[1], cameraPos[2], 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
- glColor3f(1.0, 0.0, 0.0);
- glPointSize(5);
- glBegin(GL_POINTS);
- (activePoint != 0) ? glColor3f(1.0, 0.0, 0.0) : glColor3f(0.0, 1.0, 0.0);
- glVertex3fv(points[0]);
- (activePoint != 1) ? glColor3f(1.0, 0.0, 0.0) : glColor3f(0.0, 1.0, 0.0);
- glVertex3fv(points[1]);
- (activePoint != 2) ? glColor3f(1.0, 0.0, 0.0) : glColor3f(0.0, 1.0, 0.0);
- glVertex3fv(points[2]);
- (activePoint != 3) ? glColor3f(1.0, 0.0, 0.0) : glColor3f(0.0, 1.0, 0.0);
- glVertex3fv(points[3]);
- glEnd();
- glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, &points[0][0]);
- glMapGrid1f(30, 0, 1);
- glEvalMesh1(GL_LINE, 0, 30);
- glFlush ();
- glutPostRedisplay();
- glutSwapBuffers();
- }
- void reshape(int w, int h) {
- glViewport(0, 0, (GLsizei) w, (GLsizei) h);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(45.0, (GLfloat)w / (GLfloat)h, 1.5, 300.0);
- glMatrixMode(GL_MODELVIEW);
- }
- void keyboard(unsigned char key, int x, int y){
- switch(key){
- case 27 :
- case 'q':
- exit(0);
- break;
- case 32:
- ++activePoint %= 4; break;
- case 'w':
- points[activePoint][1]++; break;
- case 's':
- points[activePoint][1]--; break;
- case 'a':
- points[activePoint][0]--; break;
- case 'd':
- points[activePoint][0]++; break;
- }
- }
- void timerfunc(int p){
- rotation += 0.3;
- glutPostRedisplay();
- glutTimerFunc(1000/fps, &timerfunc, 0);
- }
- void menu(int value) {
- switch(value) {
- case 0:
- exit(0);
- break;
- }
- }
- int main(int argc, char *argv[]) {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
- glutInitWindowSize(screenWidth, screenHeight);
- glutCreateWindow(argv[0]);
- glutDisplayFunc(display);
- glutReshapeFunc(reshape);
- glutKeyboardFunc(keyboard);
- glutTimerFunc(1000/fps, &timerfunc, 0);
- glutCreateMenu(menu);
- glutAddMenuEntry("Wyjscie", 0);
- glutAttachMenu(GLUT_RIGHT_BUTTON);
- init();
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement