在对话框opengl绘图!还会加分的! 我这里写了个程序! 在对话框中用opengl绘图!实现了! 但是我希望哪位大侠帮忙看看,我想在对话框中的某个控件中绘图,例如static,或者别的, 如果需要我可以把代码发给您,帮忙改下,不胜感激! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在对话框中绘图一样的呀,建议用picture控件! 用picture也可以!要不麻烦您帮我看看程序怎么样!我这里有在对话框画图的源程序,您帮我在控件中画出来,可以吗?麻烦你了![email protected]这是我的邮箱! BOOL OGLDiag::OnInitDialog(){ CDialog::OnInitDialog(); HDC hDC; CWnd* hwnd = GetDlgItem(IDC_PIC); RECT rect; hwnd->GetClientRect(&rect); int xsize = rect.right - rect.left; int ysize = rect.bottom - rect.top; GetDlgItem(IDC_PIC,&m_hPwnd); hDC = ::GetDC(m_hPwnd); MySetPixelFormat(hDC); m_hRC = wglCreateContext(hDC); GLdouble aspect_ratio; wglMakeCurrent(hDC, m_hRC); glShadeModel(GL_SMOOTH); // Enable Smooth Shading glEnable(GL_DEPTH_TEST); // Enables Depth Testing glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations aspect_ratio = (GLdouble)xsize/(GLdouble)ysize; glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-2,2,-2,2,-10,10);// gluPerspective(45.0f, aspect_ratio, 0.0f, 1.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); wglMakeCurrent(NULL,NULL); return TRUE; // return TRUE unless you set the focus to a control // 异常: OCX 属性页应返回 FALSE}int OGLDiag::MySetPixelFormat(HDC hdc){ PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd 1, // version number PFD_DRAW_TO_WINDOW | // support window PFD_SUPPORT_OPENGL | // support OpenGL PFD_DOUBLEBUFFER, // double buffered PFD_TYPE_RGBA, // RGBA type 24, // 24-bit color depth 0, 0, 0, 0, 0, 0, // color bits ignored 0, // no alpha buffer 0, // shift bit ignored 0, // no accumulation buffer 0, 0, 0, 0, // accum bits ignored 32, // 32-bit z-buffer 0, // no stencil buffer 0, // no auxiliary buffer PFD_MAIN_PLANE, // main layer 0, // reserved 0, 0, 0 // layer masks ignored }; int iPixelFormat; // get the device context's best, available pixel format match if((iPixelFormat = ChoosePixelFormat(hdc, &pfd)) == 0) { //MessageBox(NULL, "ChoosePixelFormat Failed", NULL, MB_OK); return 0; } // make that match the device context's current pixel format if(SetPixelFormat(hdc, iPixelFormat, &pfd) == FALSE) { //MessageBox(NULL, "SetPixelFormat Failed", NULL, MB_OK); return 0; } return 1;}void OGLDiag::OnPaint(){ CPaintDC dc(this); // device context for painting HDC hDC = ::GetDC(m_hPwnd); wglMakeCurrent(hDC, m_hRC); glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // Black Background glClearDepth(1.0f); // Depth Buffer Setup glClear(GL_COLOR_BUFFER_BIT); glColor3f(1,0,0); glBegin(GL_LINE_STRIP); glVertex3f(0,0,0); glVertex3f(1,0,0); glVertex3f(0,1,0); glEnd(); SwapBuffers(hDC); wglMakeCurrent(NULL,NULL);} 刚好我也在弄,就这三个函数就可以了。OGLDiag是为对话框创建的类,OnPaint()和OnInitDialog()是对话框的消息函数或重写函数。IDC_PIC是对话框中的一个picture控件。 我想知道OpenGL动画在对话框里有哪些方法实现,感觉管理起来不太方便,想用非模式对话框。和楼主一起学习了,大家一起讨论吧。 msdn光盘里的例程中有一个例子,cube你可以参考一下 VC模拟POST提交,非Ascii码的处理问题? 一个客户端与多台机器相连,如何采用多线程技术给每个服务器开一个线程? 用vc驱动usb摄像头时报错的问题 如何改变对话框的左上角小图标!(另注:小弟是第一次在CSDN求助的菜鸟) 哪有北京大学出版社《WINDOWS程序设计》?拜求! 端口、套接字 请问如何动态生成一个CListCtrl? 关于 Windows Media Player 的 AxtivX控件的播放进度问题!到别处回答200分! 关于vc入门的几点疑问 VC进程结速代码 [急切求助]如何实现常用字符串,转换成16进制字符串? 如何设置位图按钮的位图?
{
CDialog::OnInitDialog(); HDC hDC;
CWnd* hwnd = GetDlgItem(IDC_PIC);
RECT rect;
hwnd->GetClientRect(&rect);
int xsize = rect.right - rect.left;
int ysize = rect.bottom - rect.top; GetDlgItem(IDC_PIC,&m_hPwnd);
hDC = ::GetDC(m_hPwnd); MySetPixelFormat(hDC);
m_hRC = wglCreateContext(hDC); GLdouble aspect_ratio; wglMakeCurrent(hDC, m_hRC); glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations aspect_ratio = (GLdouble)xsize/(GLdouble)ysize;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-2,2,-2,2,-10,10);
// gluPerspective(45.0f, aspect_ratio, 0.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); wglMakeCurrent(NULL,NULL);
return TRUE; // return TRUE unless you set the focus to a control
// 异常: OCX 属性页应返回 FALSE
}
int OGLDiag::MySetPixelFormat(HDC hdc)
{
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
1, // version number
PFD_DRAW_TO_WINDOW | // support window
PFD_SUPPORT_OPENGL | // support OpenGL
PFD_DOUBLEBUFFER, // double buffered
PFD_TYPE_RGBA, // RGBA type
24, // 24-bit color depth
0, 0, 0, 0, 0, 0, // color bits ignored
0, // no alpha buffer
0, // shift bit ignored
0, // no accumulation buffer
0, 0, 0, 0, // accum bits ignored
32, // 32-bit z-buffer
0, // no stencil buffer
0, // no auxiliary buffer
PFD_MAIN_PLANE, // main layer
0, // reserved
0, 0, 0 // layer masks ignored
}; int iPixelFormat; // get the device context's best, available pixel format match
if((iPixelFormat = ChoosePixelFormat(hdc, &pfd)) == 0)
{
//MessageBox(NULL, "ChoosePixelFormat Failed", NULL, MB_OK);
return 0;
} // make that match the device context's current pixel format
if(SetPixelFormat(hdc, iPixelFormat, &pfd) == FALSE)
{
//MessageBox(NULL, "SetPixelFormat Failed", NULL, MB_OK);
return 0;
} return 1;
}
void OGLDiag::OnPaint()
{
CPaintDC dc(this); // device context for painting
HDC hDC = ::GetDC(m_hPwnd);
wglMakeCurrent(hDC, m_hRC); glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1,0,0);
glBegin(GL_LINE_STRIP);
glVertex3f(0,0,0);
glVertex3f(1,0,0);
glVertex3f(0,1,0);
glEnd();
SwapBuffers(hDC);
wglMakeCurrent(NULL,NULL);
}