static int SDLGL_Open(void *obj, const char *spec) { extern const AG_TimeOps agTimeOps_SDL; AG_Driver *drv = obj; AG_DriverSDLGL *sgl = obj; if (nDrivers != 0) { AG_SetError("Multiple SDL displays are not supported"); return (-1); } /* Initialize SDL's video subsystem. */ if (!initedSDL) { if (SDL_Init(0) == -1) { AG_SetError("SDL_Init() failed: %s", SDL_GetError()); return (-1); } initedSDL = 1; } if (!SDL_WasInit(SDL_INIT_VIDEO)) { if (SDL_InitSubSystem(SDL_INIT_VIDEO) != 0) { AG_SetError("SDL_INIT_VIDEO failed: %s", SDL_GetError()); return (-1); } initedSDLVideo = 1; } /* We can use SDL's time interface. */ if (agTimeOps == &agTimeOps_dummy) AG_SetTimeOps(&agTimeOps_SDL); /* Initialize this driver instance. */ if ((drv->mouse = AG_MouseNew(sgl, "SDL mouse")) == NULL || (drv->kbd = AG_KeyboardNew(sgl, "SDL keyboard")) == NULL) { goto fail; } sgl->outMode = AG_SDLGL_OUT_NONE; sgl->outPath = NULL; sgl->outFrame = 0; sgl->outLast = 0; sgl->outBuf = NULL; /* Configure the window caption */ SDL_WM_SetCaption(agProgName, agProgName); nDrivers = 1; return (0); fail: if (drv->kbd != NULL) { AG_ObjectDetach(drv->kbd); AG_ObjectDestroy(drv->kbd); drv->kbd = NULL; } if (drv->mouse != NULL) { AG_ObjectDetach(drv->mouse); AG_ObjectDestroy(drv->mouse); drv->mouse = NULL; } return (-1); }
static int SDLGL_Open(void *obj, const char *spec) { AG_Driver *drv = obj; AG_DriverSDLGL *sgl = obj; if (nDrivers != 0) { AG_SetError("Multiple SDL displays are not supported"); return (-1); } /* Initialize SDL's video subsystem. */ if (!initedSDL) { if (SDL_Init(0) == -1) { AG_SetError("SDL_Init() failed: %s", SDL_GetError()); return (-1); } initedSDL = 1; } if (!SDL_WasInit(SDL_INIT_VIDEO)) { if (SDL_InitSubSystem(SDL_INIT_VIDEO) != 0) { AG_SetError("SDL_INIT_VIDEO failed: %s", SDL_GetError()); return (-1); } initedSDLVideo = 1; } #if 0 /* Use SDL's time interface. */ AG_SetTimeOps(&agTimeOps_SDL); AG_DestroyEventSubsystem(); AG_InitEventSubsystem(AG_SOFT_TIMERS); #endif /* Initialize this driver instance. */ if ((drv->mouse = AG_MouseNew(sgl, "SDL mouse")) == NULL || (drv->kbd = AG_KeyboardNew(sgl, "SDL keyboard")) == NULL) { goto fail; } sgl->outMode = AG_SDLGL_OUT_NONE; sgl->outPath = NULL; sgl->outFrame = 0; sgl->outLast = 0; sgl->outBuf = NULL; /* Configure the window caption */ if (agProgName != NULL) SDL_WM_SetCaption(agProgName, agProgName); /* * TODO where AG_SINK_READ capability and pipes are available, * could we create a separate thread running SDL_WaitEvent() and * sending notifications over a pipe, instead of using a spinner? */ if ((sglEventSpinner = AG_AddEventSpinner(AG_SDL_EventSink, "%p", drv)) == NULL || (sglEventEpilogue = AG_AddEventEpilogue(AG_SDL_EventEpilogue, NULL)) == NULL) goto fail; /* Set up event filters for standard AG_EventLoop(). */ nDrivers = 1; return (0); fail: if (sglEventSpinner != NULL) { AG_DelEventSpinner(sglEventSpinner); sglEventSpinner = NULL; } if (sglEventEpilogue != NULL) { AG_DelEventEpilogue(sglEventEpilogue); sglEventEpilogue = NULL; } if (drv->kbd != NULL) { AG_ObjectDelete(drv->kbd); drv->kbd = NULL; } if (drv->mouse != NULL) { AG_ObjectDelete(drv->mouse); drv->mouse = NULL; } return (-1); }