void TextureBuilder::LoadSurface() { assert(!m_surface); SDLSurfacePtr s; if(m_textureType == TEXTURE_2D) { s = LoadSurfaceFromFile(m_filename); if (! s) { s = LoadSurfaceFromFile("textures/unknown.png"); } } else if(m_textureType == TEXTURE_CUBE_MAP) { Output("LoadSurface: %s: cannot load non-DDS cubemaps\n", m_filename.c_str()); } // XXX if we can't load the fallback texture, then what? assert(s); m_surface = s; }
void TextureBuilder::LoadDDS() { assert(!m_dds.headerdone_); LoadDDSFromFile(m_filename, m_dds); if (!m_dds.headerdone_) { m_surface = LoadSurfaceFromFile("textures/unknown.png"); } // XXX if we can't load the fallback texture, then what? }
static void _blit_image(SDL_Surface *s, const char *filename, int xoff, int yoff) { SDLSurfacePtr is = LoadSurfaceFromFile(filename); // XXX what should this do if the image couldn't be loaded? if (! is) { return; } SDL_Rect destrec = { 0, 0, 0, 0 }; destrec.x = ((FACE_WIDTH-is->w-1)/2)+xoff; destrec.y = yoff; SDL_BlitSurface(is.Get(), NULL, s, &destrec); }
WindowSDL::WindowSDL(const Graphics::Settings &vs, const std::string &name) { // XXX horrible hack. if we don't want a renderer, we might be in an // environment that doesn't actually have graphics available. since we're // not going to draw anything anyway, there's not much point initialising a // window (which will fail in aforementioned headless environment) // // the "right" way would be to have a dummy window class as well, and move // a lot of this initialisation into the GL renderer. this is much easier // right now though if (vs.rendererType == Graphics::RENDERER_DUMMY) return; bool ok; // attempt sequence is: // 1- requested mode ok = CreateWindowAndContext(name.c_str(), vs.width, vs.height, vs.fullscreen, vs.hidden, vs.requestedSamples, 24); // 2- requested mode with no anti-aliasing (skipped if no AA was requested anyway) // (skipped if no AA was requested anyway) if (!ok && vs.requestedSamples) { Output("Failed to set video mode. (%s). Re-trying without multisampling.\n", SDL_GetError()); ok = CreateWindowAndContext(name.c_str(), vs.width, vs.height, vs.fullscreen, vs.hidden, 0, 24); } // 3- requested mode with 16 bit depth buffer if (!ok) { Output("Failed to set video mode. (%s). Re-trying with 16-bit depth buffer\n", SDL_GetError()); ok = CreateWindowAndContext(name.c_str(), vs.width, vs.height, vs.fullscreen, vs.hidden, vs.requestedSamples, 16); } // 4- requested mode with 16-bit depth buffer and no anti-aliasing // (skipped if no AA was requested anyway) if (!ok && vs.requestedSamples) { Output("Failed to set video mode. (%s). Re-trying with 16-bit depth buffer and no multisampling\n", SDL_GetError()); ok = CreateWindowAndContext(name.c_str(), vs.width, vs.height, vs.fullscreen, vs.hidden, 0, 16); } // 5- abort! if (!ok) { Error("Failed to set video mode: %s", SDL_GetError()); } SDLSurfacePtr surface = LoadSurfaceFromFile(vs.iconFile); if (surface) SDL_SetWindowIcon(m_window, surface.Get()); SDL_SetWindowTitle(m_window, vs.title); SDL_ShowCursor(0); SDL_GL_SetSwapInterval((vs.vsync!=0) ? 1 : 0); }
void PartDb::ScanParts(std::vector<Part> &output, const int species_idx, const int race_idx, const std::string &path, const char *prefix) { const Uint32 selector = _make_selector(species_idx, race_idx, -1); for (fs::FileEnumerator files(fs::gameDataFiles, path); !files.Finished(); files.Next()) { const std::string &name = files.Current().GetName(); if (starts_with(name, prefix)) { SDLSurfacePtr im = LoadSurfaceFromFile(files.Current().GetPath()); if (im) { output.push_back(Part(selector, im)); } else { Output("Failed to load image %s\n", files.Current().GetPath().c_str()); } } } }
void PartDb::Scan() { Clear(); background_general = LoadSurfaceFromFile(BACKGROUND_GENERAL_PATH); if (!background_general) { Output("Failed to load image %s\n", BACKGROUND_GENERAL_PATH); } int species_count = 0; const auto flags = fs::FileEnumerator::IncludeDirs | fs::FileEnumerator::ExcludeFiles; for (fs::FileEnumerator dirs(fs::gameDataFiles, "facegen", flags); !dirs.Finished(); dirs.Next()) { if (!starts_with(dirs.Current().GetName(), "species_")) continue; if (species_count >= MAX_SPECIES) { Output("FaceParts: reached the limit on the number of species\n"); break; } ScanSpecies(dirs.Current().GetPath(), species_count); ++species_count; } }
WindowSDL::WindowSDL(const Graphics::Settings &vs, const std::string &name) { bool ok; // attempt sequence is: // 1- requested mode ok = CreateWindowAndContext(name.c_str(), vs.width, vs.height, vs.fullscreen, vs.hidden, vs.requestedSamples, 24); // 2- requested mode with no anti-aliasing (skipped if no AA was requested anyway) // (skipped if no AA was requested anyway) if (!ok && vs.requestedSamples) { Output("Failed to set video mode. (%s). Re-trying without multisampling.\n", SDL_GetError()); ok = CreateWindowAndContext(name.c_str(), vs.width, vs.height, vs.fullscreen, vs.hidden, 0, 24); } // 3- requested mode with 16 bit depth buffer if (!ok) { Output("Failed to set video mode. (%s). Re-trying with 16-bit depth buffer\n", SDL_GetError()); ok = CreateWindowAndContext(name.c_str(), vs.width, vs.height, vs.fullscreen, vs.hidden, vs.requestedSamples, 16); } // 4- requested mode with 16-bit depth buffer and no anti-aliasing // (skipped if no AA was requested anyway) if (!ok && vs.requestedSamples) { Output("Failed to set video mode. (%s). Re-trying with 16-bit depth buffer and no multisampling\n", SDL_GetError()); ok = CreateWindowAndContext(name.c_str(), vs.width, vs.height, vs.fullscreen, vs.hidden, 0, 16); } // 5- abort! if (!ok) { Error("Failed to set video mode: %s", SDL_GetError()); } SDLSurfacePtr surface = LoadSurfaceFromFile(vs.iconFile); if (surface) SDL_SetWindowIcon(m_window, surface.Get()); SDL_SetWindowTitle(m_window, vs.title); SDL_ShowCursor(0); }
WindowSDL::WindowSDL(const Graphics::Settings &vs, const std::string &name) { Uint32 winFlags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN; if (vs.fullscreen) winFlags |= SDL_WINDOW_FULLSCREEN; SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, vs.requestedSamples ? 1 : 0); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, vs.requestedSamples); // attempt sequence is: // 1- requested mode m_window = SDL_CreateWindow(name.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, vs.width, vs.height, winFlags); // 2- requested mode with no anti-aliasing (skipped if no AA was requested anyway) if (!m_window && vs.requestedSamples) { fprintf(stderr, "Failed to set video mode. (%s). Re-trying without multisampling.\n", SDL_GetError()); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0); m_window = SDL_CreateWindow(name.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, vs.width, vs.height, winFlags); } // 3- requested mode with 16 bit depth buffer if (!m_window) { fprintf(stderr, "Failed to set video mode. (%s). Re-trying with 16-bit depth buffer\n", SDL_GetError()); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, vs.requestedSamples ? 1 : 0); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, vs.requestedSamples); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); m_window = SDL_CreateWindow(name.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, vs.width, vs.height, winFlags); } // 4- requested mode with 16-bit depth buffer and no anti-aliasing // (skipped if no AA was requested anyway) if (!m_window && vs.requestedSamples) { fprintf(stderr, "Failed to set video mode. (%s). Re-trying with 16-bit depth buffer and no multisampling\n", SDL_GetError()); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); m_window = SDL_CreateWindow(name.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, vs.width, vs.height, winFlags); } // 5- abort! if (!m_window) { OS::Error("Failed to set video mode: %s", SDL_GetError()); } m_glContext = SDL_GL_CreateContext(m_window); int bpp; Uint32 rmask, gmask, bmask, amask; SDL_PixelFormatEnumToMasks(SDL_GetWindowPixelFormat(m_window), &bpp, &rmask, &gmask, &bmask, &amask); switch (bpp) { case 16: SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); break; case 24: case 32: SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); break; default: fprintf(stderr, "Invalid pixel depth: %d bpp\n", bpp); // this valuable is not reliable if antialiasing vs are overridden by // nvidia/ati/whatever vs int actualSamples = 0; SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &actualSamples); if (vs.requestedSamples != actualSamples) fprintf(stderr, "Requested AA mode: %dx, actual: %dx\n", vs.requestedSamples, actualSamples); } SDLSurfacePtr surface = LoadSurfaceFromFile(vs.iconFile); if (surface) SDL_SetWindowIcon(m_window, surface.Get()); SDL_SetWindowTitle(m_window, vs.title); }
SDLSurfacePtr LoadSurfaceFromFile(const std::string &fname) { return LoadSurfaceFromFile(fname, FileSystem::gameDataFiles); }