Logo Search packages:      
Sourcecode: fceux version File versions  Download package

int InitVideo ( FCEUGI *  gi  ) 

Attempts to initialize the graphical video display. Returns 0 on success, -1 on failure.

Definition at line 138 of file sdl-video.cpp.

References GetXScale().

Referenced by ToggleFS().

{
    // XXX soules - const?  is this necessary?
    const SDL_VideoInfo *vinf;
    int error, flags = 0;
    int doublebuf, xstretch, ystretch, xres, yres;
    

    FCEUI_printf("Initializing video...");

    // load the relevant configuration variables
    g_config->getOption("SDL.Fullscreen", &s_fullscreen);
    g_config->getOption("SDL.DoubleBuffering", &doublebuf);
#ifdef OPENGL
    g_config->getOption("SDL.OpenGL", &s_useOpenGL);
#endif
    g_config->getOption("SDL.SpecialFilter", &s_sponge);
    g_config->getOption("SDL.XStretch", &xstretch);
    g_config->getOption("SDL.YStretch", &ystretch);
    g_config->getOption("SDL.XResolution", &xres);
    g_config->getOption("SDL.YResolution", &yres);
    g_config->getOption("SDL.ClipSides", &s_clipSides);
    g_config->getOption("SDL.NoFrame", &noframe);

    // check the starting, ending, and total scan lines
    FCEUI_GetCurrentVidSystem(&s_srendline, &s_erendline);
    s_tlines = s_erendline - s_srendline + 1;
    


    // check for OpenGL and set the global flags
#if OPENGL
    if(s_useOpenGL && !s_sponge) {
        flags = SDL_OPENGL;
    }
#endif

    // initialize the SDL video subsystem if it is not already active
    if(!SDL_WasInit(SDL_INIT_VIDEO)) {
        error = SDL_InitSubSystem(SDL_INIT_VIDEO);
        if(error) {
            FCEUD_PrintError(SDL_GetError());
            return -1;
        }
    }
    s_inited = 1;

    // shows the cursor within the display window
    SDL_ShowCursor(1);

    // determine if we can allocate the display on the video card
    vinf = SDL_GetVideoInfo();
    if(vinf->hw_available) {
        flags |= SDL_HWSURFACE;
    }
    
    // check if we are rendering fullscreen
    if(s_fullscreen) {
        flags |= SDL_FULLSCREEN;
    }
    
    if(noframe) {
        flags |= SDL_NOFRAME;
    }

    // gives the SDL exclusive palette control... ensures the requested colors
    flags |= SDL_HWPALETTE;


    // enable double buffering if requested and we have hardware support
#ifdef OPENGL
    if(s_useOpenGL) {
        FCEU_printf("Initializing with OpenGL (Disable with '-opengl 0').\n");
        if(doublebuf) {
            SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
        }
    } else
#endif
        if(doublebuf && (flags & SDL_HWSURFACE)) {
            flags |= SDL_DOUBLEBUF;
        }

    if(s_fullscreen) {
        int desbpp, autoscale;
        g_config->getOption("SDL.BitsPerPixel", &desbpp);
        g_config->getOption("SDL.AutoScale", &autoscale);
        if (autoscale)
        {
            double auto_xscale = GetXScale(xres);
            double auto_yscale = GetYScale(yres);
            double native_ratio = ((double)NWIDTH) / s_tlines;
            double screen_ratio = ((double)xres) / yres;
            int keep_ratio;
            
            g_config->getOption("SDL.KeepRatio", &keep_ratio);
            
            // Try to choose resolution
            if (screen_ratio < native_ratio)
            {
                // The screen is narrower than the original. Maximizing width will not clip
                auto_xscale = auto_yscale = GetXScale(xres);
                if (keep_ratio) 
                    auto_yscale = GetYScale(yres);
            }
            else
            {
                auto_yscale = auto_xscale = GetYScale(yres);
                if (keep_ratio) 
                    auto_xscale = GetXScale(xres);
            }
            s_exs = auto_xscale;
            s_eys = auto_yscale;
        }
        else
        {
            g_config->getOption("SDL.XScale", &s_exs);
            g_config->getOption("SDL.YScale", &s_eys);
        }
        
        g_config->getOption("SDL.SpecialFX", &s_eefx);

#ifdef OPENGL
        if(!s_useOpenGL) {
            s_exs = (int)s_exs;
            s_eys = (int)s_eys;
        } else {
            desbpp = 0;
        }

        if(s_sponge) {
            if(s_sponge == 3 || s_sponge == 4) {
                s_exs = s_eys = 3;
            } else {
                s_exs = s_eys = 2;
            }
            s_eefx = 0;
            if(s_sponge == 1 || s_sponge == 3) {
                desbpp = 32;
            }
        }

        if((s_useOpenGL && !xstretch) || !s_useOpenGL)
#endif
            if(xres < (NWIDTH * s_exs) || s_exs <= 0.01) {
                FCEUD_PrintError("xscale out of bounds.");
                KillVideo();
                return -1;
            }

#ifdef OPENGL
        if((s_useOpenGL && !ystretch) || !s_useOpenGL)
#endif
            if(yres < s_tlines * s_eys || s_eys <= 0.01) {
                FCEUD_PrintError("yscale out of bounds.");
                KillVideo();
                return -1;
            }


        s_screen = SDL_SetVideoMode(xres, yres, desbpp, flags);
        if(!s_screen) {
            FCEUD_PrintError(SDL_GetError());
            return -1;
        }
    } else {
        int desbpp;
        g_config->getOption("SDL.BitsPerPixel", &desbpp);

        g_config->getOption("SDL.XScale", &s_exs);
        g_config->getOption("SDL.YScale", &s_eys);
        g_config->getOption("SDL.SpecialFX", &s_eefx);

        if(s_sponge) {
            if(s_sponge >= 3) {
                s_exs = s_eys = 3;
            } else {
                s_exs = s_eys = 2;
            }
            s_eefx = 0;
        }

#ifdef OPENGL
        if(!s_useOpenGL) {
            s_exs = (int)s_exs;
            s_eys = (int)s_eys;
        }
        if(s_exs <= 0.01) {
            FCEUD_PrintError("xscale out of bounds.");
            KillVideo();
            return -1;
        }
        if(s_eys <= 0.01) {
            FCEUD_PrintError("yscale out of bounds.");
            KillVideo();
            return -1;
        }
#endif
        
        s_screen = SDL_SetVideoMode((int)(NWIDTH * s_exs),
                                  (int)(s_tlines * s_eys),
                                  desbpp, flags);
        if(!s_screen) {
            FCEUD_PrintError(SDL_GetError());
            return -1;
        }
    }
    s_curbpp = s_screen->format->BitsPerPixel;
    if(!s_screen) {
        FCEUD_PrintError(SDL_GetError());
        KillVideo();
        return -1;
    }

#if 0
    // XXX soules - this would be creating a surface on the video
    //              card, but was commented out for some reason...
    s_BlitBuf = SDL_CreateRGBSurface(SDL_HWSURFACE, 256, 240,
                                     s_screen->format->BitsPerPixel,
                                     s_screen->format->Rmask,
                                     s_screen->format->Gmask,
                                     s_screen->format->Bmask, 0);
#endif

    FCEU_printf(" Video Mode: %d x %d x %d bpp %s\n",
                s_screen->w, s_screen->h, s_screen->format->BitsPerPixel,
                s_fullscreen ? "full screen" : "");

    if(s_curbpp != 8 && s_curbpp != 16 && s_curbpp != 24 && s_curbpp != 32) {
        FCEU_printf("  Sorry, %dbpp modes are not supported by FCE Ultra.  Supported bit depths are 8bpp, 16bpp, and 32bpp.\n", s_curbpp);
        KillVideo();
        return -1;
    }

    // if the game being run has a name, set it as the window name
    if(gi->name) {
        SDL_WM_SetCaption((const char *)gi->name, (const char *)gi->name);
    } else {
        SDL_WM_SetCaption(FCEU_NAME_AND_VERSION,"FCE Ultra");
    }

    // create the surface for displaying graphical messages
#ifdef LSB_FIRST
    s_IconSurface = SDL_CreateRGBSurfaceFrom((void *)fceu_playicon.pixel_data,
                                             32, 32, 24, 32 * 3,
                                             0xFF, 0xFF00, 0xFF0000, 0x00);
#else
    s_IconSurface = SDL_CreateRGBSurfaceFrom((void *)fceu_playicon.pixel_data,
                                             32, 32, 24, 32 * 3,
                                             0xFF0000, 0xFF00, 0xFF, 0x00);
#endif
    SDL_WM_SetIcon(s_IconSurface,0);
    s_paletterefresh = 1;

    // XXX soules - can't SDL do this for us?
    // if using more than 8bpp, initialize the conversion routines
    if(s_curbpp > 8) {
        InitBlitToHigh(s_curbpp >> 3,
                           s_screen->format->Rmask,
                           s_screen->format->Gmask,
                           s_screen->format->Bmask,
                           s_eefx, s_sponge);
#ifdef OPENGL
        if(s_useOpenGL) 
        {
            int openGLip;
            g_config->getOption("SDL.OpenGLip", &openGLip);

            if(!InitOpenGL(NOFFSET, 256 - (s_clipSides ? 8 : 0),
                           s_srendline, s_erendline + 1,
                        s_exs, s_eys, s_eefx,
                        openGLip, xstretch, ystretch, s_screen)) 
            {
                FCEUD_PrintError("Error initializing OpenGL.");
                KillVideo();
                return -1;
            }
        }
#endif
    }
    return 0;
}


Generated by  Doxygen 1.6.0   Back to index