void I_InitGraphics(void) { static int firsttime=1; if (firsttime) { firsttime = 0; atexit(I_ShutdownGraphics); lprintf(LO_INFO, "I_InitGraphics: %dx%d\n", SCREENWIDTH, SCREENHEIGHT); /* Set the video mode */ I_UpdateVideoMode(); //e6y: setup the window title I_SetWindowCaption(); //e6y: set the application icon I_SetWindowIcon(); /* Initialize the input system */ I_InitInputs(); //e6y: new mouse code UpdateFocus(); UpdateGrab(); } }
void I_Endoom(void) { #ifndef GCONSOLE // I will return to this -- Hyper_Eye unsigned char *endoom_data; unsigned char *screendata; int y; int indent; // Hack to stop crash with disk icon in_endoom = true; endoom_data = (unsigned char *)W_CacheLumpName("ENDOOM", PU_STATIC); // Set up text mode screen TXT_Init(); I_SetWindowCaption(); I_SetWindowIcon(); // Write the data to the screen memory screendata = TXT_GetScreenData(); indent = (ENDOOM_W - TXT_SCREEN_W) / 2; for (y=0; y<TXT_SCREEN_H; ++y) { memcpy(screendata + (y * TXT_SCREEN_W * 2), endoom_data + (y * ENDOOM_W + indent) * 2, TXT_SCREEN_W * 2); } // Wait for a keypress while (true) { TXT_UpdateScreen(); if (TXT_GetChar() > 0) break; TXT_Sleep(0); } // Shut down text mode screen TXT_Shutdown(); in_endoom = false; #endif // Hyper_Eye }
void I_Endoom(void) { unsigned char *endoom_data; unsigned char *screendata; int y; int indent; endoom_data = W_CacheLumpName(DEH_String("ENDOOM"), PU_STATIC); // Set up text mode screen TXT_Init(); // Make sure the new window has the right title and icon I_SetWindowCaption(); I_SetWindowIcon(); // Write the data to the screen memory screendata = TXT_GetScreenData(); indent = (ENDOOM_W - TXT_SCREEN_W) / 2; for (y=0; y<TXT_SCREEN_H; ++y) { memcpy(screendata + (y * TXT_SCREEN_W * 2), endoom_data + (y * ENDOOM_W + indent) * 2, TXT_SCREEN_W * 2); } // Wait for a keypress while (true) { TXT_UpdateScreen(); if (TXT_GetChar() > 0) { break; } TXT_Sleep(0); } // Shut down text mode screen TXT_Shutdown(); }
SDLVideo::SDLVideo(int parm) { const SDL_version *SDLVersion = SDL_Linked_Version(); if(SDLVersion->major != SDL_MAJOR_VERSION || SDLVersion->minor != SDL_MINOR_VERSION) { I_FatalError("SDL version conflict (%d.%d.%d vs %d.%d.%d dll)\n", SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL, SDLVersion->major, SDLVersion->minor, SDLVersion->patch); return; } if (SDL_InitSubSystem (SDL_INIT_VIDEO) == -1) { I_FatalError("Could not initialize SDL video.\n"); return; } if(SDLVersion->patch != SDL_PATCHLEVEL) { Printf_Bold("SDL version warning (%d.%d.%d vs %d.%d.%d dll)\n", SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL, SDLVersion->major, SDLVersion->minor, SDLVersion->patch); } // [Russell] - Just for windows, display the icon in the system menu and // alt-tab display #if WIN32 && !_XBOX HICON hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1)); if (hIcon) { HWND WindowHandle; SDL_SysWMinfo wminfo; SDL_VERSION(&wminfo.version) SDL_GetWMInfo(&wminfo); WindowHandle = wminfo.window; SendMessage(WindowHandle, WM_SETICON, ICON_SMALL, (LPARAM)hIcon); SendMessage(WindowHandle, WM_SETICON, ICON_BIG, (LPARAM)hIcon); } #endif I_SetWindowCaption(); sdlScreen = NULL; infullscreen = false; screenw = screenh = screenbits = 0; palettechanged = false; // Get Video modes SDL_PixelFormat fmt; fmt.palette = NULL; fmt.BitsPerPixel = 8; fmt.BytesPerPixel = 1; SDL_Rect **sdllist = SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_SWSURFACE); vidModeIterator = 0; vidModeIteratorBits = 8; vidModeList.clear(); if(!sdllist) { // no fullscreen modes, but we could still try windowed Printf(PRINT_HIGH, "SDL_ListModes returned NULL. No fullscreen video modes are available.\n"); return; } else if(sdllist == (SDL_Rect **)-1) { I_FatalError("SDL_ListModes returned -1. Internal error.\n"); return; } else { vidMode_t CustomVidModes[] = { { 640, 480, 8 } ,{ 640, 400, 8 } ,{ 320, 240, 8 } ,{ 320, 200, 8 } }; // Add in generic video modes reported by SDL for(int i = 0; sdllist[i]; ++i) { vidMode_t vm; vm.width = sdllist[i]->w; vm.height = sdllist[i]->h; vm.bits = 8; vidModeList.push_back(vm); } // Now custom video modes to be added for (size_t i = 0; i < STACKARRAY_LENGTH(CustomVidModes); ++i) vidModeList.push_back(CustomVidModes[i]); // Reverse sort the modes std::sort(vidModeList.begin(), vidModeList.end(), std::greater<vidMode_t>()); // Get rid of any duplicates (SDL some times reports duplicates as well) vidModeList.erase(std::unique(vidModeList.begin(), vidModeList.end()), vidModeList.end()); } }
SDLVideo::SDLVideo(int parm) { const SDL_version *SDLVersion = SDL_Linked_Version(); if(SDLVersion->major != SDL_MAJOR_VERSION || SDLVersion->minor != SDL_MINOR_VERSION) { I_FatalError("SDL version conflict (%d.%d.%d vs %d.%d.%d dll)\n", SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL, SDLVersion->major, SDLVersion->minor, SDLVersion->patch); return; } if (SDL_InitSubSystem (SDL_INIT_VIDEO) == -1) { I_FatalError("Could not initialize SDL video.\n"); return; } if(SDLVersion->patch != SDL_PATCHLEVEL) { Printf_Bold("SDL version warning (%d.%d.%d vs %d.%d.%d dll)\n", SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL, SDLVersion->major, SDLVersion->minor, SDLVersion->patch); } // [Russell] - Just for windows, display the icon in the system menu and // alt-tab display #if WIN32 && !_XBOX HICON Icon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1)); if (Icon != 0) { HWND WindowHandle; SDL_SysWMinfo wminfo; SDL_VERSION(&wminfo.version) SDL_GetWMInfo(&wminfo); WindowHandle = wminfo.window; // GhostlyDeath <October 26, 2008> -- VC6 (No Service Packs or new SDKs) has no SetClassLongPtr? #if defined(_MSC_VER) && _MSC_VER <= 1200// && !defined(_MSC_FULL_VER) SetClassLong(WindowHandle, GCL_HICON, (LONG) Icon); #else SetClassLongPtr(WindowHandle, GCL_HICON, (LONG_PTR) Icon); #endif } #endif I_SetWindowCaption(); sdlScreen = NULL; infullscreen = false; screenw = screenh = screenbits = 0; palettechanged = false; chainHead = new cChain(NULL); // Get Video modes SDL_PixelFormat fmt; fmt.palette = NULL; fmt.BitsPerPixel = 8; fmt.BytesPerPixel = 1; SDL_Rect **sdllist = SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_SWSURFACE); vidModeList = NULL; vidModeCount = 0; if(!sdllist) { // no fullscreen modes, but we could still try windowed Printf(PRINT_HIGH, "SDL_ListModes returned NULL. No fullscreen video modes are available.\n"); vidModeList = NULL; vidModeCount = 0; return; } else if(sdllist == (SDL_Rect **)-1) { I_FatalError("SDL_ListModes returned -1. Internal error.\n"); return; } else { int i; for(i = 0; sdllist[i]; i++) ; vidModeList = new vidMode[i]; vidModeCount = i; for(i = 0; sdllist[i]; i++) { vidModeList[i].width = sdllist[i]->w; vidModeList[i].height = sdllist[i]->h; vidModeList[i].bits = 8; } } }
void I_InitGraphics(void) { SDL_Event dummy; byte *doompal; int flags = 0; char *env; // Pass through the XSCREENSAVER_WINDOW environment variable to // SDL_WINDOWID, to embed the SDL window into the Xscreensaver // window. env = getenv("XSCREENSAVER_WINDOW"); if (env != NULL) { char winenv[30]; int winid; sscanf(env, "0x%x", &winid); sprintf(winenv, "SDL_WINDOWID=%i", winid); putenv(winenv); } SetSDLVideoDriver(); if (SDL_Init(SDL_INIT_VIDEO) < 0) { I_Error("Failed to initialize video: %s", SDL_GetError()); } // Check for command-line video-related parameters. CheckCommandLine(); doompal = W_CacheLumpName (DEH_String("PLAYPAL"),PU_CACHE); if (screensaver_mode) { windowwidth = 0; windowheight = 0; } else { if (autoadjust_video_settings) { I_AutoAdjustSettings(); } windowwidth = screen_width; windowheight = screen_height; screen_mode = I_FindScreenMode(windowwidth, windowheight); if (screen_mode == NULL) { I_Error("I_InitGraphics: Unable to find a screen mode small " "enough for %ix%i", windowwidth, windowheight); } if (windowwidth != screen_mode->width || windowheight != screen_mode->height) { printf("I_InitGraphics: %s (%ix%i within %ix%i)\n", WindowBoxType(screen_mode, windowwidth, windowheight), screen_mode->width, screen_mode->height, windowwidth, windowheight); } // Generate lookup tables before setting the video mode. if (screen_mode->InitMode != NULL) { screen_mode->InitMode(doompal); } } // Set up title and icon. Windows cares about the ordering; this // has to be done before the call to SDL_SetVideoMode. I_SetWindowCaption(); #if !SDL_VERSION_ATLEAST(1, 3, 0) I_SetWindowIcon(); #endif // Set the video mode. flags |= SDL_SWSURFACE | SDL_HWPALETTE | SDL_DOUBLEBUF; if (fullscreen) { flags |= SDL_FULLSCREEN; } screen = SDL_SetVideoMode(windowwidth, windowheight, 8, flags); if (screen == NULL) { I_Error("Error setting video mode: %s\n", SDL_GetError()); } // Start with a clear black screen // (screen will be flipped after we set the palette) if (SDL_LockSurface(screen) >= 0) { byte *screenpixels; int y; screenpixels = (byte *) screen->pixels; for (y=0; y<screen->h; ++y) memset(screenpixels + screen->pitch * y, 0, screen->w); SDL_UnlockSurface(screen); } // Set the palette I_SetPalette(doompal); SDL_SetColors(screen, palette, 0, 256); CreateCursors(); UpdateFocus(); UpdateGrab(); // In screensaver mode, now find a screen_mode to use. if (screensaver_mode) { screen_mode = I_FindScreenMode(screen->w, screen->h); if (screen_mode == NULL) { I_Error("I_InitGraphics: Unable to find a screen mode small " "enough for %ix%i", screen->w, screen->h); } // Generate lookup tables before setting the video mode. if (screen_mode->InitMode != NULL) { screen_mode->InitMode(doompal); } } // On some systems, it takes a second or so for the screen to settle // after changing modes. We include the option to add a delay when // setting the screen mode, so that the game doesn't start immediately // with the player unable to see anything. if (fullscreen && !screensaver_mode) { SDL_Delay(startup_delay); } // Check if we have a native surface we can use // If we have to lock the screen, draw to a buffer and copy // Likewise if the screen pitch is not the same as the width // If we have to multiply, drawing is done to a separate 320x200 buf native_surface = !SDL_MUSTLOCK(screen) && screen_mode == &mode_scale_1x && screen->pitch == SCREENWIDTH && aspect_ratio_correct; // If not, allocate a buffer and copy from that buffer to the // screen when we do an update if (native_surface) { screens[0] = (unsigned char *) screen->pixels; screens[0] += (screen->h - SCREENHEIGHT) / 2; } else { screens[0] = (unsigned char *) Z_Malloc (SCREENWIDTH * SCREENHEIGHT, PU_STATIC, NULL); } // "Loading from disk" icon LoadDiskImage(); // Clear the screen to black. memset(screens[0], 0, SCREENWIDTH * SCREENHEIGHT); // We need SDL to give us translated versions of keys as well SDL_EnableUNICODE(1); // Repeat key presses - this is what Vanilla Doom does // Not sure about repeat rate - probably dependent on which DOS // driver is used. This is good enough though. SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); // clear out any events waiting at the start and center the mouse while (SDL_PollEvent(&dummy)); if (usemouse && !nomouse && (fullscreen || grabmouse)) { CenterMouse(); } initialized = true; }