2012年7月17日 星期二

GLUT

#include "windows.h"
#include "GL/glut.h"
#include "stdlib.h"
#include "NeoBmp.H"
NeoBmp image;
float px=0,py=0;
void keyboard(unsigned char key, int x, int y )
{
  switch( key )
  {
    case 'd':
     px += .01;
     glutPostRedisplay();
     break;
    case 'a':
     px -= .01;
     glutPostRedisplay();
     break;
    case 'w':
     py += .01;
     glutPostRedisplay();
     break;
    case 's':
     py -= .01;
     glutPostRedisplay();
     break;
    case 27:
     exit(0);
  }
}
void display()
{
  glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  glRasterPos2f( -image.width/640.0+px, -image.height/640.0+py );
  glDrawPixels( image.width, image.height, GL_RGB, GL_UNSIGNED_BYTE, image.rgb );
  glutSwapBuffers();
}

int main()
{
  glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGB );
  glutInitWindowSize( 640, 640 );
  glutCreateWindow( "Slut Test" );
  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  glutDisplayFunc(display);
  glutKeyboardFunc(keyboard);
  image.load( "test.bmp" );
  glutMainLoop();

  return 0;
}

沒有留言:

張貼留言