Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. OpenGL control on split MFC form

OpenGL control on split MFC form

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsquestionc++game-devtesting
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 12249262
    wrote on last edited by
    #1

    I am trying to build an MFC application the uses a form with two panes, one for controls and the other for an OpenGL graphics window. I followed 2 code project for this task.

    1. 15338/SDI-with-split-window by kencocomputers
    2. Setting up OpenGL in an MFC control from codeguru C10975
      The split window application part worked fine but I cannot initialize the openGL context in the graphics pane.
      The classes in the project are:
    3. CAboutDlg
    4. CFormLeft
    5. CFormRight
    6. CMainForm
    7. CMFC_SurfaceViwerApp
    8. COpenGLControl
      CFormLeft and CFormRight views are created in the CManFrame function
      BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)

    Specifically with:
    if (!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CFormLeft), CSize(300, 100), pContext) ||
    !m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CFormRight), CSize(100, 100), pContext))
    {
    m_wndSplitter.DestroyWindow();
    return FALSE;
    }

    My question is how to actually implement the OpenGL Window; I suspect that it requires some code like:
    void COpenGLControl::oglInitialize()
    {
    // Initial Setup:
    //
    static PIXELFORMATDESCRIPTOR pfd =
    {
    sizeof(PIXELFORMATDESCRIPTOR),
    1,
    PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
    PFD_TYPE_RGBA,
    32, // bit depth
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    16, // z-buffer depth
    0, 0, 0, 0, 0, 0, 0,
    };
    // Get device context only once.
    hdc = GetDC()->m_hDC;

    // Pixel format.
    m\_nPixelFormat = ChoosePixelFormat(hdc, &pfd);
    SetPixelFormat(hdc, m\_nPixelFormat, &pfd);
    
    // Create the OpenGL Rendering Context.
    hrc = wglCreateContext(hdc);
    wglMakeCurrent(hdc, hrc);
    
    // Basic Setup:
    //
    // Set color to use when clearing the background.
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glClearDepth(1.0f);
    
    // Turn on backface culling
    glFrontFace(GL\_CCW);
    glCullFace(GL\_BACK);
    
    // Turn on depth testing
    glEnable(GL\_DEPTH\_TEST);
    glDepthFunc(GL\_LEQUAL);
    
    // Send draw request
    OnDraw(NULL);
    

    }
    But how does it activate? I put a call inside the oglCreate() function but nothing happened.

    void COpenGLControl::oglCreate(CRect rect, CWnd *parent)
    {
    CString className = AfxRegisterWndClass(CS_HREDRAW |
    CS_VREDRAW | CS_OWNDC, NULL,
    (HBRUSH)GetStockObject(BLACK_BRUSH), NULL);

    CreateEx(0, className, L"OpenGL", WS\_CHILD | WS\_VISIBLE |
    	WS\_CLIPSIBLINGS | WS\_CLIPCHILDREN, rect, parent, 0);
    
    // Set initial variables' values
    m\_oldWindow = rect;
    m\_originalRect = re
    
    L 1 Reply Last reply
    0
    • U User 12249262

      I am trying to build an MFC application the uses a form with two panes, one for controls and the other for an OpenGL graphics window. I followed 2 code project for this task.

      1. 15338/SDI-with-split-window by kencocomputers
      2. Setting up OpenGL in an MFC control from codeguru C10975
        The split window application part worked fine but I cannot initialize the openGL context in the graphics pane.
        The classes in the project are:
      3. CAboutDlg
      4. CFormLeft
      5. CFormRight
      6. CMainForm
      7. CMFC_SurfaceViwerApp
      8. COpenGLControl
        CFormLeft and CFormRight views are created in the CManFrame function
        BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)

      Specifically with:
      if (!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CFormLeft), CSize(300, 100), pContext) ||
      !m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CFormRight), CSize(100, 100), pContext))
      {
      m_wndSplitter.DestroyWindow();
      return FALSE;
      }

      My question is how to actually implement the OpenGL Window; I suspect that it requires some code like:
      void COpenGLControl::oglInitialize()
      {
      // Initial Setup:
      //
      static PIXELFORMATDESCRIPTOR pfd =
      {
      sizeof(PIXELFORMATDESCRIPTOR),
      1,
      PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
      PFD_TYPE_RGBA,
      32, // bit depth
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      16, // z-buffer depth
      0, 0, 0, 0, 0, 0, 0,
      };
      // Get device context only once.
      hdc = GetDC()->m_hDC;

      // Pixel format.
      m\_nPixelFormat = ChoosePixelFormat(hdc, &pfd);
      SetPixelFormat(hdc, m\_nPixelFormat, &pfd);
      
      // Create the OpenGL Rendering Context.
      hrc = wglCreateContext(hdc);
      wglMakeCurrent(hdc, hrc);
      
      // Basic Setup:
      //
      // Set color to use when clearing the background.
      glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
      glClearDepth(1.0f);
      
      // Turn on backface culling
      glFrontFace(GL\_CCW);
      glCullFace(GL\_BACK);
      
      // Turn on depth testing
      glEnable(GL\_DEPTH\_TEST);
      glDepthFunc(GL\_LEQUAL);
      
      // Send draw request
      OnDraw(NULL);
      

      }
      But how does it activate? I put a call inside the oglCreate() function but nothing happened.

      void COpenGLControl::oglCreate(CRect rect, CWnd *parent)
      {
      CString className = AfxRegisterWndClass(CS_HREDRAW |
      CS_VREDRAW | CS_OWNDC, NULL,
      (HBRUSH)GetStockObject(BLACK_BRUSH), NULL);

      CreateEx(0, className, L"OpenGL", WS\_CHILD | WS\_VISIBLE |
      	WS\_CLIPSIBLINGS | WS\_CLIPCHILDREN, rect, parent, 0);
      
      // Set initial variables' values
      m\_oldWindow = rect;
      m\_originalRect = re
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Since all this code is based on CodeProject articles you may get more help by using the forum at the end of the article. Also, you should not call OnDraw() directly, you should use the standard Windows rules for updating Windows. See UpdateWindow function (Windows)[^].

      B 1 Reply Last reply
      0
      • L Lost User

        Since all this code is based on CodeProject articles you may get more help by using the forum at the end of the article. Also, you should not call OnDraw() directly, you should use the standard Windows rules for updating Windows. See UpdateWindow function (Windows)[^].

        B Offline
        B Offline
        Bram van Kampen
        wrote on last edited by
        #3

        ??? Richard, Was this post meant for me? I NEVER use OnDraw directly, and my App is not at all based on Code Project Articles! I am just feeling around on my own, to solve a particular problem. If it IS meant for me a sentence containing "Wrong End" and "Stick" springs to mind! About Code Project Articles, I Only suggested, that, if I ever get this to work, that it merits me submitting an article about how to avoid the pittfals! :)

        Bram van Kampen

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups