SHARE
TWEET

Some Basic GLUT

TheCodingUniverse Dec 18th, 2011 5,742 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top