Advertisement
metalx1000

Very basic OpenGL Window - Draw Square

Dec 8th, 2012
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.97 KB | None | 0 0
  1. #sudo aptitude install libghc-glut-dev
  2. #gcc main.c -o main -lglut -lGLU -lGL
  3.  
  4. #include <stdio.h>
  5. #include <GL/glut.h>
  6. void display(void)
  7. {
  8.  glClear( GL_COLOR_BUFFER_BIT);
  9.  glColor3f(0.0, 1.0, 0.0);
  10.  glBegin(GL_POLYGON);
  11.   glVertex3f(2.0, 4.0, 0.0);
  12.   glVertex3f(8.0, 4.0, 0.0);
  13.   glVertex3f(8.0, 6.0, 0.0);
  14.   glVertex3f(2.0, 6.0, 0.0);
  15.  glEnd();
  16.  glFlush();
  17. }
  18.  
  19. int main(int argc, char **argv)
  20. {
  21.  printf("hello world\n");
  22.  glutInit(&argc, argv);
  23.  glutInitDisplayMode ( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
  24.  
  25.  glutInitWindowPosition(100,100);
  26.  glutInitWindowSize(300,300);
  27.  glutCreateWindow ("square");
  28.  
  29.  glClearColor(0.0, 0.0, 0.0, 0.0);         // black background
  30.  glMatrixMode(GL_PROJECTION);              // setup viewing projection
  31.  glLoadIdentity();                           // start with identity matrix
  32.  glOrtho(0.0, 10.0, 0.0, 10.0, -1.0, 1.0);   // setup a 10x10x2 viewing world
  33.  
  34.  glutDisplayFunc(display);
  35.  glutMainLoop();
  36.  
  37.  return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement