PDA

View Full Version : how can i call opengl from another Visual C++ program



Mystery
12-24-2002, 11:48 PM
hi
I have a problem. I can not call an opengl example from my another(my base) program in Visual C++.
I calgulate some values and I want to draw it in opengl.
Everything is ok but when I write
gluMainLoop() my base program stops.

So I want to learn if there is a simple way to call opengl window from another program.
Thanks for your answer.

Deiussum
12-25-2002, 11:25 AM
glutMainLoop basically takes over the thread of operation it is called in until the window is closed. You could call that in a separate thread, but there might be better ways. You'd have to explain what you want in a bit more detail.

Mystery
12-26-2002, 12:26 AM
In fact my problem is with glutMainLoop().

I want to take the coordinates from another (my base) program and draw in step by step with opengl in another window. I can take the values from base program and update them. But I can't make it draw step bye step. Whenever I put glutMainLoop() my base program stops. I want two of them to run together. To update the coordinates and draw it.

Is there a way to draw something like this step by step in opengl?

By the way thanks for your answer http://www.opengl.org/discussion_boards/ubb/smile.gif

mikael_aronsson
12-26-2002, 12:31 AM
Hi !

Can't you use a timer, or an idle function, not sure if idle function are available in glut though.

The timer calls a callback function for you every x milliseconds, wouldn't that be possible to put your code in there ?

Mikael

Mystery
12-26-2002, 01:33 AM
I don't want a timer infact. I only want to run two programs parallel. I dont want opengl to stop my base program. It stops whenever I write glutMainLoop(). So I cant see it step by step. I can only see the diagram at the end of the program. That is my problem...
But a timer is not a solution for me.
Thanks anyway http://www.opengl.org/discussion_boards/ubb/smile.gif

Deiussum
12-26-2002, 06:15 AM
As I already stated, glutMainLoop() will lock up the current thread of execution until that window is closed. That means if you call it from your main thread, your main thread will appear to be halted.

There are a few methods to do what you are trying to do, but it would help to know a bit more about the architecture of your program. How do you create your main window? How do you update your data? Do you want them to be totally separate of each other, or do you want the display window to be a child window of the main window?

Some methods off the top of my head would include:
- Multithreading, and have the glut app check for updated data in the idle method, or a timer
- Create both windows with glut and use the idle function or timer for updating the data.
- Create both windows with Win32 (or however you are creating your main app window).
- Create them as two truly separate applications which communicate using something like named pipes or sockets.

nexusone
12-26-2002, 09:00 AM
You do not have to use GLUT to write a openGL program, there are lot's of examples of writting openGL with pure windows code to open and setup the window.

Once you have written a standard windows based program, should be able to pass information between your openGL window and some other program program written using the windows API.

But do you really need two program, or maybe one that creates two seaperate threads. Which is now more a windows question and best suited for a forum on windows programming.


Originally posted by Mystery:
hi
I have a problem. I can not call an opengl example from my another(my base) program in Visual C++.
I calgulate some values and I want to draw it in opengl.
Everything is ok but when I write
gluMainLoop() my base program stops.

So I want to learn if there is a simple way to call opengl window from another program.
Thanks for your answer.



[This message has been edited by nexusone (edited 12-26-2002).]

Mystery
12-26-2002, 11:22 PM
Infact I'm trying to run two closed programs. My base program is not a graffical program. But I want to see what it is doing. It is a timestepped program. It updates all data according to time. I can take the updated values to opengl. I have no problem with it. But I dont want to use
glutMainLoop() cause it stops my other program.
Opengl is the child wimdow. It only draws the updated values.

I'll try the thing you suggested.
thank you

Deiussum
12-27-2002, 05:34 AM
You keep saying, "two programs" yet you seem to be inferring that you have all the code in a single executable. Generally two separate programs would actually be considered two separate executables. What it sounds like you've actually got is a single program with two windows.

Anyway, the simplest thing for you to do might be just create a separate thread for the glut-based app. It isn't necessarily the best way, but it should work and be fairly simple to implement once you learn how to create a new thread. (Look at the CreateThread function in the Win32 API.)

Mystery
12-29-2002, 11:53 PM
It seems that it is the best way to create a thread. I'll try it...

Thank you...