急!OpenGl图形无法显示。

brightboy 2003-12-25 11:09:12
为什么在OnDraw中采用内存位图方式画图后,OpenGl图形就显示不出来了?其他普通线条等图元显示正常.(是为了减少闪烁才用的内存位图方式)
...全文
216 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
stonecsdn 2003-12-26
  • 打赏
  • 举报
回复
减少闪烁?是不是你设置的背景(比如黑色)和windows擦除窗口时的默认背景白色不一样?
那么修改这个默认的窗口重绘时的背景吧。
brightboy 2003-12-26
  • 打赏
  • 举报
回复
在MSDN上查到了:
OpenGL VI:Rendering on DIBs with PFD_DRAW_TO_BITMAP
有没有类似的例子?
wangweintk 2003-12-25
  • 打赏
  • 举报
回复
1.glViewport(0, 0, m_oldRect.right, m_oldRect.bottom);是不是应该放到Init()中。
2.没见你设置视景体,可能是视景体设置有问题,导致你画的东西不在视线范围内,建议做一个旋转函数,用键盘转转看。
3.glViewport后(并且在视景体设置以后),是不是应该加入
glMatrixMode(GL_PROJECTION),因为你随后所做的操作是针对物体的。

brightboy 2003-12-25
  • 打赏
  • 举报
回复
用lineto画是正常的。
brightboy 2003-12-25
  • 打赏
  • 举报
回复
void CEdit3DMView::init()
{
PIXELFORMATDESCRIPTOR pfd;
int n;
//HGLRC hrc;

m_pDC = new CClientDC(this);
ASSERT(m_pDC!=NULL);
if(!bSetupPixelFormat()) return;

n=::GetPixelFormat(m_pDC->GetSafeHdc());
::DescribePixelFormat(m_pDC->GetSafeHdc(),n,sizeof(pfd),&pfd);
//hrc=wglCreateContext(m_pDC->GetSafeHdc());
m_hRC = wglCreateContext(m_pDC->GetSafeHdc());
//wglMakeCurrent(m_pDC->GetSafeHdc(), hrc);
wglMakeCurrent(m_pDC->GetSafeHdc(), m_hRC);

GetClientRect(&m_oldRect);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

//glEnable(GL_TEXTURE_2D); //Æô¶¯ÎÆÀí
//glEnable(GL_NORMALIZE);

//if u have many device(windows) for OpenGL, u can add this sentence
//to make the current device to be NULL.
//wglMakeCurrent(m_pDC->GetSafeHdc(), NULL);

}
void CEdit3DMView::OnDraw(CDC* pDC)
{
CEdit3DMDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
//set current device

//

CDC dc;
CDC* pDrawDC = pDC;
CBitmap bitmap;
CBitmap* pOldBitmap;

// only paint the rect that needs repainting
CRect client;
pDC->GetClipBox(client);
CRect rect = client;
CClientDC dc1(this);

OnPrepareDC(&dc1, NULL);
dc1.LPtoDP(rect);
rect.NormalizeRect();

if (!pDC->IsPrinting())
{
// draw to offscreen bitmap for fast looking repaints
if (dc.CreateCompatibleDC(pDC))
{
if (bitmap.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height()))
{
OnPrepareDC(&dc, NULL);
pDrawDC = &dc;

// offset origin more because bitmap is just piece of the whole drawing
dc.OffsetViewportOrg(-rect.left, -rect.top);
pOldBitmap = dc.SelectObject(&bitmap);
dc.SetBrushOrg(rect.left % 8, rect.top % 8);

// might as well clip to the same rectangle
dc.IntersectClipRect(client);
}
}
}
else {//printing
}
// paint background

wglMakeCurrent(pDrawDC->GetSafeHdc(), m_hRC);
DrawScene();

if (pDrawDC != pDC)//drawing in the view
{
pDC->SetViewportOrg(0, 0);
pDC->SetWindowOrg(0,0);
pDC->SetMapMode(MM_TEXT);
dc.SetViewportOrg(0, 0);
dc.SetWindowOrg(0,0);
dc.SetMapMode(MM_TEXT);
pDC->BitBlt(rect.left, rect.top, rect.Width(), rect.Height(),
&dc, 0, 0, SRCCOPY);
dc.SelectObject(pOldBitmap);
}
//
}
void CEdit3DMView::DrawScene()
{
//To get the current view type
ViewType currentviewtype;
CMainFrame* pframe = (CMainFrame*)GetParentFrame();
currentviewtype = pframe->m_ViewArrange.m_MainViewType;

glViewport(0, 0, m_oldRect.right, m_oldRect.bottom);

glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

CEdit3DMDoc* pdoc = GetDocument();
if(pdoc != NULL)
{
pdoc->m_3DMani.SetProjection(currentviewtype, 0);
pdoc->m_3DMani.DrawBound(currentviewtype);
}

glFinish();
SwapBuffers(wglGetCurrentDC());
}
easyrock 2003-12-25
  • 打赏
  • 举报
回复
我觉得不需要使用双缓冲,因为PIXELFORMATDESCRIPTOR结构的dwFlags成员指定PFD_DOUBLEBUFFER就可以实现双缓冲了。
zhucde 2003-12-25
  • 打赏
  • 举报
回复
能看看你调用初始化OpenGL窗口及显示的代码吗?
zhucde 2003-12-25
  • 打赏
  • 举报
回复
http://www.csdn.net/develop/read_article.asp?id=22732
brightboy 2003-12-25
  • 打赏
  • 举报
回复
bool CEdit3DMView::bSetupPixelFormat()
{
static PIXELFORMATDESCRIPTOR pfd=
{
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_BITMAP|
PFD_DRAW_TO_WINDOW|
PFD_SUPPORT_OPENGL,//|PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
24,
0,0,0,0,0,0,
0,
0,
0,
0,0,0,0,
32,
0,
0,
PFD_MAIN_PLANE,
0,
0,0,0
};
int pixelformat;

if((pixelformat=ChoosePixelFormat(m_pDC->GetSafeHdc(),&pfd))==0)
{
MessageBox("ChoosePixelFormat failed");
return false;
}
if(SetPixelFormat(m_pDC->GetSafeHdc(),pixelformat,&pfd)==false)
{
MessageBox("SetPixelFormat failed");
return false;
}
return true;
}
brightboy 2003-12-25
  • 打赏
  • 举报
回复
请帮忙。
brightboy 2003-12-25
  • 打赏
  • 举报
回复
to wangweintk(枫杨):
这些处理在OnSize里。
xinyu 2003-12-25
  • 打赏
  • 举报
回复
我也想知道怎么回事

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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