Advertisement
Guest User

Untitled

a guest
Jul 18th, 2012
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. #include <GL/glut.h>
  2.  
  3. void init();
  4. void display();
  5. void reshape(int w,int h);
  6.  
  7. int main(){
  8.     glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
  9.     glutInitWindowPosition(100,100);
  10.     glutInitWindowSize(500,500);
  11.     glutCreateWindow("test");
  12.     init();
  13.     glutReshapeFunc(reshape);
  14.     glutDisplayFunc(display);
  15.     glutIdleFunc(display);
  16.  
  17.     glutMainLoop();
  18.  
  19.     return 0;
  20. }
  21.  
  22. void init(){
  23.     glClearColor (0.0, 0.90, 1.0, 0.0);
  24. }
  25.  
  26. void reshape(int w, int h){
  27.     glMatrixMode(GL_PROJECTION);
  28.     glLoadIdentity();
  29.     glViewport(0,0,w,h);
  30.     gluPerspective(45.0f, w/h, 0.1f, 100.0f);
  31.     glMatrixMode(GL_MODELVIEW);
  32. }
  33.  
  34. void display(){
  35.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  36.     glLoadIdentity();
  37.     glTranslatef(0.0f,0.0f,-6.0f);
  38.     glColor3f(1.0f,0.0f,0.0f);
  39.     glBegin(GL_QUADS);
  40.         glVertex3f( -1.0f, 1.0f, -1.5f);
  41.         glVertex3f( -1.0f, -1.0f, -1.5f);
  42.         glVertex3f( 1.0f, -1.0f, -1.5f);
  43.         glVertex3f( 1.0f, 1.0f, -1.5f);
  44.     glEnd();
  45.     glColor3f(1.0f,1.0f,0.0f);
  46.     glBegin(GL_TRIANGLES);
  47.         glVertex3f( 0.0f, 1.0f, 0.0f);
  48.         glVertex3f( -1.0f, -1.0f, 0.0f);
  49.         glVertex3f( 1.0f, -1.0f, 0.0f);
  50.     glEnd();
  51.  
  52.     glutSwapBuffers();
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement