分类:
2009-04-21 17:06:01
#include #include /*设置背景色*/ void myInit(void) { glClearColor(1.0,1.0,1.0,1.0); } /*绘制彩色三角形*/ void triangle(void) { glBegin(GL_TRIANGLES); glColor3f(1.0,1.0,0.0); glVertex2f(10.0,10.0); glColor3f(0.0,0.3,1.0); glVertex2f(20.0,30.0); glColor3f(1.0,0.0,0.0); glVertex2f(30.0,10.0); glEnd(); } void myDisplay() { int i; glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glPushMatrix(); glTranslatef(10.0,100.0,0.0); triangle(); glPopMatrix(); glPushMatrix(); for(i = 0;i < 5;i++) { glRasterPos2i(20+i*30,10+i*5);//为像素操作指定光栅位置 glCopyPixels(50,200,500,500,GL_COLOR);//在缓存中拷贝像素 } glPopMatrix(); glFlush(); } void myReshape(int w,int h) { glViewport(0,0,(GLsizei)w,(GLsizei)h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if( w <= h) gluOrtho2D(0.0,150,0.0,150.0*(GLfloat)h/(GLfloat)w); else gluOrtho2D(0.0,150*(GLfloat)w/(GLfloat)h,0.0,150.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } int main(int argc,char ** argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH); glutInitWindowSize(500,400); glutInitWindowPosition(100,100); glutCreateWindow(" copy "); myInit(); glutReshapeFunc(myReshape); glutDisplayFunc(myDisplay); glutMainLoop(); return 0; } |
#include #include /*字母F*/ GLubyte f_rasters[12] = {0xc0,0xc0,0xc0,0xc0,0xc0,0xfc, 0xfc,0xc0,0xc0,0xc0,0xff,0xff}; /*字母I*/ GLubyte i_rasters[12] = {0xff,0xff,0x18,0x18,0x18,0x18, 0x18,0x18,0x18,0x18,0xff,0xff}; /*字母L*/ GLubyte l_rasters[12] = {0xff,0xff,0xc0,0xc0,0xc0,0xc0, 0xc0,0xc0,0xc0,0xc0,0xc0,0xc0}; /*字母E*/ GLubyte e_rasters[12] = {0xff,0xff,0xc0,0xc0,0xc0,0xff, 0xff,0xc0,0xc0,0xc0,0xff,0xff}; void myInit(void) { glPixelStorei(GL_UNPACK_ALIGNMENT,1);//设置像素存储模式 glClearColor(1.0,1.0,1.0,1.0);//设置背景为白色 } void myDisplay() { glClear(GL_COLOR_BUFFER_BIT); glColor3f(0.0,0.0,0.0);//设置像素颜色为黑色 glRasterPos2i(20,20);//为像素指定位置 /*绘制位图*/ glBitmap(8,12,0.0,0.0,14.0,0.0,f_rasters); glBitmap(8,12,0.0,0.0,14.0,0.0,i_rasters); glBitmap(8,12,0.0,0.0,14.0,0.0,l_rasters); glBitmap(8,12,0.0,0.0,14.0,0.0,e_rasters); glFlush(); } void myReshape(int w,int h) { glViewport(0,0,(GLsizei)w,(GLsizei)h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0,w,0,h,-1.0,1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } int main(int argc,char ** argv) { /*初始化*/ glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutInitWindowSize(500,400); glutInitWindowPosition(100,100); /*创建窗口*/ glutCreateWindow(" BitMap"); /*绘制图形*/ myInit(); glutReshapeFunc(myReshape); glutDisplayFunc(myDisplay); glutMainLoop();//进入GLUT事件处理循环 return 0; } |