Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GL/glut.h>
- double angle = 0;
- int color1=1;
- void InitGL(void)
- {
- glClearColor(0.0, 0.8, 0.8, 0.0);
- glClearDepth( 1.0 );
- glEnable( GL_DEPTH_TEST ); //rysowanie z glebią ekranu
- }
- void Idle(void){
- angle +=5;
- glutPostRedisplay();
- }
- void text(char*string)
- {
- char*p;
- for(p=string; *p;p++)
- glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *p);
- }
- void reshape(int w, int h)
- {
- GLdouble aspect = (GLdouble) w / h;
- glViewport (0, 0, (GLsizei) w, (GLsizei) h);
- glMatrixMode(GL_PROJECTION); //macierz projekcji
- glLoadIdentity(); //zerowanie macierzy
- if (w <= h)
- glOrtho(-250.0, 250, -250./ aspect, 250.0/ aspect, -100, 100);
- else
- glOrtho (-250.*aspect, 250.*aspect, -250, 250, -100.0, 100);
- glMatrixMode(GL_MODELVIEW); //macierz wyglądu
- glLoadIdentity();
- }
- void displayCallBack(void)
- {
- glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); //czyszczenie buforów
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
- glColor3d(0.1,0.3,0);
- glRotatef(15, 1, 1, 0);
- glRotatef(15,0,1,0);
- glutSolidCube(100);
- glLoadIdentity();
- glColor3d(0,0,0);
- glRasterPos2f(-200,200);
- text("BLABLLABLA");
- glColor3d(1,0,0);
- glRotatef(angle,1.0,0.0,0.0);
- glRotatef(15.0,0.0,1.0,0.0);
- glFlush();
- glutSwapBuffers(); //zamienia bufory
- if(color1 == 1) glColor3d(1,0,0);
- if(color1 == 2) glColor3d(1,1,0);
- }
- void Keyboard(unsigned char key, int x, int y)
- {
- switch(key)
- {
- case '1':
- color1 = 1;
- break;
- case '2':
- color1 = 2;
- break;
- case 27: case 'q':
- exit(0);
- break;
- }
- }
- void main(int argc, char** argv)
- {
- glutInit(&argc, argv);
- glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE );
- glutInitWindowSize(600, 600);
- glutCreateWindow("Program_1");
- InitGL();
- float pos[4] = { 1.50F, 3.50F, 0.25F, 0.00F };
- float dir[3] = {-1, -1, -1};
- glEnable(GL_COLOR_MATERIAL);
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
- glLightfv(GL_LIGHT0, GL_POSITION, pos);
- glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, dir);
- glutReshapeFunc(reshape);
- glutDisplayFunc(displayCallBack);
- glutMainLoop();
- glutIdleFunc(Idle);
- glutMainLoop();
- float pos[4] = {0.90F, 0.90F, 2.25F, 0.00F};
- glutKeyboardFunc(Keyboard);
- glutIdleFunc(Idle);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement