Results 1 to 9 of 9

Thread: Having another program control rendering

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2004
    Posts
    20

    Having another program control rendering

    I have some standalone C++ code that decides does some calculations and decide a dynamic flightpath of some airplanes.

    What I would like to do is have those flightpaths displayed though opengl.

    However, in my previous programming with OpenGL, I use the glutDisplayFunc and glutIdleFunc to display.
    But how would I integrate my C++ code with the rendering code because my C++ code decides the coordinates of the code and passes it to my opengl code, but since rendering functions registerd through glutDisplayFunc and glutIdleFunc are always running.. how do I move program control to my program?
    Ie I want to start rendering. then go back to my C++ code that does its own stuff and updates the coordinates whenever it wants to.

    I suppose using shared data structures is a solution but.. that might involve mutexes since I add and delete new objects.. so that list has to be locked.

    Right now a hack is to have my opengl code being called by my c++ code and in the display code, I ask for new coordinates every now and then.

    But this will not be sufficient if I want to send data to 3 diff rendering codes that draw difff scenes.

    So how can I better control the whole rendering process if I'm always stuck in the loop for the display and idle functions.

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Jan 2003
    Location
    Virginia
    Posts
    586

    Re: Having another program control rendering

    semaphores, shared memory, sockets, signals...

  3. #3
    Guest

    Re: Having another program control rendering

    I've had some success using glut to do rendering outside of any callback functions. Like this:

    -glutSetWindow( someWindow ); // focus on a window
    -perform OpenGL drawing: glBegin..glEnd()
    for instance
    -glutPostRedisplay();

    -in the display callback:
    glFlush();
    glutSwapBuffers();

    I've had some of the experts on this forum object to this method but it works.

    I'm a relative newbie so take my advice with a
    large grain of salt.

  4. #4
    Guest

    Re: Having another program control rendering

    Forgot to mention - I'm not stuck in a loop. I use glutMainEventLoop() which exits and lets you get back to doing other stuff. glutMainEventLoop() is from the OpenGLUT library. Your executive could look like:

    - initialize your window(s)

    while
    {
    - call you flight calculations

    glutSetWindow( your window );
    - invoke OpenGL stuff to draw
    glutPostRedisplay();

    glutMainEventLoop();

    // returned from glutMainEventLoop

    }!done;

  5. #5
    Junior Member Newbie
    Join Date
    Oct 2004
    Posts
    20

    Re: Having another program control rendering

    hmm glutMainEventLoop(); looks promising but I cant find any documentation for it.
    Only 2 links for it came up in google. and those were extensions to the OpenGL library.

  6. #6
    Junior Member Newbie
    Join Date
    Oct 2004
    Posts
    20

    Re: Having another program control rendering

    Perhaps my description of my problem wasnt clear enough.
    I basically have some decision code that decides to draw planes from point A to B in t seconds. And it can add new planes to draw whenever it wants. And I cant put this update code as my idle function.

    At the same time, I want to display the airplane flying on a textured background.
    I also want to display the events in a different display.

    How do I integrate this?
    The only idea I have is to start my decision code that spawns two threads to display.
    And the two display codes will be the normal glut application that draws planes using shared memory with my decision code.
    Does this sound right?
    Or is there a simpler way

  7. #7
    Junior Member Newbie
    Join Date
    Oct 2004
    Posts
    20

    Re: Having another program control rendering

    If the program werent threaded.. how would i start my decision code, start my display.
    and every now and then send new inputs to be drawn to my display?
    Problem1: glutmainloop keeps looping, i cant return to my decision code.
    Problem2: if problem 1 is solved, how do I signal something new to be drawn by my display?

  8. #8
    Member Newbie
    Join Date
    Jan 2005
    Location
    Lexington, KY
    Posts
    48

    Re: Having another program control rendering


  9. #9
    Member Newbie
    Join Date
    Jan 2005
    Location
    Lexington, KY
    Posts
    48

    Re: Having another program control rendering

    I am currently working on a Windows/OpenGLUT/OpenGL program that has 4 windows and 2 subwindows. We're drawing 2-dimensional symbols that move on 3 of the displays while drawing bitmapped text to a 4th display. We're doing all of that in 1 (one) thread. We've considered making the leap to multitasking but so far it has not been necessary.

    When you want to draw to one of the displays:

    glutSetDisplay( display1 );
    -draw some stuff
    glutPostRedisplay();

    and then to the other display:

    glutSetDisplay( display2 );
    -draw some stuff
    glutPostRedisplay();

    Better check this out with an expert. However, it's working very well for us.

Similar Threads

  1. Control VGA Output from program
    By jc15100 in forum OpenGL: Windows
    Replies: 2
    Last Post: 10-23-2011, 08:34 PM
  2. Replies: 1
    Last Post: 08-30-2004, 11:39 AM
  3. Opengl rendering as control on child window of MDI App. in MFC
    By mbaker in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 07-30-2004, 10:58 AM
  4. Replies: 6
    Last Post: 04-07-2004, 10:03 AM
  5. key input and timer control in an opengl program
    By jesusgumbau in forum OpenGL: Linux
    Replies: 1
    Last Post: 03-28-2001, 10:05 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