static void SDLGL_BeginRendering(void *obj) { AG_DriverSDLGL *sgl = obj; #if defined(AG_THREADS) && defined(HAVE_GETTIMEOFDAY) && \ defined(HAVE_CLOCK_GETTIME) && !defined(HAVE_CYGWIN) { extern AG_Cond agCondBeginRender; /* Suspend any AG_Delay()'ed threads. */ AG_CondBroadcast(&agCondBeginRender); } #endif glPushAttrib(GL_VIEWPORT_BIT|GL_TRANSFORM_BIT|GL_LIGHTING_BIT| GL_ENABLE_BIT); if (AGDRIVER_SW(sgl)->flags & AG_DRIVER_SW_OVERLAY) { AG_GL_InitContext( AG_RECT(0, 0, AGDRIVER_SW(sgl)->w, AGDRIVER_SW(sgl)->h)); } else { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); } sgl->clipStates[0] = glIsEnabled(GL_CLIP_PLANE0); glEnable(GL_CLIP_PLANE0); sgl->clipStates[1] = glIsEnabled(GL_CLIP_PLANE1); glEnable(GL_CLIP_PLANE1); sgl->clipStates[2] = glIsEnabled(GL_CLIP_PLANE2); glEnable(GL_CLIP_PLANE2); sgl->clipStates[3] = glIsEnabled(GL_CLIP_PLANE3); glEnable(GL_CLIP_PLANE3); }
static void SDLGL_BeginRendering(void *obj) { AG_DriverSDLGL *sgl = obj; AG_GL_Context *gl = &sgl->gl; glPushAttrib(GL_VIEWPORT_BIT|GL_TRANSFORM_BIT|GL_LIGHTING_BIT| GL_ENABLE_BIT); if (AGDRIVER_SW(sgl)->flags & AG_DRIVER_SW_OVERLAY) { AG_Driver *drv = obj; /* Reinitialize Agar's OpenGL context. */ if (drv->gl != NULL) { AG_GL_DestroyContext(drv); } if (AG_GL_InitContext(drv, gl) == -1) { AG_FatalError(NULL); } AG_GL_SetViewport(gl, AG_RECT(0, 0, AGDRIVER_SW(sgl)->w, AGDRIVER_SW(sgl)->h)); } else { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); } gl->clipStates[0] = glIsEnabled(GL_CLIP_PLANE0); glEnable(GL_CLIP_PLANE0); gl->clipStates[1] = glIsEnabled(GL_CLIP_PLANE1); glEnable(GL_CLIP_PLANE1); gl->clipStates[2] = glIsEnabled(GL_CLIP_PLANE2); glEnable(GL_CLIP_PLANE2); gl->clipStates[3] = glIsEnabled(GL_CLIP_PLANE3); glEnable(GL_CLIP_PLANE3); }
static void SDLGL_EndRendering(void *drv) { AG_DriverSDLGL *sgl = drv; AG_GL_Context *gl = &sgl->gl; /* Render to specified capture output. */ if (sgl->outMode != AG_SDLGL_OUT_NONE) SDLGL_CaptureOutput(sgl); glPopAttrib(); if (AGDRIVER_SW(sgl)->flags & AG_DRIVER_SW_OVERLAY) { /* * Restore the OpenGL state exactly to its former state * (all textures are display lists are deleted). */ AG_GL_DestroyContext(gl); } else { SDL_GL_SwapBuffers(); if (gl->clipStates[0]) { glEnable(GL_CLIP_PLANE0); } else { glDisable(GL_CLIP_PLANE0); } if (gl->clipStates[1]) { glEnable(GL_CLIP_PLANE1); } else { glDisable(GL_CLIP_PLANE1); } if (gl->clipStates[2]) { glEnable(GL_CLIP_PLANE2); } else { glDisable(GL_CLIP_PLANE2); } if (gl->clipStates[3]) { glEnable(GL_CLIP_PLANE3); } else { glDisable(GL_CLIP_PLANE3); } } }
static void SDLGL_EndRendering(void *drv) { AG_DriverSDLGL *sgl = drv; Uint i; /* Render to specified capture output. */ if (sgl->outMode != AG_SDLGL_OUT_NONE) SDLGL_CaptureOutput(sgl); if (!(AGDRIVER_SW(sgl)->flags & AG_DRIVER_SW_OVERLAY)) { SDL_GL_SwapBuffers(); if (sgl->clipStates[0]) { glEnable(GL_CLIP_PLANE0); } else { glDisable(GL_CLIP_PLANE0); } if (sgl->clipStates[1]) { glEnable(GL_CLIP_PLANE1); } else { glDisable(GL_CLIP_PLANE1); } if (sgl->clipStates[2]) { glEnable(GL_CLIP_PLANE2); } else { glDisable(GL_CLIP_PLANE2); } if (sgl->clipStates[3]) { glEnable(GL_CLIP_PLANE3); } else { glDisable(GL_CLIP_PLANE3); } } glPopAttrib(); /* Remove textures and display lists queued for deletion. */ glDeleteTextures(sgl->nTextureGC, sgl->textureGC); for (i = 0; i < sgl->nListGC; i++) { glDeleteLists(sgl->listGC[i], 1); } sgl->nTextureGC = 0; sgl->nListGC = 0; #if defined(AG_THREADS) && defined(HAVE_GETTIMEOFDAY) && \ defined(HAVE_CLOCK_GETTIME) && !defined(HAVE_CYGWIN) { extern AG_Cond agCondEndRender; /* Resume any AG_Delay()'ed threads. */ AG_CondBroadcast(&agCondEndRender); } #endif }
/* * Initialize Agar with an existing SDL display. If the display surface has * flags SDL_OPENGL / SDL_OPENGLBLIT set, the "sdlgl" driver is selected; * otherwise, the "sdlfb" driver is used. */ int AG_InitVideoSDL(void *pDisplay, Uint flags) { SDL_Surface *display = pDisplay; AG_Driver *drv = NULL; AG_DriverClass *dc = NULL; int useGL = 0; int i; if (AG_InitGUIGlobals() == -1) return (-1); /* Enable OpenGL mode if the surface has SDL_OPENGL set. */ if (display->flags & (SDL_OPENGL|SDL_OPENGLBLIT)) { if (flags & AG_VIDEO_SDL) { AG_SetError("AG_VIDEO_SDL flag requested, but " "display surface has SDL_OPENGL set"); goto fail; } useGL = 1; } else { if (flags & AG_VIDEO_OPENGL) { AG_SetError("AG_VIDEO_OPENGL flag requested, but " "display surface is missing SDL_OPENGL"); goto fail; } } for (i = 0; i < agDriverListSize; i++) { dc = agDriverList[i]; if (dc->wm == AG_WM_SINGLE && (dc->flags & AG_DRIVER_SDL) && (!useGL || (dc->flags & AG_DRIVER_OPENGL)) && (drv = AG_DriverOpen(dc)) != NULL) break; } if (i == agDriverListSize) { AG_SetError("No compatible SDL driver is available"); goto fail; } /* Open a video display. */ if (AGDRIVER_SW_CLASS(drv)->openVideoContext(drv, (void *)display, flags) == -1) { AG_DriverClose(drv); goto fail; } if (drv->videoFmt == NULL) AG_FatalError("Driver did not set video format"); /* Generic Agar-GUI initialization. */ if (AG_InitGUI(0) == -1) { AG_DriverClose(drv); goto fail; } agDriverOps = dc; agDriverSw = AGDRIVER_SW(drv); #ifdef AG_LEGACY agView = drv; #endif return (0); fail: AG_DestroyGUIGlobals(); return (-1); }
static int SDLGL_OpenVideo(void *obj, Uint w, Uint h, int depth, Uint flags) { char buf[16]; AG_Driver *drv = obj; AG_DriverSw *dsw = obj; AG_DriverSDLGL *sgl = obj; Uint32 sFlags = SDL_OPENGL; int newDepth; /* Set the requested display options. */ if (flags & AG_VIDEO_RESIZABLE) { sFlags |= SDL_RESIZABLE; } if (flags & AG_VIDEO_ANYFORMAT) { sFlags |= SDL_ANYFORMAT; } if (flags & AG_VIDEO_HWPALETTE) { sFlags |= SDL_HWPALETTE; } if (flags & AG_VIDEO_DOUBLEBUF) { sFlags |= SDL_DOUBLEBUF; } if (flags & AG_VIDEO_FULLSCREEN) { sFlags |= SDL_FULLSCREEN; } if (flags & AG_VIDEO_NOFRAME) { sFlags |= SDL_NOFRAME; } if (flags & AG_VIDEO_OVERLAY) dsw->flags |= AG_DRIVER_SW_OVERLAY; if (flags & AG_VIDEO_BGPOPUPMENU) dsw->flags |= AG_DRIVER_SW_BGPOPUP; /* Apply the output capture settings. */ if (AG_Defined(drv, "out")) { char *ext; AG_GetString(drv, "out", buf, sizeof(buf)); if ((ext = strrchr(buf, '.')) != NULL && ext[1] != '\0') { if (Strcasecmp(&ext[1], "jpeg") == 0 || Strcasecmp(&ext[1], "jpg") == 0) { sgl->outMode = AG_SDLGL_OUT_JPEG; if ((sgl->outPath = TryStrdup(buf)) == NULL) return (-1); } else if (Strcasecmp(&ext[1], "png") == 0) { sgl->outMode = AG_SDLGL_OUT_PNG; if ((sgl->outPath = TryStrdup(buf)) == NULL) return (-1); } else { AG_SetError("Invalid out= argument: `%s'", buf); return (-1); } if (AG_Defined(drv, "outFirst")) { AG_GetString(drv, "outFirst", buf, sizeof(buf)); sgl->outFrame = atoi(buf); } else { sgl->outFrame = 0; } if (AG_Defined(drv, "outLast")) { AG_GetString(drv, "outLast", buf, sizeof(buf)); sgl->outLast = atoi(buf); } } } /* Apply the default resolution settings. */ if (w == 0 && AG_Defined(drv, "width")) { AG_GetString(drv, "width", buf, sizeof(buf)); w = atoi(buf); } if (h == 0 && AG_Defined(drv, "height")) { AG_GetString(drv, "height", buf, sizeof(buf)); h = atoi(buf); } if (depth == 0 && AG_Defined(drv, "depth")) { AG_GetString(drv, "depth", buf, sizeof(buf)); depth = atoi(buf); } /* Set the video mode. Force hardware palette in 8bpp. */ Verbose(_("SDLGL: Setting mode %dx%d (%d bpp)\n"), w, h, depth); newDepth = SDL_VideoModeOK(w, h, depth, sFlags); if (newDepth == 8) { Verbose(_("Enabling hardware palette")); sFlags |= SDL_HWPALETTE; } if ((sgl->s = SDL_SetVideoMode((int)w, (int)h, newDepth, sFlags)) == NULL) { AG_SetError("Setting %dx%dx%d mode: %s", w, h, newDepth, SDL_GetError()); return (-1); } SDL_EnableUNICODE(1); if ((drv->videoFmt = AG_SDL_GetPixelFormat(sgl->s)) == NULL) { goto fail; } dsw->w = sgl->s->w; dsw->h = sgl->s->h; dsw->depth = (Uint)drv->videoFmt->BitsPerPixel; Verbose(_("SDLGL: New display (%dbpp)\n"), (int)drv->videoFmt->BitsPerPixel); /* Initialize clipping rectangles. */ if (InitClipRects(sgl, dsw->w, dsw->h) == -1) goto fail; /* Create the cursors. */ if (AG_SDL_InitDefaultCursor(sgl) == -1 || AG_InitStockCursors(drv) == -1) goto fail; /* Initialize the GL viewport. */ AG_GL_InitContext( AG_RECT(0, 0, AGDRIVER_SW(sgl)->w, AGDRIVER_SW(sgl)->h)); if (!(dsw->flags & AG_DRIVER_SW_OVERLAY)) { ClearBackground(); } /* Initialize the output capture buffer. */ Free(sgl->outBuf); if ((sgl->outBuf = AG_TryMalloc(dsw->w*dsw->h*4)) == NULL) { AG_Verbose("Out of memory for buffer; disabling capture\n"); sgl->outMode = AG_SDLGL_OUT_NONE; } /* Toggle fullscreen if requested. */ if (AG_CfgBool("view.full-screen")) { if (!SDL_WM_ToggleFullScreen(sgl->s)) AG_SetCfgBool("view.full-screen", 0); } return (0); fail: if (drv->videoFmt) { AG_PixelFormatFree(drv->videoFmt); drv->videoFmt = NULL; } return (-1); }
void AG_GLViewDraw(void *obj) { AG_GLView *glv = obj; AG_Driver *drv = WIDGET(glv)->drv; GLint vpSave[4]; Uint hView; glGetIntegerv(GL_VIEWPORT, vpSave); if (glv->flags & AG_GLVIEW_INIT_MATRICES) { glv->flags &= ~(AG_GLVIEW_INIT_MATRICES); SetIdentity(glv->mProjection, GL_PROJECTION); SetIdentity(glv->mModelview, GL_MODELVIEW); SetIdentity(glv->mTexture, GL_TEXTURE); } if (glv->flags & AG_GLVIEW_RESHAPE) { glv->flags &= ~(AG_GLVIEW_RESHAPE); AG_GLViewReshape(glv); } if (AGDRIVER_SINGLE(drv)) { hView = AGDRIVER_SW(drv)->h; } else { hView = HEIGHT(WIDGET(glv)->window); } glViewport(WIDGET(glv)->rView.x1, hView - WIDGET(glv)->rView.y2, WIDTH(glv), HEIGHT(glv)); glMatrixMode(GL_TEXTURE); glPushMatrix(); glLoadMatrixf(glv->mTexture); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadMatrixf(glv->mProjection); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadMatrixf(glv->mModelview); glPushAttrib(GL_TRANSFORM_BIT); glDisable(GL_CLIP_PLANE0); glDisable(GL_CLIP_PLANE1); glDisable(GL_CLIP_PLANE2); glDisable(GL_CLIP_PLANE3); if (glv->draw_ev != NULL) glv->draw_ev->handler(glv->draw_ev); glPopAttrib(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glMatrixMode(GL_TEXTURE); glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glViewport(vpSave[0], vpSave[1], vpSave[2], vpSave[3]); if (glv->overlay_ev != NULL) glv->overlay_ev->handler(glv->overlay_ev); }
void AG_GLViewDraw(void *obj) { AG_GLView *glv = obj; AG_Driver *drv = WIDGET(glv)->drv; Uint hView; if (glv->flags & AG_GLVIEW_BGFILL) { AG_DrawRect(glv, AG_RECT(0,0, WIDTH(glv), HEIGHT(glv)), glv->bgColor); } if (glv->underlay_ev != NULL) glv->underlay_ev->handler(glv->underlay_ev); glPushAttrib(GL_TRANSFORM_BIT | GL_VIEWPORT_BIT); if (glv->flags & AG_GLVIEW_INIT_MATRICES) { glv->flags &= ~(AG_GLVIEW_INIT_MATRICES); SetIdentity(glv->mProjection, GL_PROJECTION); SetIdentity(glv->mModelview, GL_MODELVIEW); SetIdentity(glv->mTexture, GL_TEXTURE); } if (glv->flags & AG_GLVIEW_RESHAPE) { glv->flags &= ~(AG_GLVIEW_RESHAPE); AG_GLViewReshape(glv); } if (AGDRIVER_SINGLE(drv)) { hView = AGDRIVER_SW(drv)->h; } else { hView = HEIGHT(WIDGET(glv)->window); } glViewport(WIDGET(glv)->rView.x1, hView - WIDGET(glv)->rView.y2, WIDTH(glv), HEIGHT(glv)); glMatrixMode(GL_TEXTURE); glPushMatrix(); glLoadMatrixf(glv->mTexture); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadMatrixf(glv->mProjection); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadMatrixf(glv->mModelview); glDisable(GL_CLIP_PLANE0); glDisable(GL_CLIP_PLANE1); glDisable(GL_CLIP_PLANE2); glDisable(GL_CLIP_PLANE3); if (glv->draw_ev != NULL) glv->draw_ev->handler(glv->draw_ev); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_TEXTURE); glPopMatrix(); /* restore transform and viewport */ glPopAttrib(); if (glv->overlay_ev != NULL) { glPushAttrib(GL_TRANSFORM_BIT); glv->overlay_ev->handler(glv->overlay_ev); glPopAttrib(); } }