Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <time.h>
- #include <GL/gl.h>
- #include <GL/glu.h>
- #include <GL/glut.h>
- GLfloat zoom = -7.0;
- GLfloat rotObsY = 25.0;
- GLfloat rotObsX = 20.0;
- int pomocnicze = -1;
- void Rysuj(void)
- {
- glEnable(GL_DEPTH_TEST);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glMatrixMode(GL_MODELVIEW);
- if(pomocnicze == 1)
- {
- glBegin(GL_LINES);
- glColor3f(1.0, 0.0, 0.0);
- glVertex3f(-100.0, 0.0, 0.0);
- glVertex3f(100.0, 0.0, 0.0);
- glColor3f(0.0,1.0,0.0);
- glVertex3f(0.0, -100.0, 0.0);
- glVertex3f(0.0, 100.0, 0.0);
- glColor3f(0.0,0.0,1.0);
- glVertex3f(0.0, 0.0, -100.0);
- glVertex3f(0.0, 0.0, 100.0);
- glEnd();
- }
- glPushMatrix();
- glColor3f(0.3f, 0.5f, 0.3f);
- glutSolidCube(1.0);
- glPopMatrix();
- }
- void WyswietlObraz(void)
- {
- glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
- glPushMatrix();
- glTranslatef(0, 0, zoom);
- glRotatef(rotObsX, 1, 0, 0);
- glRotatef(rotObsY,0,1,0);
- Rysuj();
- glPopMatrix();
- glutSwapBuffers();
- }
- void UstawParametryWidoku(int szerokosc, int wysokosc)
- {
- glViewport(0, 0, szerokosc, wysokosc);
- glShadeModel(GL_SMOOTH);
- glClearColor(0, 0, 0, 0);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(40.0, (float)szerokosc/(float)wysokosc, 1.0, 1000.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- }
- void ObslugaKlawiszySpecjalnych(int klawisz, int x, int y)
- {
- switch(klawisz)
- {
- case GLUT_KEY_UP:
- rotObsX = rotObsX + 2.0;
- break;
- case GLUT_KEY_DOWN:
- rotObsX = rotObsX - 2.0;
- break;
- case GLUT_KEY_LEFT:
- rotObsY = rotObsY - 2.0;
- break;
- case GLUT_KEY_RIGHT:
- rotObsY = rotObsY + 2.0;
- break;
- case GLUT_KEY_PAGE_UP:
- zoom = (zoom <= -10.0) ? zoom + 5.0 : zoom;
- break;
- case GLUT_KEY_PAGE_DOWN:
- zoom = (zoom >= -200.0) ? zoom - 5.0 : zoom;
- break;
- }
- }
- void ObslugaKlawiatury(unsigned char klawisz, int x, int y)
- {
- switch(klawisz)
- {
- case 'p': pomocnicze = -pomocnicze; break;
- case 27: exit(0); break;
- }
- }
- int main(int argc, char **argv)
- {
- glutInit(&argc, argv);
- glutInitDisplayMode (GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
- glutInitWindowPosition(100, 100);
- glutInitWindowSize(600, 400);
- glutCreateWindow("Cube");
- glEnable(GL_DEPTH_TEST);
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
- glEnable(GL_COLOR_MATERIAL);
- glClearDepth(1000.0);
- glClearColor (0.0, 0.0, 0.0, 0.0);
- glutDisplayFunc(WyswietlObraz);
- glutReshapeFunc(UstawParametryWidoku);
- glutIdleFunc(WyswietlObraz);
- glutKeyboardFunc(ObslugaKlawiatury);
- glutSpecialFunc(ObslugaKlawiszySpecjalnych);
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement