本节例子将教会你几个方面:
(1)怎样读写opengl图象
(2)怎样拷贝opengl图象
(3)怎样缩放opengl图象
void myImage(){ GLubyte image1[64][64][3]; GLubyte image2[64][64][3]; for(int i = 0; i < 64; i++) for(int j = 0; j < 64; j++) { image1[i][j][0]=(GLubyte)j*3.5; image1[i][j][1]=(GLubyte)i*3.5; image1[i][j][2]=(GLubyte)(255-i*3.5); } glRasterPos3f(-1.2f,0.5f,0.0f);//设置当前光栅的位置 glDrawPixels(64,64,GL_RGB,GL_UNSIGNED_BYTE,image1);//绘制图像 GLint rasPostion[4]; glGetIntegerv(GL_CURRENT_RASTER_POSITION,rasPostion);//获得当前光栅的位置 glReadPixels(rasPostion[0],rasPostion[1],64,64,GL_RGB,GL_UNSIGNED_BYTE,image2); glRasterPos3f(0.6f,0.5f,0.0f); glDrawPixels(64,64,GL_RGB,GL_UNSIGNED_BYTE,image2); glGetIntegerv(GL_CURRENT_RASTER_POSITION,rasPostion); glRasterPos3f(-1.2f,-0.3f,0.0f); glCopyPixels(rasPostion[0],rasPostion[1],64,32,GL_COLOR); glRasterPos3f(0.6f,-0.3f,0.0f); glCopyPixels(rasPostion[0],rasPostion[1],32,32,GL_COLOR); glPixelZoom(2.0f,1.0f);} |