我这里写了个程序!
  在对话框中用opengl绘图!实现了!
  但是我希望哪位大侠帮忙看看,我想在对话框中的某个控件中绘图,例如static,或者别的,
  如果需要我可以把代码发给您,帮忙改下,不胜感激!
  

解决方案 »

  1.   

    在对话框中绘图一样的呀,建议用picture控件!
      

  2.   

    用picture也可以!要不麻烦您帮我看看程序怎么样!我这里有在对话框画图的源程序,您帮我在控件中画出来,可以吗?麻烦你了![email protected]这是我的邮箱!
      

  3.   

    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);
    }
      

  4.   

    刚好我也在弄,就这三个函数就可以了。OGLDiag是为对话框创建的类,OnPaint()和OnInitDialog()是对话框的消息函数或重写函数。IDC_PIC是对话框中的一个picture控件。
      

  5.   

    我想知道OpenGL动画在对话框里有哪些方法实现,感觉管理起来不太方便,想用非模式对话框。和楼主一起学习了,大家一起讨论吧。
      

  6.   

    msdn光盘里的例程中有一个例子,cube你可以参考一下