Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdarg.h>
- #include <math.h>
- #define GL_GLEXT_PROTOTYPES
- #include <GL/glut.h> gl.h
- double rotate_y=0;
- double rotate_x=0;
- void display ()
- {
- glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
- glLoadIdentity();
- glRotatef( rotate_x, 1.0, 0.0, 0.0 );
- glRotatef( rotate_y, 0.0, 1.0, 0.0 );
- glBegin(GL_QUADS);
- glColor3f(1.0,0.0,1.0);
- glVertex3f(0.2, 0.0, -0.5);
- glVertex3f(1.0, 0.0, -0.5);
- glVertex3f(1.0, 0.2, -0.5);
- glVertex3f(0.2, 0.2, -0.5);
- glEnd();
- glBegin(GL_QUADS);
- glColor3f(1.0,0.0,1.0);
- glVertex3f(0.0, 0.0, -0.5);
- glVertex3f(0.2, 0.0, -0.5);
- glVertex3f(0.2, 1.0, -0.5);
- glVertex3f(0.0, 1.0, -0.5);
- glEnd();
- glBegin(GL_QUADS);
- glColor3f(1.0,0.0,1.0);
- glVertex3f(0.2, 0.0, 0.0);
- glVertex3f(1.0, 0.0, 0.0);
- glVertex3f(1.0, 0.2, 0.0);
- glVertex3f(0.2, 0.2, 0.0);
- glEnd();
- glBegin(GL_QUADS);
- glColor3f(1.0,0.0,1.0);
- glVertex3f(0.0, 0.0, 0.0);
- glVertex3f(0.2, 0.0, 0.0);
- glVertex3f(0.2, 1.0, 0.0);
- glVertex3f(0.0, 1.0, 0.0);
- glEnd();
- glBegin(GL_QUADS);
- glColor3f(1.0,0.0,1.0);
- glVertex3f(0.2, 1.0, 0.0);
- glVertex3f(0.0, 1.0, 0.0);
- glVertex3f(0.0, 1.0, -0.5);
- glVertex3f(0.2, 1.0, -0.5);
- glEnd();
- glBegin(GL_QUADS);
- glColor3f(1.0,0.0,1.0);
- glVertex3f(0.0, 0.0, 0.0);
- glVertex3f(0.2, 0.0, 0.0);
- glVertex3f(0.2, 0.0, -0.5);
- glVertex3f(0.0, 0.0, -0.5);
- glEnd();
- glBegin(GL_QUADS);
- glColor3f(1.0,0.0,1.0);
- glVertex3f(0.2, 0.2, 0.0);
- glVertex3f(1.0, 0.2, 0.0);
- glVertex3f(1.0, 0.2, -0.5);
- glVertex3f(0.2, 0.2, -0.5);
- glEnd();
- glBegin(GL_QUADS);
- glColor3f(1.0,0.0,1.0);
- glVertex3f(0.2, 0.0, 0.0);
- glVertex3f(1.0, 0.0, 0.0);
- glVertex3f(1.0, 0.0, -0.5);
- glVertex3f(0.2, 0.0, -0.5);
- glEnd();
- glBegin(GL_QUADS);
- glColor3f(1.0,0.0,1.0);
- glVertex3f(1.0, 0.2, 0.0);
- glVertex3f(1.0, 0.0, 0.0);
- glVertex3f(1.0, 0.0, -0.5);
- glVertex3f(1.0, 0.2, -0.5);
- glEnd();
- glBegin(GL_QUADS);
- glColor3f(1.0,0.0,1.0);
- glVertex3f(0.0, 0.0, 0.0);
- glVertex3f(0.0, 1.0, 0.0);
- glVertex3f(0.0, 1.0, -0.5);
- glVertex3f(0.0, 0.0, -0.5);
- glEnd();
- glFlush();
- glutSwapBuffers();
- }
- void init(void)
- {
- glClearColor(0,0,0,0);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluOrtho2D(-320, 319,-240, 239);
- glClear(GL_COLOR_BUFFER_BIT);
- glFlush();
- }
- void keys( int key, int x, int y )
- {
- if(key==GLUT_KEY_RIGHT)
- {
- rotate_y=rotate_y+5;
- }
- if(key==GLUT_KEY_LEFT)
- {
- rotate_y=rotate_y-5;
- }
- if(key==GLUT_KEY_UP)
- {
- rotate_x=rotate_x+5;
- }
- if(key==GLUT_KEY_DOWN)
- {
- rotate_x=rotate_x-5;
- }
- glutPostRedisplay();
- }
- void reshape(GLsizei width, GLsizei height)
- {
- if (height == 0)
- height = 1;
- GLfloat aspect = (GLfloat)width / (GLfloat)height;
- glViewport(0, 0, width, height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- if (width >= height)
- {
- gluOrtho2D(-1.0 * aspect, 1.0 * aspect, -1.0, 1.0);
- }
- else
- {
- gluOrtho2D(-1.0, 1.0, -1.0 / aspect, 1.0 / aspect);
- }
- }
- void keyboard(unsigned char key, int x, int y) {
- }
- int main(int argc, char* argv[])
- {
- glutInit(&argc,argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
- glutCreateWindow("Rotating Letter L");
- glEnable(GL_DEPTH_TEST);
- glutDisplayFunc(display);
- glutReshapeFunc(reshape);
- glutSpecialFunc(keys);
- glutKeyboardFunc(keyboard);
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment