凌晨跪拜求教!如何让openGL和GDI同时显示在form中?

happyili 2004-10-29 03:18:23
大致是这样的。。本来有一个用GDI绘图显示的程序,现在要加入openGL绘制内容。
可是在opengl画完之后一用SwapBuffers好像就把整个窗口擦除了。。
有什么好办法把opengl绘制的内容限制在一个窗口里面呢?难道用memDC+bitmap?
...全文
128 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
lynnboy 2004-10-31
  • 打赏
  • 举报
回复
涉及到GDI的就是这么回事吧。。。
happyili 2004-10-30
  • 打赏
  • 举报
回复
哎,试了半天还是没有成功~
郁闷,用不来啊,memDC

自己再顶一下,期盼着高手再来指点阿~~
zzwu 2004-10-30
  • 打赏
  • 举报
回复
恭喜你取得了成功!


happyili 2004-10-30
  • 打赏
  • 举报
回复
呵呵,弄了半天没想到还真是memdc+bitmap... 分特。。
happyili 2004-10-30
  • 打赏
  • 举报
回复
哈~ 终于搞定了,原来前面在selectobject(bitmap...)之前设置了pixelformat... 真正郁闷阿~
现在的大致是下面这个样子。。

不过还是不懂DIB dc,和在绘时切换RC是什么概念,望多指点拉~~

BITMAPINFO info; /* Bitmap information */
GLubyte *bits; /* Buffer for bitmap data */
HBITMAP bitmap; /* Bitmap */
PIXELFORMATDESCRIPTOR pfd;
// Create the device context...
dc = CreateCompatibleDC(NULL);

// Create and bind the rendering context

//CDC dcMemory;
//dcMemory.CreateCompatibleDC(pDC);

/* Create and bind the bitmap */
memset(&info, 0, sizeof(info));
info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
info.bmiHeader.biWidth = 900;
info.bmiHeader.biHeight = 900;
info.bmiHeader.biPlanes = 1;
info.bmiHeader.biBitCount = 24;
info.bmiHeader.biCompression = BI_RGB;

bitmap = CreateDIBSection(dc, &info, DIB_RGB_COLORS, (void **)&bits, NULL, 0);

//CBitmap* pOldBitmap = dcMemory.SelectObject(&bmp);

SelectObject(dc, bitmap); // create context after select the bitmap???

// Set the pixel format...
// !!! must set the pixel format after selecting the bitmap!!!!!!!!!!!!
memset(&pfd, 0, sizeof(pfd));
pfd.nSize = sizeof(pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_BITMAP | PFD_SUPPORT_OPENGL; // draw to bitmap!!!
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cRedBits = 8;
pfd.cGreenBits = 8;
pfd.cBlueBits = 8;
pfd.cDepthBits = 16;

int pf = ChoosePixelFormat(dc, &pfd);
SetPixelFormat(dc, pf, &pfd);

rc = wglCreateContext(dc);
wglMakeCurrent(dc, rc);

Initialize();
DrawObject();

// SwapBuffers(dc);

// prepare palette
LOGPALETTE * pLogPal = (LOGPALETTE *)new char[sizeof(LOGPALETTE) +
256 * sizeof(PALETTEENTRY)];

pLogPal->palVersion = 0x300;
pLogPal->palNumEntries = 256;

RGBQUAD pRGB[256];
::GetDIBColorTable(dc, 0, 256, pRGB); // use HDC of opengl

for(int i = 0 ; i < 256 ; i ++)
{
pLogPal->palPalEntry[i].peRed = pRGB[i].rgbRed;
pLogPal->palPalEntry[i].peGreen = pRGB[i].rgbGreen;
pLogPal->palPalEntry[i].peBlue = pRGB[i].rgbBlue;
pLogPal->palPalEntry[i].peFlags = 0;
}

CPalette * hPalette = NULL;
hPalette = new CPalette;
hPalette->CreatePalette(pLogPal);

delete pLogPal;


CClientDC thisdc(this);
CPalette *oldPalette;
oldPalette = thisdc.SelectPalette(hPalette, true);
thisdc.RealizePalette();

::StretchDIBits(thisdc.GetSafeHdc(), 0,0, 500, 500,
0, 0, 500, 500,
bits, &info,
DIB_RGB_COLORS, SRCCOPY);

thisdc.SelectPalette(oldPalette, true);
::DeleteObject(hPalette);

wglMakeCurrent(NULL,NULL);

// wglDeleteContext(rc);
DeleteObject(bitmap);
// DeleteDC(dc);
ReleaseDC(&thisdc);
syy64 2004-10-29
  • 打赏
  • 举报
回复
在绘时切换RC
yjh1982 2004-10-29
  • 打赏
  • 举报
回复
用DIB dc可以办到.可惜是永不加速.也就是说只能用到M$的软件实现.


还有一个方法是GDI绘在memDC中.画opengl其它内容前用drawpixel先画memDC中的内容.
redcony 2004-10-29
  • 打赏
  • 举报
回复
关注
happyili 2004-10-29
  • 打赏
  • 举报
回复
有没有具体的代码阿。。。贴出来看看。。。
我很菜的。。。
我先去试试吧~ 多谢拉~~

4,445

社区成员

发帖
与我相关
我的任务
社区描述
图形图像/机器视觉
社区管理员
  • 机器视觉
  • 迪菲赫尔曼
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧