VBO的像素操作,绘制24位位图
来源:互联网 发布:怎样提高淘宝店信誉度 编辑:程序博客网 时间:2024/05/22 01:51
#include <stdio.h>#include <stdlib.h>#include <assert.h>#include <fstream>#include <string>#include <gl/glew.h>#include <GL/glut.h>#pragma comment(lib,"glew32.lib")#pragma comment(lib,"glut32.lib")using namespace std;/*Create checkerboard image*/#definecheckImageWidth 64#definecheckImageHeight 64GLubyte checkImage[checkImageHeight][checkImageWidth][3];static GLdouble zoomFactor = 1.0;//static GLint height;void makeCheckImage(void){int i, j, c;for (i = 0; i < checkImageHeight; i++) {for (j = 0; j < checkImageWidth; j++) {c = ((((i&0x8)==0)^((j&0x8))==0))*255;checkImage[i][j][0] = (GLubyte) c;checkImage[i][j][1] = (GLubyte) c;checkImage[i][j][2] = (GLubyte) c;}}}static GLuint unpackBuffer = 0;static int width=0, height = 0, totals=0;void readBitmp24(const std::string& filename, void* &ptr){fstream in(filename.c_str(), ios_base::in|ios_base::binary);if (!in){ptr = NULL;return;}//int width=0, height = 0;in.seekg(0x12); //18个字节开始读取宽度和高度in.read((char*)&width, sizeof(int));in.read((char*)&height,sizeof(int));//BMP的每行按照4个字节对齐int lineLength = width*3;while (lineLength % 4 != 0)++lineLength;totals = lineLength * height;ptr = malloc(totals);in.seekg(0x36); //54开始是数据,按照行读取in.read((char*)ptr, totals);in.close();}void init(void){ glClearColor (0.0, 0.0, 0.0, 0.0);glShadeModel(GL_FLAT);makeCheckImage();//默认按照4个字节对齐//glPixelStorei(GL_UNPACK_ALIGNMENT, 4);void* ptrData = NULL;readBitmp24(std::string("e:/test.bmp"), ptrData);glewInit();glGenBuffers(1,&unpackBuffer);assert(unpackBuffer != 0);glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer);glBufferData(GL_PIXEL_UNPACK_BUFFER,totals, ptrData,GL_STATIC_DRAW);glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);free(ptrData);}void display(void){glClear(GL_COLOR_BUFFER_BIT);glRasterPos2i(0, 0);glBindBuffer(GL_PIXEL_UNPACK_BUFFER, unpackBuffer);//glPixelZoom(4,4);glDrawPixels(width, height, GL_BGR_EXT, GL_UNSIGNED_BYTE, 0);glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);glFlush();}void reshape(int w, int h){glViewport(0, 0, (GLsizei) w, (GLsizei) h);//height = (GLint) h;glMatrixMode(GL_PROJECTION);glLoadIdentity();gluOrtho2D(0.0, (GLdouble) w, 0.0, (GLdouble) h);glMatrixMode(GL_MODELVIEW);glLoadIdentity();}void motion(int x, int y){//static GLint screeny;//screeny = height - (GLint) y;//glRasterPos2i (x, screeny);//glPixelZoom (zoomFactor, zoomFactor);//glCopyPixels (0, 0, checkImageWidth, checkImageHeight, GL_COLOR);//glPixelZoom (1.0, 1.0);//glFlush ();}void keyboard(unsigned char key, int x, int y){switch (key) {case 'r':case 'R':zoomFactor = 1.0;glutPostRedisplay();printf ("zoomFactor reset to 1.0\n");break;case 'z':zoomFactor += 0.5;if (zoomFactor >= 3.0) zoomFactor = 3.0;printf ("zoomFactor is now %4.1f\n", zoomFactor);break;case 'Z':zoomFactor -= 0.5;if (zoomFactor <= 0.5) zoomFactor = 0.5;printf ("zoomFactor is now %4.1f\n", zoomFactor);break;case 27:exit(0);break;default:break;}}int main(int argc, char** argv){glutInit(&argc, argv);glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);glutInitWindowSize(600, 600);glutInitWindowPosition(100, 100);glutCreateWindow(argv[0]);init();glutDisplayFunc(display);glutReshapeFunc(reshape);glutKeyboardFunc(keyboard);glutMotionFunc(motion);glutMainLoop();return 0; }
运行效果
- VBO的像素操作,绘制24位位图
- 32BPP窗口模式下24位位图的像素操作(1)
- 32BPP窗口模式下24位位图的像素操作(2)
- glReadPixels glDrawPixels glCopyPixels与VBO结合 使用24位的位图
- 位图和像素位
- 位图和像素位
- bmp位图和OpenGL的像素操作
- 位图像素的颜色
- OGL绘制像素数据之位图字体
- 位图的像素操作练习(2012-05-25)
- opencv2.x中32位图像的像素级操作
- 32位位图到24位位图的转换
- 8位位图和24位位图的相互转换
- 32位位图到24位位图的转换
- BMP的8位位图转换24位位图
- OpenGL下的VBO的图形绘制
- 绘制位图的问题
- 透明位图的绘制
- ecshop --在php_gd2库安装后还是显示不支持jpeg格式解决办法
- Hadoop源码分析之心跳机制<转>
- 【2002 计算球体积】
- Session、Dialog和Transaction的区别
- 全球移动通信系统GSM学习
- VBO的像素操作,绘制24位位图
- Tizen
- 理解会话
- Web开发人员速查卡
- js的数组
- SIP结构
- SIP代理服务器(1)
- asp.net 缓存总结
- XML学习日记