Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.55 KB | None | 0 0
  1. #include <GL/glut.h>
  2. #include <GL/freeglut.h>
  3. #include <GL/glu.h>
  4.  
  5.  
  6. #define window_width  640
  7. #define window_height 480
  8.  
  9. // Main loop
  10. void main_loop_function()
  11. {
  12.    // Z angle
  13.    static float angle;
  14.    // Clear color (screen)
  15.    // And depth (used internally to block obstructed objects)
  16.    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  17.    // Load identity matrix
  18.    glLoadIdentity();
  19.    // Multiply in translation matrix
  20.    glTranslatef(0,0, -10);
  21.    // Multiply in rotation matrix
  22.    glRotatef(angle, 0, 0, 1);
  23.    // Render colored quad
  24.    glBegin(GL_QUADS);
  25.    glColor3ub(255, 000, 000); glVertex2f(-1,  1);
  26.    glColor3ub(000, 255, 000); glVertex2f( 1,  1);
  27.    glColor3ub(000, 000, 255); glVertex2f( 1, -1);
  28.    glColor3ub(255, 255, 000); glVertex2f(-1, -1);
  29.    glEnd();
  30.    // Swap buffers (color buffers, makes previous render visible)
  31.     glutSwapBuffers();
  32.    // Increase angle to rotate
  33.    angle+=0.25;
  34. }
  35.  
  36. // Initialze OpenGL perspective matrix
  37. void GL_Setup(int width, int height)
  38. {
  39.  
  40.     glViewport( 0, 0, width, height );
  41.     glMatrixMode( GL_PROJECTION );
  42.     glEnable( GL_DEPTH_TEST );
  43.     gluPerspective( 45, (float)width/height, .1, 100 );
  44.     glMatrixMode( GL_MODELVIEW );
  45. }
  46.  
  47.  
  48. // Initialize GLUT and start main loop
  49. int main(int argc, char** argv) {
  50.     glutInit(&argc, argv);
  51.  
  52.     glutInitWindowSize(window_width, window_height);
  53.  
  54.     glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
  55.  
  56.     glutCreateWindow("GLUT Example!!!");
  57.  
  58.     glutIdleFunc(main_loop_function);
  59.  
  60.     GL_Setup(window_width, window_height);
  61.    glutMainLoop();
  62.     return 0;
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement