/** wzSetCursor()-- Set the current cursor */ void wzSetCursor(CURSOR cur) { ASSERT(cur < CURSOR_MAX, "Specified cursor(%d) is over our limit of (%d)!", (int)cur, (int)CURSOR_MAX); // we reset mouse cursors on the fly...(only in the mouse options screen!) if ((~(war_GetColouredCursor() ^ monoCursor)) && (titleMode == MOUSE_OPTIONS)) { sdlFreeCursors(); war_GetColouredCursor() ? sdlInitColoredCursors() : sdlInitCursors(); SDL_SetCursor(aCursors[cur]); } // If we are already using this cursor then return if (cur != currentCursor) { SDL_SetCursor(aCursors[cur]); currentCursor = cur; } }
// This stage, we handle display mode setting bool wzMainScreenSetup(int antialiasing, bool fullscreen, bool vsync) { // populate with the saved values (if we had any) int width = pie_GetVideoBufferWidth(); int height = pie_GetVideoBufferHeight(); int bitDepth = pie_GetVideoBufferDepth(); if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) { debug(LOG_ERROR, "Error: Could not initialise SDL (%s).", SDL_GetError()); return false; } // Populated our resolution list (does all displays now) SDL_DisplayMode displaymode; struct screeninfo screenlist; for (int i = 0; i < SDL_GetNumVideoDisplays(); ++i) // How many monitors we got { int numdisplaymodes = SDL_GetNumDisplayModes(i); // Get the number of display modes on this monitor for (int j = 0; j < numdisplaymodes; j++) { displaymode.format = displaymode.w = displaymode.h = displaymode.refresh_rate = 0; displaymode.driverdata = 0; if (SDL_GetDisplayMode(i, j, &displaymode) < 0) { debug(LOG_FATAL, "SDL_LOG_CATEGORY_APPLICATION error:%s", SDL_GetError()); SDL_Quit(); exit(EXIT_FAILURE); } debug(LOG_WZ, "Monitor[%d]%dx%d %d %s", i, displaymode.w, displaymode.h, displaymode.refresh_rate, getSDL_fmt_string(displaymode.format)); if (displaymode.refresh_rate < 59) { continue; // only store 60Hz & higher modes, some display report 59 on linux } screenlist.height = displaymode.h; screenlist.width = displaymode.w; screenlist.refresh_rate = displaymode.refresh_rate; screenlist.screen = i; // which monitor this belongs to displaylist.push_back(screenlist); } } SDL_DisplayMode current = { 0, 0, 0, 0, 0 }; for (int i = 0; i < SDL_GetNumVideoDisplays(); ++i) { int display = SDL_GetCurrentDisplayMode(i, ¤t); if (display != 0) { debug(LOG_FATAL, "Can't get the current display mode, because: %s", SDL_GetError()); SDL_Quit(); exit(EXIT_FAILURE); } debug(LOG_WZ, "Monitor[%d]%dx%d %d", i, current.w, current.h, current.refresh_rate); } if (width == 0 || height == 0) { pie_SetVideoBufferWidth(width = screenWidth = current.w); pie_SetVideoBufferHeight(height = screenHeight = current.h); } else { screenWidth = width; screenHeight = height; } screenWidth = MAX(screenWidth, 640); screenHeight = MAX(screenHeight, 480); //// The flags to pass to SDL_CreateWindow int video_flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN; if (war_getFullscreen()) { video_flags |= SDL_WINDOW_FULLSCREEN; } SDL_Rect bounds; for (int i = 0; i < SDL_GetNumVideoDisplays(); i++) { SDL_GetDisplayBounds(i, &bounds); debug(LOG_WZ, "Monitor %d: pos %d x %d : res %d x %d", i, (int)bounds.x, (int)bounds.y, (int)bounds.w, (int)bounds.h); } if (war_GetScreen() > SDL_GetNumVideoDisplays()) { debug(LOG_FATAL, "Invalid screen defined in configuration"); SDL_Quit(); exit(EXIT_FAILURE); } SDL_GetDisplayBounds(war_GetScreen(), &bounds); bounds.w -= (bounds.w + screenWidth) / 2; bounds.h -= (bounds.h + screenHeight) / 2; WZwindow = SDL_CreateWindow(PACKAGE_NAME, bounds.x + bounds.w, bounds.y + bounds.h, screenWidth, screenHeight, video_flags); if (!WZwindow) { debug(LOG_FATAL, "Can't create a window, because: %s", SDL_GetError()); SDL_Quit(); exit(EXIT_FAILURE); } WZglcontext = SDL_GL_CreateContext(WZwindow); if (!WZglcontext) { debug(LOG_ERROR, "Failed to create a openGL context! [%s]", SDL_GetError()); return false; } // Set the double buffer OpenGL attribute. SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); // Enable FSAA anti-aliasing if and at the level requested by the user if (antialiasing) { SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, antialiasing); } int bpp = SDL_BITSPERPIXEL(SDL_GetWindowPixelFormat(WZwindow)); debug(LOG_WZ, "Bpp = %d format %s" , bpp, getSDL_fmt_string(SDL_GetWindowPixelFormat(WZwindow))); if (!bpp) { debug(LOG_ERROR, "Video mode %dx%d@%dbpp is not supported!", width, height, bitDepth); return false; } switch (bpp) { case 32: case 24: // all is good... break; case 16: info("Using colour depth of %i instead of a 32/24 bit depth (True color).", bpp); info("You will experience graphics glitches!"); break; case 8: debug(LOG_FATAL, "You don't want to play Warzone with a bit depth of %i, do you?", bpp); SDL_Quit(); exit(1); break; default: debug(LOG_FATAL, "Unsupported bit depth: %i", bpp); exit(1); break; } // Enable/disable vsync if requested by the user wzSetSwapInterval(war_GetVsync()); int value = 0; if (SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &value) == -1 || value == 0) { debug(LOG_FATAL, "OpenGL initialization did not give double buffering!"); debug(LOG_FATAL, "Double buffering is required for this game!"); SDL_Quit(); exit(1); } #if SDL_BYTEORDER == SDL_BIG_ENDIAN uint32_t rmask = 0xff000000; uint32_t gmask = 0x00ff0000; uint32_t bmask = 0x0000ff00; uint32_t amask = 0x000000ff; #else uint32_t rmask = 0x000000ff; uint32_t gmask = 0x0000ff00; uint32_t bmask = 0x00ff0000; uint32_t amask = 0xff000000; #endif SDL_Surface *surface_icon = SDL_CreateRGBSurfaceFrom((void *)wz2100icon.pixel_data, wz2100icon.width, wz2100icon.height, wz2100icon.bytes_per_pixel * 8, wz2100icon.width * wz2100icon.bytes_per_pixel, rmask, gmask, bmask, amask); if (surface_icon) { SDL_SetWindowIcon(WZwindow, surface_icon); SDL_FreeSurface(surface_icon); } else { debug(LOG_ERROR, "Could not set window icon because %s", SDL_GetError()); } SDL_SetWindowTitle(WZwindow, PACKAGE_NAME); /* initialise all cursors */ if (war_GetColouredCursor()) { sdlInitColoredCursors(); } else { sdlInitCursors(); } // FIXME: aspect ratio glViewport(0, 0, width, height); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0, width, height, 0, 1, -1); glMatrixMode(GL_TEXTURE); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glCullFace(GL_FRONT); glEnable(GL_CULL_FACE); return true; }