Advertisement
Guest User

GLUT Test

a guest
Sep 24th, 2012
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.65 KB | None | 0 0
  1. #include <windows.h>
  2. #include <GL/freeglut.h>
  3. #include <GL/freeglut_ext.h>
  4. #include <GL/freeglut_std.h>
  5. #include <iostream>
  6. #include <stdlib.h>
  7.  
  8. void renderScene(void);
  9.  
  10. void keyboard(unsigned char c, int x, int y);
  11.  
  12. double posX = 50;
  13. double posY = 50;
  14.  
  15. double speedX = 5;
  16. double speedY = 5;
  17.  
  18.  
  19.  
  20. int main(int argc, char *argv[])
  21. {
  22.     //Init GLUT and create window
  23.     glutInit(&argc, argv);
  24.     glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
  25.     glutInitWindowPosition(100,100);
  26.     glutInitWindowSize(800,600);
  27.     glutCreateWindow("GLUT Test");
  28.  
  29.     gluOrtho2D(0,800,0,600);
  30.  
  31.     //register callbacks
  32.     glutDisplayFunc(renderScene);
  33.     //Main draw loop when window is not resized
  34.     glutIdleFunc(renderScene);
  35.     //Keyboard input
  36.     glutKeyboardFunc(keyboard);
  37.  
  38.  
  39.     //enter GLUT event processing cycle
  40.     glutMainLoop();
  41.  
  42.     return 0;
  43. }
  44.  
  45. void keyboard(unsigned char c, int x, int y)
  46. {
  47.     if(c == 'w')
  48.         posY += speedY;
  49.     if(c == 'a')
  50.         posX -= speedX;
  51.     if(c == 's')
  52.         posY -= speedY;
  53.     if(c == 'd')
  54.         posX += speedX;
  55. }
  56.  
  57.  
  58. void renderScene()
  59. {
  60.     //std::cout << "updating" << std::endl;
  61.  
  62.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  63.  
  64.     //x += .01;
  65.     std::cout << posX;
  66.     std::cout << " , ";
  67.     std::cout << posY << std::endl;
  68.  
  69.  
  70.     glColor4f(0,.5,0,1);
  71.     glBegin(GL_QUADS);
  72.         glVertex2d(posX, posY);
  73.         glVertex2d(posX, posY + 50);
  74.         glVertex2d(posX + 50, posY + 50);
  75.         glVertex2d(posX + 50, posY);
  76.     glEnd();
  77.  
  78.     glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, (const unsigned char*)'t');
  79.  
  80.     glutSwapBuffers();
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement