Open GL Program Instances....

How do you make sure that there is only one instance of your program running?

Not really OpenGL related but, there are several ways to do that. Assuming Windows, one way is to broadcast a custom defined message and see if any apps respond. You could also enumerate the names of the various open windows, and check them. Or enumerate the currently running processes.
You could also check for an app defined global atom, and create it if it is not present. Just be sure to always destroy the atom, even when the app crashes.

[This message has been edited by DFrey (edited 10-16-2000).]

How exactly would you go about doing that?

In former times the parameter hPrevInstance in your WinMain() function indicated that.

No this is what Microsoft recommends in the MSDN: (msdn.microsoft.com search for WinMain)
>>>
hPrevInstance
[in] Handle to the previous instance of the application. For a Win32-based application, this parameter is always NULL.
If you need to detect whether another instance already exists, create a uniquely named mutex using the CreateMutex function. CreateMutex will succeed even if the mutex already exists, but the GetLastError function will return ERROR_ALREADY_EXISTS. This indicates that another instance of your application exists, because it created the mutex first.
<<<

Not to be annoying or anything but i dont really understand all that…i am still a beginner so could you explain a bit more?

Something like:

hmutex=CreateMutex(NULL,FALSE,“MYAPPMUTEX”);
if(!hmutex | | GetLastError()==ERROR_ALREADY_EXISTS)
return FALSE;

Where hmutex is a HANDLE. Also make sure you destroy the mutex handle when the program exits (normally or abnormally) by calling CloseHandle(hmutex); Windows should automatically close the handle when the program exits but I don’t trust it.

You should probably also use a better mutex name than MYAPPMUTEX.

[This message has been edited by DFrey (edited 10-18-2000).]