OpenGL于MFC使用汇总(三)——离屏渲染
生活随笔
收集整理的這篇文章主要介紹了
OpenGL于MFC使用汇总(三)——离屏渲染
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
有時直接創(chuàng)建OpenGL形式不適合,或者干脆不同意然后創(chuàng)建一個表單,正如我現(xiàn)在這個項目,創(chuàng)建窗體不顯示,它僅限于主框架。而我只是ActiveX里做一些相關(guān)工作,那僅僅能用到OpenGL的離屏渲染技術(shù)了~即不直接繪制到窗體上,而是繪制到一張位圖上。然后再次調(diào)用這張位圖實現(xiàn)興許的工作。
以下就總結(jié)怎么使用所謂的“離屏渲染”。
const int WIDTH = 500;const int HEIGHT = 500;// Create a memory DC compatible with the screenHDC 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 bitsHBITMAP 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 DCHGDIOBJ r = SelectObject(hdc, hbm);if (r == 0) cout<<"Could not select bitmap into DC";// Choose the pixel formatPIXELFORMATDESCRIPTOR pfd = {sizeof (PIXELFORMATDESCRIPTOR), // struct size1, // Version numberPFD_DRAW_TO_BITMAP | PFD_SUPPORT_OPENGL, // use OpenGL drawing to BMPFD_TYPE_RGBA, // RGBA pixel values32, // color bits0, 0, 0, // RGB bits shift sizes...0, 0, 0, // Don't care about them0, 0, // No alpha buffer info0, 0, 0, 0, 0, // No accumulation buffer32, // depth buffer bits0, // No stencil buffer0, // No auxiliary buffersPFD_MAIN_PLANE, // Layer type0, // Reserved (must be 0)0, // No layer mask0, // No visible mask0, // 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 DCBOOL b = SetPixelFormat(hdc, pfid, &pfd);if (!b) cout<<"Pixel format set failed";// Create the OpenGL resource context (RC) and make it current to the threadHGLRC hglrc = wglCreateContext(hdc);if (hglrc == 0) cout<<"OpenGL resource context creation failed";wglMakeCurrent(hdc, hglrc);// Draw using GL - remember to sync with GdiFlush()GdiFlush();/*詳細的繪制函數(shù)~~~~~~~~~~~~~~我就不寫了*/// Clean upwglDeleteContext(hglrc); // Delete RCSelectObject(hdc, r); // Remove bitmap from DCDeleteObject(hbm); // Delete bitmapDeleteDC(hdc); // Delete DC
版權(quán)聲明:本文博客原創(chuàng)文章。博客,未經(jīng)同意,不得轉(zhuǎn)載。
轉(zhuǎn)載于:https://www.cnblogs.com/bhlsheji/p/4713200.html
總結(jié)
以上是生活随笔為你收集整理的OpenGL于MFC使用汇总(三)——离屏渲染的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: cpc专利电子申请客户端安装教程以及常见
- 下一篇: 关于android中的armeabi、a