Announcement

Collapse
No announcement yet.

OpenGL message pump

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • OpenGL message pump

    Hi all,

    I need to add an OpenGL 3-D system to someone's application. My problem
    is that up to this point the 3-D system I've done opens in one window only.
    I need to allow the person to switch/open the full screen OpenGL window
    and run a real time rendering by use of a button or key, etc, from the main
    app.. OpenGL requires a PeekMessage loop something like:

    Code:
        WHILE 1
            WHILE ISTRUE(PeekMessage(msg,%NULL,0,0,%PM_NOREMOVE))
                IF GetMessage(msg,%NULL,0,0) THEN
                    TranslateMessage msg
                    DispatchMessage msg
                ELSE
                   FUNCTION = 1
                   EXIT FUNCTION
                END IF
            WEND
    
            DrawGLScene
            SwapBuffers hDC
            IF keys(%VK_ESCAPE) THEN SendMessage hWnd,%WM_CLOSE,0,0
        WEND
    DrawGLScene runs the rendering... I'm confused here. How can
    I go about including a loop like this in the main app? There should
    only be one message pump, right? Should the main app's pump be changed?
    If so, any suggestions on where I might begin allowing the main app
    to switch/already be using this loop from the beginning?

    Sorry this is a vague question, perhaps I can come up with a better code example.

    Thanks,


    ------------------
    Todd Wasson
    -------------
    Performance Simulations
    Drag Racing and Top Speed
    Prediction Software http://PerformanceSimulations.Com



    [This message has been edited by Todd Wasson (edited October 23, 2001).]
    Todd Wasson
    http://PerformanceSimulations.Com
    PowerBasic Racing Simulator (October 2007 clip - 15.1MB wmv file) http:http://www.performancesimulations.co...m-GenIV-12.wmv

  • #2
    Todd;

    There is only one message loop in any application, running
    at one time (technically, an app may have more than one set of
    message loop code - ie. normal window message loop and a custom
    modal message loop).

    Normally a message loop uses GetMessage. Since GetMessage waits
    until a message is received before it returns control to your app,
    the code for your OpenGL messageloop uses PeekMessage which tests
    for a message (without retrieving it) and immediate returns control
    to your app, so the loop will run continuously (this allows the
    OpenGL commands to be executed).

    You will have to replace the existing message loop (with the new code above)
    in your for this to work. The message loop is usually in the WinMain
    (or PBMain) procedure.

    I think you may have to resort to using SDK style (pure API) code
    rather than DDT in this instance, since I don't think DDT gives you
    access to the message loop (as far as I know anyway).




    ------------------
    Chris Boss
    Computer Workshop
    Developer of "EZGUI"
    http://cwsof.com
    http://twitter.com/EZGUIProGuy

    Comment


    • #3
      You should be able to still use DDT, just subclass it.

      ------------------
      -Greg
      -Greg
      [email protected]
      MCP,MCSA,MCSE,MCSD

      Comment


      • #4
        Chris, you omitted to mention non-primary thread message pumps.

        Also, you should be able to use DDT without subclassing, but by using MODELESS dialog(s) with an SDK-style message pump (PeekMessage/IsDialogMessage/TranslateMessage/DispatchMessage/etc).


        ------------------
        Lance
        PowerBASIC Support
        mailto:[email protected][email protected]</A>
        Lance
        mailto:[email protected]

        Comment


        • #5
          Great, thanks for the replies. Looks like I'll need to study
          a bit to get my head around how exactly to go about this, but at
          least now I know to use one PeekMessage loop. I'd like to learn how
          to do this using SDK style code, even though I personally find
          DDT much easier to work with. Perhaps I'll be back with more
          questions.... My basics are just not up to par!

          If I was to have one main app window (not-OpenGL), there are tons
          of SDK examples (plus Petzold's) included with PB, but I can't
          seem to figure out how I'd go about opening OpenGL fullscreen window
          from this. It shouldn't really be any different than opening a
          standard window, but with SDK style, this is hard for me! lol

          Basically, I should be defining and registering the window classes
          in WinMain one right after the other, then open the main window with:
          Code:
            ShowWindow hWnd, iCmdShow
            UpdateWindow hWnd
          Then the PeekMessage pump should follow, right? This will first
          fire off the WM_CREATE message and possibly a WM_PAINT (not concerned
          with that one really.)

          When opening the second window, I'd want to CreateWindow in WndProc
          in response to something like a WM_LBTNCLICKED message (or whatever.)

          Is this basically where my thinking should begin? Anyway, I'll read
          more like I should! If I can open and close some windows using SDK style
          code for a change, I ought to be able to open an OpenGL window covering
          everything too.

          Thanks!



          ------------------
          Todd Wasson
          -------------
          Performance Simulations
          Drag Racing and Top Speed
          Prediction Software
          http://PerformanceSimulations.Com
          Todd Wasson
          http://PerformanceSimulations.Com
          PowerBasic Racing Simulator (October 2007 clip - 15.1MB wmv file) http:http://www.performancesimulations.co...m-GenIV-12.wmv

          Comment


          • #6
            Originally posted by Todd Wasson:
            If I was to have one main app window (not-OpenGL), there are tons
            of SDK examples (plus Petzold's) included with PB, but I can't
            seem to figure out how I'd go about opening OpenGL fullscreen window
            from this. It shouldn't really be any different than opening a
            standard window, but with SDK style, this is hard for me! lol
            You can find some information about OpenGL and PBDLL in: http://root.tty0.org/sublevel6/

            Regards, Theo Meester.

            ------------------

            Comment


            • #7
              Thanks for the link, Theo. That's where I got most of the info
              so far. That site is a life saver, to be sure :-)

              I think I've got the problem licked, although it may not be
              "proper" programming style. Still, it should do the job just fine.

              Thanks again,



              ------------------
              Todd Wasson
              -------------
              Performance Simulations
              Drag Racing and Top Speed
              Prediction Software
              http://PerformanceSimulations.Com
              Todd Wasson
              http://PerformanceSimulations.Com
              PowerBasic Racing Simulator (October 2007 clip - 15.1MB wmv file) http:http://www.performancesimulations.co...m-GenIV-12.wmv

              Comment

              Working...
              X