2 // VIDEO.CPP: SDL/local hardware specific video routines
6 // JLH = James L. Hammons <jlhamm@acm.org>
9 // --- ---------- ------------------------------------------------------------
10 // JLH 01/04/2006 Added changelog ;-)
11 // JLH 01/20/2006 Cut out unnecessary buffering
16 #include <string.h> // Why??? (for memset, etc... Lazy!) Dunno why, but this just strikes me as wrong...
22 // Exported global variables (actually, these are LOCAL global variables, EXPORTED...)
24 static SDL_Window * sdlWindow = NULL;
25 static SDL_Renderer * sdlRenderer = NULL;
26 static SDL_Texture * sdlTexture = NULL;
27 uint32_t scrBuffer[VIRTUAL_SCREEN_WIDTH * VIRTUAL_SCREEN_HEIGHT * sizeof(uint32_t)];
31 // Prime SDL and create surfaces
35 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO | SDL_INIT_TIMER | SDL_INIT_NOPARACHUTE) != 0)
37 WriteLog("Video: Could not initialize the SDL library: %s\n", SDL_GetError());
41 int retVal = SDL_CreateWindowAndRenderer(VIRTUAL_SCREEN_WIDTH * 2, VIRTUAL_SCREEN_HEIGHT * 2, SDL_WINDOW_OPENGL, &sdlWindow, &sdlRenderer);
45 WriteLog("Video: Could not window and/or renderer: %s\n", SDL_GetError());
49 // Make the scaled rendering look smoother.
50 SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
51 // SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "nearest");
52 SDL_RenderSetLogicalSize(sdlRenderer, VIRTUAL_SCREEN_WIDTH, VIRTUAL_SCREEN_HEIGHT);
54 sdlTexture = SDL_CreateTexture(sdlRenderer,
55 SDL_PIXELFORMAT_ABGR8888, SDL_TEXTUREACCESS_STREAMING,
56 VIRTUAL_SCREEN_WIDTH, VIRTUAL_SCREEN_HEIGHT);
58 WriteLog("Video: Successfully initialized.\n");
64 // Free various SDL components
68 WriteLog("Video: Shutting down SDL...\n");
70 WriteLog("Video: Done.\n");
75 // Render the screen buffer to the primary screen surface
77 void RenderScreenBuffer(void)
79 SDL_UpdateTexture(sdlTexture, NULL, scrBuffer, VIRTUAL_SCREEN_WIDTH * sizeof(Uint32));
80 SDL_RenderClear(sdlRenderer);
81 SDL_RenderCopy(sdlRenderer, sdlTexture, NULL, NULL);
82 SDL_RenderPresent(sdlRenderer);
87 // Fullscreen <-> window switching
89 void ToggleFullScreen(void)
91 settings.fullscreen = !settings.fullscreen;
93 int retVal = SDL_SetWindowFullscreen(sdlWindow, (settings.fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0));
94 SDL_ShowCursor(settings.fullscreen ? 0 : 1);
97 WriteLog("Video::ToggleFullScreen: SDL error = %s\n", SDL_GetError());