Guest User

Untitled

a guest
Oct 18th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.98 KB | None | 0 0
  1. #include <GL/glut.h>
  2.  
  3.  
  4. void RenderScene(void) {
  5.     glClear(GL_COLOR_BUFFER_BIT);
  6.     glColor3f(1.0f, 0.0f, 0.0f);
  7.     glRectf(-25.0f, 25.0f, 25.0f, -25.0f);
  8.    
  9.     glFlush();
  10. }
  11.  
  12. void ColorSceneInit(void) {
  13.     glClearColor(0.5f, 0.25f, 1.0f, 0.0f);
  14. }
  15.  
  16. void ResizeWindow(GLsizei w, GLsizei h) {
  17.     GLfloat ratio;
  18.    
  19.     if (h == 0) h = 1;
  20.    
  21.     glViewport(0, 0, w, h);
  22.     glMatrixMode(GL_PROJECTION);
  23.     glLoadIdentity();
  24.     ratio = (GLfloat) w / (GLfloat) h;
  25.     if (w <= h) {
  26.         glOrtho(-100.0, 100.0, -100/ratio, 100.0/ratio, 1.0, -1.0);
  27.     } else {
  28.         glOrtho(-100.0 * ratio, 100.0 * ratio, -100.0, 100.0, 1.0, -1.0);
  29.     }
  30.     glMatrixMode(GL_MODELVIEW);
  31.     glLoadIdentity();
  32. }
  33.  
  34. void main(int argcp, char **argv) {
  35.     glutInit(&argcp, argv);
  36.     glutInitWindowSize(640, 480);
  37.     glutInitWindowPosition(0, 0);
  38.    
  39.     glutCreateWindow("OpenGL Application");
  40.     glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE);
  41.    
  42.     glutDisplayFunc(RenderScene);
  43.     glutReshapeFunc(ResizeWindow);
  44.     ColorSceneInit();
  45.    
  46.     glutMainLoop();
  47. }
Add Comment
Please, Sign In to add comment