日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

OpenGL于MFC使用汇总(三)——离屏渲染

發(fā)布時間:2023/12/20 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。