Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Setting up OpenGL in SDI/MDI MFC application

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2011
    Location
    NY, USA
    Posts
    3

    Setting up OpenGL in SDI/MDI MFC application

    I am new in OpenGL and even in VC++, was programming with Fortran for all my student time. I am trying to set up OpenGL in MFC SDI or Dialog application. Tried different websites for more than a week so far. I learned basic OpenGL functionalities but yet to fully understand how it connects to MFC. I am trying to exactly follow step by step below procedure to set up OpenGL in a MFC/Dialog from below link.

    http://www.codeguru.com/cpp/g-m/opengl/o...MFC-Control.htm

    I get error on this line:
    CreateEx(0, className, "OpenGL", WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, rect, parent, 0);
    it says "no instance of overloaded function "COpenControl:: CreateEx" matches the argument list.
    is it because of different version of VS? any comment is appreciated.
    Also tried to follow Microsoft MFCOGL example; it does not have solution ".sln" and I could not build something to test it.

    My ultimate goal is to have a MFC/SDI application with a window in it that can show 3D graphic of cutting tools that is moving toward a piece and can zoom/rotate/pan it.

    I am using VS2010 Professional in WinXP.
    Thanks for any other comment to expedite my learning procedure

  2. #2
    Senior Member Regular Contributor
    Join Date
    Oct 2010
    Location
    France
    Posts
    458

    Re: Setting up OpenGL in SDI/MDI MFC application

    First, use glut if you are new. This is the best and easiest way to start with OpenGL with no mess at all.

    Second, I think there is no reason to use MFC libraries, and I wonder if they are still really used.

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2011
    Location
    NY, USA
    Posts
    3

    Re: Setting up OpenGL in SDI/MDI MFC application

    what do you mean, by using "glut".
    by "I think there is no reason to use MFC libraries" you mean for such an application that I am looking for I don't need to use MFC?

  4. #4
    Senior Member Regular Contributor
    Join Date
    Oct 2010
    Location
    France
    Posts
    458

    Re: Setting up OpenGL in SDI/MDI MFC application

    To my opinion, mfc are old. But if you want to continue with them, the error you have says that the arguments you give to CreateEx does not match any prototype providen by MFC. So check for all prototypes of this function and call it the good way (I know nothing about MFC, so maybe it's just a type that doesn't match, or a missing argument, or argument ordering...).

    I just meant that if you're new to OpenGL you should first get use to program with it before entering a "big" application. glut won't allow you to have menus, buttons or such, but it will allow you to work with GL easily, without having to deal with other things (windowing programmation...).

    Finally, direct programming with WIN32 libraries should be better than MFC; and VC 2010 provides you an editor to create your window and buttons and such easily, so AFAIK there's no more need to use MFC.

  5. #5
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,674

    Re: Setting up OpenGL in SDI/MDI MFC application

    what do you mean, by using "glut".
    FreeGLUT is a simple library for writing relatively simple OpenGL applications. It does all the setup work for you, which allows you to focus on learning OpenGL. So if you are new to OpenGL and need to learn how the API works, it's a great starting place.

    There is an older GLUT library, which you should not use. It hasn't been updated in the better part of a decade. FreeGLUT is actually being worked on, so it's far more likely to work.

    As for his commentary on MFC, I have no idea what he's talking about.

  6. #6
    Senior Member OpenGL Pro Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    1,214

    Re: Setting up OpenGL in SDI/MDI MFC application

    It is a good idea to isolate OpenGL functions from MFC framework. So I recommend you to create GLRenderer class with following attributes and methods:

    • attribut
      • HGLRC m_hrc – OpenGL Rendering Context (OpenGL server)
    • mehtods
      – bool CreateGLContext(CDC* pDC) –Creates OpenGL Rendering Context,
      – void PrepareScene(CDC* pDC) – Initializes scene,
      – void DestroyScene(CDC* pDC) – Releases resources,
      – void Reshape(CDC* pDC, int w, int h) – Executes whenever the window or viewport is resized
      – void DrawScene(CDC* pDC) – Draws scene

    Include OpenGL support (gl.h, glu.h, ..., opengl.lib, glu32.lib, ...)

    In the View class:
    • add reference to GLRenderer (m_glRend),
    • add message handlers for:
      • WM_CREATE,
      • WM_ERASEBKGND,
      • WM_SIZE i
      • WM_DESTROY,
    • overload OnInitialUpdate
    • in CGLView::OnCreate call m_glRend.CreateGLContext,
    • in CGLView::OnSize call m_glRend.Reshape,
    • in CGLView::OnDestroy call m_glRend.DestoyScene,
    • in CGLView::OnInitialUpdate call m_glRend.PrepareScene,
    • in CGLView::OnDraw call m_glRend.DrawScene,
    • in CGLView::OnEraseBkgnd just return TRUE


    This is in short how MFC SDI/MDI/Dialog Based application can be OpenGL "enabled".

  7. #7
    Junior Member Newbie
    Join Date
    Jan 2011
    Location
    NY, USA
    Posts
    3

    Re: Setting up OpenGL in SDI/MDI MFC application

    I used LPCTSTR("OpenGL") for third arg and it worked.
    "CreateEx(0, className, LPCTSTR("OpenGL"), WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, rect, parent, 0);"

    Thanks for the advises.

  8. #8
    Senior Member OpenGL Pro Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    1,214

    Re: Setting up OpenGL in SDI/MDI MFC application

    Quote Originally Posted by _arts_
    To my opinion, mfc are old. But if you want to continue with them, the error you have says that the arguments you give to CreateEx does not match any prototype providen by MFC. So check for all prototypes of this function and call it the good way (I know nothing about MFC, so maybe it's just a type that doesn't match, or a missing argument, or argument ordering...).
    The first statement is that MFC is old, but the last claims that you don't know anything about MFC. Isn't is contradictory?

    Quote Originally Posted by _arts_
    Finally, direct programming with WIN32 libraries should be better than MFC; and VC 2010 provides you an editor to create your window and buttons and such easily, so AFAIK there's no more need to use MFC.
    Even more silly statement!!!

    I really don't understand need to tell something about the unknown stuff.

    Well, MFC library was extremely useful in the time of VS 4.0/4.1/4.2. Then there was an enormous time gap. It is shame that Microsoft don't support C++ programmers as they did before. There are so many useful tools and libraries for e.g. C#, and practically nothing for C++. It was sad to see VS2k8 with MFC on the level of VS6.0 (even with VS6.0 we used additional libraries for fancy controls). But with the service pack 1 things are become little bit better. Now we have ribbons and all the fancy stuff.
    VS2k10 is on the level of 2k8 considering MFC, but it is still very useful. I would like to see anyone creating Windows application using only Windows API.

  9. #9
    Senior Member Regular Contributor
    Join Date
    Oct 2010
    Location
    France
    Posts
    458

    Re: Setting up OpenGL in SDI/MDI MFC application

    I tried MFC some years ago, and I found that direct C WIN32 was easier, and better supported. So I know enough to say that MFC is old, not really maintained, and know too few about it to try to correct his mistake.

  10. #10
    Senior Member OpenGL Pro Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    1,214

    Re: Setting up OpenGL in SDI/MDI MFC application

    Well, it is time to reconsider your opinion.

    Check, for example, the following link:
    http://www.codeguru.com/columns/kate/art...nhancements.htm

Page 1 of 2 12 LastLast

Similar Threads

  1. Copy back buffer from one application and use in another application
    By murrdpirate in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 06-24-2014, 12:26 PM
  2. OpenGL Setting FPS
    By SeanAustin in forum OpenGL: Basic Coding
    Replies: 13
    Last Post: 10-21-2009, 06:47 PM
  3. setting up OpenGL for use in VS6
    By NightGiant in forum OpenGL: Windows
    Replies: 4
    Last Post: 03-17-2004, 07:56 PM
  4. help setting up openGL!!
    By in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 02-28-2002, 02:18 PM
  5. Setting up OpenGL
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 08-24-2001, 06:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean