Copyright1993-2010NVIDIACorporation.Allrightsreserved.NVIDIACorporationanditslicensorsretainallintellectualpropertyandproprietaryrightsinandtothissoftwareandrelateddocumentation.Anyuse,reproduction,disclosure,ordistributionofthissoftwareandrelateddocumentationwithoutanexpresslicenseagreementfromNVIDIACorporationisstrictlyprohibited.PleaserefertotheapplicableNVIDIAenduserlicenseagreement(EULA)associatedwiththissourcecodefortermsandconditionsthatgovernyouruseofthisNVIDIAsoftware.#ifndef __CPU_BITMAP_H__
#define __CPU_BITMAP_H__
#include "gl_helper.h"
structCPUBitmap{unsignedchar*pixels;intx,y;void*dataBlock;void(*bitmapExit)(void*);CPUBitmap(intwidth,intheight,void*d=NULL){pixels=newunsignedchar[width*height*4];x=width;y=height;dataBlock=d;}~CPUBitmap(){delete[]pixels;}unsignedchar*get_ptr(void)const{returnpixels;}//返回指向位图数据的指针
longimage_size(void)const{returnx*y*4;}voiddisplay_and_exit(void(*e)(void*)=NULL){CPUBitmap**bitmap=get_bitmap_ptr();*bitmap=this;bitmapExit=e;// a bug in the Windows GLUT implementation prevents us from
// passing zero arguments to glutInit()
intc=1;char*dummy="";glutInit(&c,&dummy);glutInitDisplayMode(GLUT_SINGLE|GLUT_RGBA);glutInitWindowSize(x,y);glutCreateWindow("bitmap");glutKeyboardFunc(Key);glutDisplayFunc(Draw);glutMainLoop();}// static method used for glut callbacks
staticCPUBitmap**get_bitmap_ptr(void){staticCPUBitmap*gBitmap;return&gBitmap;}// static method used for glut callbacks
staticvoidKey(unsignedcharkey,intx,inty){switch(key){case27:CPUBitmap*bitmap=*(get_bitmap_ptr());if(bitmap->dataBlock!=NULL&&bitmap->bitmapExit!=NULL)bitmap->bitmapExit(bitmap->dataBlock);exit(0);}}// static method used for glut callbacks
staticvoidDraw(void){CPUBitmap*bitmap=*(get_bitmap_ptr());glClearColor(0.0,0.0,0.0,1.0);glClear(GL_COLOR_BUFFER_BIT);glDrawPixels(bitmap->x,bitmap->y,GL_RGBA,GL_UNSIGNED_BYTE,bitmap->pixels);glFlush();}};#endif // __CPU_BITMAP_H__