Advertisement
TheCodingUniverse

Some Basic GLUT

Dec 18th, 2011
7,873
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. #include <GLUT/GLUT.h>
  2. #include <iostream>
  3.  
  4. void render(void);
  5.  
  6. void keyboard(unsigned char c, int x, int y);
  7.  
  8. void mouse(int button, int state, int x, int y);
  9.  
  10. int main(int argc, char** argv) {
  11.     glutInit(&argc, argv);
  12.     glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
  13.     glutInitWindowPosition(100, 100);
  14.     glutInitWindowSize(640, 480);
  15.     glutCreateWindow("Simple GLUT Application");
  16.  
  17.     glutDisplayFunc(render);   
  18.     glutKeyboardFunc(keyboard);
  19.     glutMouseFunc(mouse);
  20.  
  21.     glutMainLoop();
  22. }
  23.  
  24. void keyboard(unsigned char c, int x, int y) {
  25.     if (c == 27) {
  26.         exit(0);
  27.     }
  28. }
  29.  
  30. void mouse(int button, int state, int x, int y) {
  31.     if (button == GLUT_RIGHT_BUTTON) {
  32.         exit(0);
  33.     }
  34. }
  35.  
  36. void render(void) {
  37.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  38.  
  39.     glBegin(GL_TRIANGLES);
  40.         glColor3f(1, 0, 0);
  41.         glVertex2f(-0.5, -0.5);
  42.         glColor3f(0, 1, 0);
  43.         glVertex2f(0.5, -0.5);
  44.         glColor3f(0, 0, 1);
  45.         glVertex2f(0.0, 0.5);
  46.     glEnd();
  47.  
  48.     glutSwapBuffers();
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement