OpenGL在MFC中的使用总结(三)——离屏渲染
来源:互联网 发布:钢结构楼梯踏步计算法 编辑:程序博客网 时间:2024/06/04 19:53
有些时候直接创建OpenGL窗口不适合,或者根本不允许再创建窗口,就像我现在的这个项目,创建的窗口显示不出来,被主框架限定,而我只能在ActiveX控件的子类里做一些相关工作,那只能用到OpenGL的离屏渲染技术了~即不直接绘制到窗口上,而是绘制到一张位图上,然后再次调用这张位图实现后续的工作。
下面就总结怎么使用所谓的“离屏渲染”。
const int WIDTH = 500; const int HEIGHT = 500; // Create a memory DC compatible with the screen HDC hdc = CreateCompatibleDC(0); if (hdc == 0) cout<<"Could not create memory device context"; // Create a bitmap compatible with the DC // must use CreateDIBSection(), and this means all pixel ops must be synchronised // using calls to GdiFlush() (see CreateDIBSection() docs) BITMAPINFO bmi = { { sizeof(BITMAPINFOHEADER), WIDTH, HEIGHT, 1, 32, BI_RGB, 0, 0, 0, 0, 0 }, { 0 } }; unsigned char *pbits; // pointer to bitmap bits HBITMAP hbm = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void **) &pbits, 0, 0); if (hbm == 0) cout<<"Could not create bitmap"; //HDC hdcScreen = GetDC(0); //HBITMAP hbm = CreateCompatibleBitmap(hdcScreen,WIDTH,HEIGHT); // Select the bitmap into the DC HGDIOBJ r = SelectObject(hdc, hbm); if (r == 0) cout<<"Could not select bitmap into DC"; // Choose the pixel format PIXELFORMATDESCRIPTOR pfd = { sizeof (PIXELFORMATDESCRIPTOR), // struct size 1, // Version number PFD_DRAW_TO_BITMAP | PFD_SUPPORT_OPENGL, // use OpenGL drawing to BM PFD_TYPE_RGBA, // RGBA pixel values 32, // color bits 0, 0, 0, // RGB bits shift sizes... 0, 0, 0, // Don't care about them 0, 0, // No alpha buffer info 0, 0, 0, 0, 0, // No accumulation buffer 32, // depth buffer bits 0, // No stencil buffer 0, // No auxiliary buffers PFD_MAIN_PLANE, // Layer type 0, // Reserved (must be 0) 0, // No layer mask 0, // No visible mask 0, // No damage mask }; int pfid = ChoosePixelFormat(hdc, &pfd); if (pfid == 0) cout<<"Pixel format selection failed"; // Set the pixel format // - must be done *after* the bitmap is selected into DC BOOL b = SetPixelFormat(hdc, pfid, &pfd); if (!b) cout<<"Pixel format set failed"; // Create the OpenGL resource context (RC) and make it current to the thread HGLRC hglrc = wglCreateContext(hdc); if (hglrc == 0) cout<<"OpenGL resource context creation failed"; wglMakeCurrent(hdc, hglrc); // Draw using GL - remember to sync with GdiFlush() GdiFlush(); /*具体的绘制函数~~~~~~~~~~~~~~我就不写了 */ // Clean up wglDeleteContext(hglrc); // Delete RC SelectObject(hdc, r); // Remove bitmap from DC DeleteObject(hbm); // Delete bitmap DeleteDC(hdc); // Delete DC
1 1
- OpenGL在MFC中的使用总结(三)——离屏渲染
- OpenGL在MFC中的使用总结(二)——派生的OpenGL类
- OpenGL在MFC中的使用总结(一)——基本框架
- Opengl(三)——渲染出一个三角形
- opengl使用FBO离屏渲染图片
- OpenGL在MFC中的实现
- OpenGL在MFC中的实现
- 在MFC中使用OpenGL相关配置的整理总结
- OpenGL离屏渲染
- opengl离屏渲染
- 在MFC中的picture control 中使用opengl作图
- OpenGL—渲染管线
- OpenGL—渲染管线
- 在Android中使用OpenGL效果渲染
- opengl在linux上进行离屏渲染
- 在Android中的jni里使用OpenGL ES 渲染一幅图片
- OpenGL渲染管线总结
- OpenGL渲染管线总结
- 程序更新后tomcat内存持续增长原因分析
- 20140822 【 优先队列 】 POJ 3253 Fence Repair
- Web GIS访问ArcGIS安全认证服务代理配置解决方案-Java版本
- 四十岁的男人
- 多线程中的线程同步
- OpenGL在MFC中的使用总结(三)——离屏渲染
- 更新Xcode是其他人的appleID怎么办?怎么使用新的appleID更新Xcode
- extern "C"编译指令
- CentOS6.5下安装flash player插件
- mysql授权+限制连接
- Linux常用命令大全
- 数据结构上机实验之二分查找(哈希优化)
- iOS开发 - UIActivityViewController详解
- Rotate List Java