Example #1
0
int
main(int argc, char *argv[])
{
   struct thread_init_arg tia[MAX_WINDOWS];
   struct window *h[MAX_WINDOWS];
   HANDLE threads[MAX_WINDOWS];
   int i;

   terminate = CreateEvent(NULL, TRUE, FALSE, NULL);

   if (initMainthread())
      return -1;

   /* four windows and contexts sharing display lists and texture objects */
   h[0] = AddWindow( 10,  10, gCtx);
   h[1] = AddWindow(330,  10, gCtx);
   h[2] = AddWindow( 10, 350, gCtx);
   h[3] = AddWindow(330, 350, gCtx);

   for (i = 0; i < NumWindows; i++) {
      Windows[i].hEventInitialised = CreateEvent(NULL, TRUE, FALSE, NULL);
   }

   for (i = 0; i < NumWindows; i++) {
      DWORD id;

      tia[i].id = i;
      threads[i] = CreateThread(NULL, 0, threadRunner, &tia[i], 0, &id);

      WaitForSingleObject(Windows[i].hEventInitialised, INFINITE);
   }

   if (!wglMakeCurrent(gHDC, gCtx)) {
      Error("wglMakeCurrent failed for init thread.");
      return -1;
   }

   InitGLstuff();

   while (1) {
      MSG msg;

      /* wait 1 ms for signal either to exit or process messages */
      switch (MsgWaitForMultipleObjects(NumWindows, threads, TRUE, 1, QS_ALLINPUT)) {
      case WAIT_OBJECT_0:
         return 0;
      }

      while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
         if (msg.message == WM_QUIT) {
            return 0;
         }
         TranslateMessage(&msg);
         DispatchMessage(&msg);
      }
   }

   return 0;
}
Example #2
0
int
main(int argc, char *argv[])
{
   const char *dpyName = XDisplayName(NULL);
   pthread_t t0, t1, t2, t3;
   struct thread_init_arg tia0, tia1, tia2, tia3;
   struct window *h0;

   XInitThreads();

   gDpy = XOpenDisplay(dpyName);
   if (!gDpy) {
      Error(dpyName, "Unable to open display");
      return -1;
   }

   if (initMainthread(gDpy, dpyName))
      return -1;

   /* four windows and contexts sharing display lists and texture objects */
   h0 = AddWindow(gDpy, dpyName,  10,  10, gCtx);
   (void) AddWindow(gDpy, dpyName, 330,  10, gCtx);
   (void) AddWindow(gDpy, dpyName,  10, 350, gCtx);
   (void) AddWindow(gDpy, dpyName, 330, 350, gCtx);

   if (!glXMakeCurrent(gDpy, h0->Win, gCtx)) {
      Error(dpyName, "glXMakeCurrent failed for init thread.");
      return -1;
   }

   InitGLstuff();

   tia0.id = 0;
   pthread_create(&t0, NULL, threadRunner, &tia0);
   tia1.id = 1;
   pthread_create(&t1, NULL, threadRunner, &tia1);
   tia2.id = 2;
   pthread_create(&t2, NULL, threadRunner, &tia2);
   tia3.id = 3;
   pthread_create(&t3, NULL, threadRunner, &tia3);
   EventLoop();
   return 0;
}