⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdl_ph_video.c

📁 Simple DirectMedia Layer - Simple DirectMedia Layer 是一个跨平台的多媒体库设计用来提供快速图形framebuffer和音频驱动。应用MPEG为软件
💻 C
📖 第 1 页 / 共 2 页
字号:
               desktoppal=SDLPH_PAL_SYSTEM;            }                        /* save old video mode caps */            PgGetVideoMode(&settings);            old_video_mode=settings.mode;            old_refresh_rate=settings.refresh;            /* setup new video mode */            settings.mode = mode;            settings.refresh = 0;            settings.flags = 0;            if (PgSetVideoMode(&settings) < 0)            {                fprintf(stderr,"ph_SetVideoMode(): PgSetVideoMode failed !\n");            }            current->flags = (flags & (~SDL_RESIZABLE)); /* no resize for Direct Context */            /* Begin direct mode */            ph_EnterFullScreen(this);        } /* end fullscreen flag */        else        {            /* Use offscreen memory iff SDL_HWSURFACE flag is set */            if (flags & SDL_HWSURFACE)            {                /* no stretch blit in offscreen context */                current->flags = (flags & (~SDL_RESIZABLE));            }            /* using palette emulation code in window mode */            if (bpp==8)            {                if (desktopbpp>=15)                {                    desktoppal=SDLPH_PAL_EMULATE;                }                else                {                    desktoppal=SDLPH_PAL_SYSTEM;                }            }            else            {               desktoppal=SDLPH_PAL_NONE;            }        }	/* If we are setting video to use the palette make sure we have allocated memory for it */	if (bpp==8)	{            current->format->palette = malloc(sizeof(SDL_Palette));            memset(current->format->palette, 0, sizeof(SDL_Palette));            current->format->palette->ncolors = 256;            current->format->palette->colors = (SDL_Color *)malloc(256 *sizeof(SDL_Color));            /* fill the palette */            rtnval = PgGetPalette(ph_palette);            tempptr = (unsigned long *)current->format->palette->colors;            for(i=0; i<256; i++)            {                *tempptr = (((unsigned long)ph_palette[i]) << 8);                tempptr++;            }        }    }    current->w = width;    current->h = height;    current->format->BitsPerPixel = bpp;    current->format->BytesPerPixel = (bpp+7)/8;    current->pitch = SDL_CalculatePitch(current);    /* Must call at least once it setup image planes */    rtnval = ph_ResizeImage(this, current, flags);        if (rtnval==-1)    {        fprintf(stderr,"ph_SetVideoMode(): ph_ResizeImage failed !\n");        return NULL;    }    /* delayed set caption call */    if (captionflag)    {        ph_SetCaption(this, this->wm_title, NULL);    }    /* finish window drawing */    PtFlush();    SDL_Unlock_EventThread();    /* We're done! */    return (current);}static void ph_VideoQuit(_THIS){#ifdef HAVE_OPENGL    PhRegion_t region_info;#endif /* HAVE_OPENGL */    ph_DestroyImage(this, SDL_VideoSurface);     if (currently_fullscreen)    {        ph_LeaveFullScreen(this);    }#ifdef HAVE_OPENGL    /* prevent double SEGFAULT during parachute mode */    if (this->screen)    {        if (((this->screen->flags & SDL_FULLSCREEN)==SDL_FULLSCREEN) &&            ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL))        {            region_info.cursor_type=Ph_CURSOR_POINTER;            region_info.rid=PtWidgetRid(window);            PhRegionChange(Ph_REGION_CURSOR, 0, &region_info, NULL, NULL);        }    }    PtFlush();#endif /* HAVE_OPENGL */        if (window)    {        PtUnrealizeWidget(window);        PtDestroyWidget(window);        window=NULL;    }        /* restore palette */    if (desktoppal!=SDLPH_PAL_NONE)    {        PgSetPalette(ph_palette, 0, 0, _Pg_MAX_PALETTE, Pg_PALSET_GLOBAL | Pg_PALSET_FORCE_EXPOSE, 0);    }#ifdef HAVE_OPENGL    if (oglctx)    {        PhDCSetCurrent(NULL);        PhDCRelease(oglctx);        oglctx=NULL;    }#endif /* HAVE_OPENGL */}static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors){    int i;    PhPoint_t point={0, 0};    PgColor_t syspalph[_Pg_MAX_PALETTE];    /* palette emulation code, using palette of the PhImage_t struct */    if (desktoppal==SDLPH_PAL_EMULATE)    {        if ((SDL_Image) && (SDL_Image->palette))        {            for (i=firstcolor; i<firstcolor+ncolors; i++)            {                SDL_Image->palette[i]  = 0x00000000UL;                SDL_Image->palette[i] |= colors[i-firstcolor].r<<16;                SDL_Image->palette[i] |= colors[i-firstcolor].g<<8;                SDL_Image->palette[i] |= colors[i-firstcolor].b;            }           /* image needs to be redrawed, very slow method */           PgDrawPhImage(&point, SDL_Image, 0);        }    }    else    {        if (desktoppal==SDLPH_PAL_SYSTEM)        {            for (i=firstcolor; i<firstcolor+ncolors; i++)            {                syspalph[i]  = 0x00000000UL;                syspalph[i] |= colors[i-firstcolor].r<<16;                syspalph[i] |= colors[i-firstcolor].g<<8;                syspalph[i] |= colors[i-firstcolor].b;            }            if ((this->screen->flags & SDL_FULLSCREEN) != SDL_FULLSCREEN)            {                /* window mode must use soft palette */                PgSetPalette((PgColor_t*)&syspalph[firstcolor], 0, firstcolor, ncolors, Pg_PALSET_SOFT, 0);                /* image needs to be redrawed, very slow method */                if (SDL_Image)                {                   PgDrawPhImage(&point, SDL_Image, 0);                }            }            else            {                /* fullscreen mode must use hardware palette */                PgSetPalette((PgColor_t*)&syspalph[firstcolor], 0, firstcolor, ncolors, Pg_PALSET_GLOBAL, 0);            }        }        else        {            /* SDLPH_PAL_NONE do nothing */        }    }        return 1;}#ifdef HAVE_OPENGLint ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags){    PtArg_t args[8];    PhDim_t dim;    uint64_t OGLAttrib[PH_OGL_MAX_ATTRIBS];    int OGLargc;    int pargc;    dim.w=width;    dim.h=height;        if (oglctx!=NULL)    {       PhDCSetCurrent(NULL);       PhDCRelease(oglctx);       oglctx=NULL;    }    OGLargc=0;    if (this->gl_config.depth_size)    {        OGLAttrib[OGLargc++]=PHOGL_ATTRIB_DEPTH_BITS;        OGLAttrib[OGLargc++]=this->gl_config.depth_size;    }    if (this->gl_config.stencil_size)    {        OGLAttrib[OGLargc++]=PHOGL_ATTRIB_STENCIL_BITS;        OGLAttrib[OGLargc++]=this->gl_config.stencil_size;    }    OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FORCE_SW;    if (flags & SDL_FULLSCREEN)    {        OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FULLSCREEN;        OGLAttrib[OGLargc++]=PHOGL_ATTRIB_DIRECT;        OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FULLSCREEN_BEST;        OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FULLSCREEN_CENTER;    }    OGLAttrib[OGLargc++]=PHOGL_ATTRIB_NONE;    if (this->gl_config.double_buffer)    {        oglctx=PdCreateOpenGLContext(2, &dim, 0, OGLAttrib);    }    else    {        oglctx=PdCreateOpenGLContext(1, &dim, 0, OGLAttrib);    }    if (oglctx==NULL)    {        fprintf(stderr,"ph_SetupOpenGLContext(): cannot create OpenGL context.\n");        return (-1);    }    PhDCSetCurrent(oglctx);    pargc=0;    PtSetArg(&args[pargc++], Pt_ARG_DIM, &dim, 0);    PtSetArg(&args[pargc++], Pt_ARG_RESIZE_FLAGS, Pt_FALSE, Pt_RESIZE_XY_AS_REQUIRED);    PtSetArg(&args[pargc++], Pt_ARG_FILL_COLOR, Pg_BLACK, 0);    if (flags & SDL_FULLSCREEN)    {        PhPoint_t pos;        pos.x=0;        pos.y=0;        PtSetArg(&args[pargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, ~0);        PtSetArg(&args[pargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE, Ph_WM_FFRONT | Ph_WM_CLOSE | Ph_WM_TOFRONT | Ph_WM_CONSWITCH);        PtSetArg(&args[pargc++], Pt_ARG_WINDOW_STATE, Pt_TRUE, Ph_WM_STATE_ISFRONT | Ph_WM_STATE_ISFOCUS);        PtSetArg(&args[pargc++], Pt_ARG_POS, &pos, 0);    }    else    {        /* remove border and caption if no frame flag selected */        if ((flags & SDL_NOFRAME) == SDL_NOFRAME)        {            PtSetArg(&args[pargc++], Pt_ARG_WINDOW_RENDER_FLAGS, 0, Ph_WM_RENDER_TITLE | Ph_WM_RENDER_BORDER);        }        else        {           /* if window is not resizable then remove resize handles */           if ((flags & SDL_RESIZABLE) != SDL_RESIZABLE)           {               PtSetArg(&args[pargc++], Pt_ARG_WINDOW_RENDER_FLAGS, 0, Ph_WM_RENDER_RESIZE);           }        }    }    if (window!=NULL)    {        PtUnrealizeWidget(window);        PtDestroyWidget(window);        window=NULL;    }    window=PtCreateWidget(PtWindow, NULL, pargc, args);    PtRealizeWidget(window);    /* disable mouse for fullscreen */    if (flags & SDL_FULLSCREEN)    {        PhRegion_t region_info;        region_info.cursor_type=Ph_CURSOR_NONE;        region_info.rid=PtWidgetRid(window);        PhRegionChange(Ph_REGION_CURSOR, 0, &region_info, NULL, NULL);    }    PtFlush();    return 0;}void ph_GL_SwapBuffers(_THIS){    PgSetRegion(PtWidgetRid(window));    PdOpenGLContextSwapBuffers(oglctx);}int ph_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value){    switch (attrib)    {        case SDL_GL_DOUBLEBUFFER:             *value=this->gl_config.double_buffer;             break;        case SDL_GL_STENCIL_SIZE:             *value=this->gl_config.stencil_size;             break;        case SDL_GL_DEPTH_SIZE:             *value=this->gl_config.depth_size;             break;        default:             *value=0;             return(-1);    }    return 0;}#endif /* HAVE_OPENGL */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -