先来段代码吧;
#include <iostream> #include <gl/glut.h> using namespace std; #pragma comment(lib,"opengl32.lib") #pragma comment(lib,"glut32.lib") #pragma comment(lib,"glu32.lib") GLubyte rasters[24]={ 0xc0,0x00,0xc0,0x00,0xc0,0x00,0xc0,0x00, 0xc0,0x00,0xff,0x00,0xff,0x00,0xc0,0x00, 0xc0,0x00,0xc0,0x00,0xff,0xc0,0xff,0xc0 }; void init() { glClearColor(0.0,0.0,0.0,0.0); glShadeModel(GL_FLAT); glPixelStorei(GL_UNPACK_ALIGNMENT,1); } void display() { glClear(GL_COLOR_BUFFER_BIT); GLfloat colors[]={1.0,1.0,0.0}; glColor3fv(colors); glRasterPos2i(0,0); glBitmap(10,12,0.0,0.0,11.0,0.0,rasters); glBitmap(10,12,0.0,0.0,11.0,0.0,rasters); glBitmap(10,12,0.0,0.0,11.0,0.0,rasters); glFlush(); } void reshape(int w,int h) { glViewport(0,0,(GLsizei)w,(GLsizei)h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0,(GLdouble)w,0.0,(GLdouble)h);//left right,buttom,up (left,buttom),(right,up) glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } int main(int argc,char** argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE); glutInitWindowSize(500,500); glutInitWindowPosition(100,100); glutCreateWindow(argv[0]); init(); glutDisplayFunc(display); glutReshapeFunc(reshape); glutMainLoop(); return 0; }
显示结果:
位图的绘制就是上面的代码。是不是很简单。。