void image_file::load_bmp( const string256& str ) { bmp_header head; file bmp_file(str); CRAP_ASSERT_DEBUG( bmp_file.readable(), "BMP File does not exist or is not readable" ); bmp_file.read_bytes( &head, sizeof(head) ); CRAP_ASSERT_DEBUG( head.validate(), "Not a valid BMP-file" ); if( head.size_of_image == 0 ) head.size_of_image = head.width * head.height * 3; // 3 = RGB if( head.offset == 0 ) head.offset = 54; //default u8* dat = new u8[ head.size_of_image ]; bmp_file.read_bytes( dat, head.size_of_image ); bmp_file.close(); _dimension.x = head.width; _dimension.y = head.height; _format = GL_RGB; _bpp = 24; _size = head.width * head.height * 3; _data = dat; }
void save() { float width = Global_Max.getCoordinateX()*100; float height = Global_Max.getCoordinateY()*100; bmp_file((GLint)width, (GLint)height); return; }
static void key_callback(unsigned char key, int x, int y) { switch(key) { case 'q': //按下q键退出程序 exit(0); break; case 's': bmp_file(WIDTH, HEIGHT); break; default: break; } glutPostRedisplay(); /* this redraws the scene without waiting for the display callback so that any changes appear instantly */ }