Advertisement
Guest User

Untitled

a guest
May 30th, 2012
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.09 KB | None | 0 0
  1. #include <GL/gl.h>
  2. #include <GL/glu.h>
  3. #include <GL/glut.h>
  4. #include <string.h>
  5. //g++ main.cpp -lGL -lglut -lGLU
  6. using namespace std;
  7.  
  8. float droll=0; //Yes, badly named, I know.
  9. float dpitch=0;
  10. int KeyDown[256];
  11.  
  12. void init(void) {
  13.   glClearColor (0.0, 0.0, 0.0, 0.0);
  14.   glShadeModel (GL_FLAT);
  15. }
  16.  
  17. void display(void) {
  18. /* Check this stuff out, yo.
  19. http://gamedev.stackexchange.com/questions/12885/help-understanding-glulookat
  20. WhatisthisIdon'teven.*/
  21.   glClear (GL_COLOR_BUFFER_BIT);
  22.   glColor3f (1.0, 1.0, 1.0);
  23.   glLoadIdentity ();             /* clear the matrix */
  24.           /* viewing transformation  */
  25.   gluLookAt (0.0, 0.0, 6.0, 0.0, 0.0+dpitch, 0.0+droll, 0.0, 1.0, 0.0);
  26.   glScalef (1.0, 1.0, 1.0);      /* modeling transformation */
  27.   glutWireCube (1.0);
  28.   glFlush ();
  29. }
  30. void reshape (int w, int h) {
  31.   glViewport (0, 0, (GLsizei) w, (GLsizei) h);
  32.   glMatrixMode (GL_PROJECTION);
  33.   glLoadIdentity ();
  34.   glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 200.0);
  35.   glMatrixMode (GL_MODELVIEW);
  36. }
  37.  
  38. void mousefunc(int button,int state,int x,int y) {
  39.   switch(button) {
  40.     case GLUT_LEFT_BUTTON:
  41.       glutPostRedisplay();
  42.       break;
  43.     case GLUT_RIGHT_BUTTON:
  44.       glutPostRedisplay();
  45.       break;
  46.   }
  47. }
  48. void keyboardfunc(unsigned char key,int x,int y) {
  49.   KeyDown[key]=1;
  50. }
  51. void keyboardUpfunc(unsigned char key,int x,int y) {
  52.   KeyDown[key]=0;
  53. }
  54. void idlefunc() {
  55.   if(KeyDown['a']) {
  56.     droll-=0.01;
  57.   }
  58.   else if(KeyDown['d']) {
  59.     droll+=0.01;
  60.   }
  61.   else if(KeyDown['s']) {
  62.     dpitch-=0.01;
  63.   }
  64.   else if(KeyDown['w']) {
  65.     dpitch+=0.01;
  66.   }
  67.   glutPostRedisplay();
  68. }
  69.  
  70. int main(int argc, char** argv) {
  71.   glutInit(&argc, argv);
  72.   glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  73.   glutInitWindowSize(500, 500);
  74.   glutInitWindowPosition(100, 100);
  75.   glutCreateWindow(argv[0]);
  76.   init();
  77.  
  78.   glutDisplayFunc(display);
  79.   glutReshapeFunc(reshape);
  80.  
  81.   memset(KeyDown,0,sizeof(KeyDown));
  82.   glutMouseFunc(mousefunc);
  83.   glutKeyboardFunc(keyboardfunc);
  84.   glutKeyboardUpFunc(keyboardUpfunc);
  85.   glutIdleFunc(idlefunc);
  86.   glutMainLoop();
  87.   return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement