[OpenGL] 获取画布背景的位图数据
2017-04-01 18:11
459 查看
用OpenGL绘制好画面后 可以将画面数据保存成位图
本文给出一个获取位图数据的函数:
本文给出一个获取位图数据的函数:
// get data of canvas rendered with OpenGL // note : need to call delete[] for *pData bool CaptureOpenGL(int& nWidth, int& nHeight, int& nPitch, BYTE** pData) { static GLenum s_Format = GL_BGRA_EXT; static int s_nBytePerPixel = 4; // 4Byte : because pixel format is GL_BGRA_EXT nWidth = nHeight = nPitch = 0; *pData = NULL; GLint aViewport[4]; glGetIntegerv(GL_VIEWPORT, aViewport); int width = aViewport[2]; int height = aViewport[3]; if ((width * height) <= 0) return false; int pitch = width * s_nBytePerPixel; int len = pitch * height; BYTE* pBuffer = new BYTE[len]; if (!pBuffer) return false; glPixelStorei(GL_PACK_ALIGNMENT, 1); glPixelStorei(GL_PACK_ROW_LENGTH, 0); glPixelStorei(GL_PACK_SKIP_ROWS, 0); glPixelStorei(GL_PACK_SKIP_PIXELS, 0); GLenum lastBuffer; glGetIntegerv(GL_READ_BUFFER, (GLint*)&lastBuffer); glReadBuffer(GL_FRONT); glReadPixels(0, 0, width, height, s_Format, GL_UNSIGNED_BYTE, pBuffer); glReadBuffer(lastBuffer); // reset value of alpha channel with 255. because sometimes the value is 0, such as CS1.6 CWindowTool::ResetAlpha(pBuffer, len, 255); // this function should be completed by yourself nWidth = width; nHeight = height; nPitch = pitch; *pData = pBuffer; return true; }
相关文章推荐
- 同样指令bmp.LockBits不同平台(Windows/WinCE)获取位图的数据不同
- GetObject 和 GetBitmapBits 获取位图数据的区别
- Python数据可视化Matplotlib——Figure画布背景设置
- 获取opengl中2D图片资源数据
- WINCE下由HBITMAP获取位图RGB颜色数据
- 同样指令bmp.LockBits不同平台(Windows/WinCE)获取位图的数据不同
- 获取单色位图指定坐标的数据
- Bitmap类中getPixels()方法介绍--获取位图的数据
- 通过GetCurrentObject和GetObject获取和hdc相关的位图对象数据区起始地址
- 同样指令bmp.LockBits不同平台(Windows/WinCE)获取位图的数据不同
- android opengl 获取bitmap 数据
- 同样指令bmp.LockBits不同平台(Windows/WinCE)获取位图的数据不同
- 同样指令bmp.LockBits不同平台(Windows/WinCE)获取位图的数据不同
- 同样指令bmp.LockBits不同平台(Windows/WinCE)获取位图的数据不同
- 关于OpenNI2和OpenCV2的那些事——获取三维点云数据并用OpenGL表示
- 根据BITMAPINFO获取位图数据
- ajax返回的数据 用easyui的datagrid的表格来循环显示,用灰色背景的是隐藏的列。点击可以获取到隐藏的值
- 从高维数据中获取低维结构——背景总…
- 如何连接MDB数据,并且获取相关的数据
- 获取datable中某行某列的数据