From 094d8946f6229e20384102703e2d97dd3755846b Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sun, 1 Aug 2010 11:07:44 +0100 Subject: [PATCH] Enumerate available resolutions from SDL for options screen --- src/OpenGL.cpp | 14 ++++++++++++++ src/OpenGL.hpp | 9 +++++++++ src/Options.cpp | 25 ++++++++++++++++++++----- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/src/OpenGL.cpp b/src/OpenGL.cpp index 2c91696..df94f2d 100644 --- a/src/OpenGL.cpp +++ b/src/OpenGL.cpp @@ -408,6 +408,20 @@ void OpenGL::SkipDisplay() dodisplay = false; } +void OpenGL::EnumResolutions(vector& out) const +{ + Uint32 sdl_flags = SDL_OPENGL | SDL_FULLSCREEN; + + SDL_Rect** modes = SDL_ListModes(NULL, sdl_flags); + if (modes == NULL) + throw runtime_error("no video modes available"); + + if (modes == (SDL_Rect**)-1) + return; // Pick some useful default modes? + + for (int i = 0; modes[i] != NULL; i++) + out.push_back(Resolution(modes[i]->w, modes[i]->h)); +} Renderable::Renderable(int x, int y, int width, int height, float r, float g, float b) diff --git a/src/OpenGL.hpp b/src/OpenGL.hpp index 8a48500..205b329 100644 --- a/src/OpenGL.hpp +++ b/src/OpenGL.hpp @@ -23,6 +23,8 @@ #include "Platform.hpp" #include "Geometry.hpp" +#include + #define WINDOW_TITLE "Lunar Lander" #define FRAME_RATE 35 @@ -106,6 +108,13 @@ public: void DeferScreenShot(); bool SetVideoMode(bool fullscreen, int width, int height); + + struct Resolution { + Resolution(int w, int h) : width(w), height(h) {} + + int width, height; + }; + void EnumResolutions(vector& out) const; bool IsTextureSizeSupported(int width, int height, int ncols=4, GLenum format=GL_RGBA); diff --git a/src/Options.cpp b/src/Options.cpp index 3865e33..7ca13da 100644 --- a/src/Options.cpp +++ b/src/Options.cpp @@ -1,6 +1,6 @@ // // Options.cpp -- The options screen. -// Copyright (C) 2008-2009 Nick Gasson +// Copyright (C) 2008-2010 Nick Gasson // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -39,12 +39,27 @@ Options::Options() fullscreen.values.push_back("No"); fullscreen.active = (cfile.get_bool("fullscreen") ? 0 : 1); - // TODO: It would be better to query SDL for these values + vector available; + OpenGL::GetInstance().EnumResolutions(available); + + const int min_width = 640; + const int min_height = 480; + Item resolution = { "Resolution", 0 }; - resolution.values.push_back("800x600"); - resolution.values.push_back("1024x768"); - resolution.values.push_back("1280x1024"); + for (vector::reverse_iterator it = available.rbegin(); + it != available.rend(); + ++it) { + const OpenGL::Resolution& r = *it; + + if (r.width >= min_width && r.height >= min_height) { + ostringstream ss; + ss << r.width << "x" << r.height; + + resolution.values.push_back(ss.str()); + } + } + int hres = cfile.get_int("hres"); int vres = cfile.get_int("vres"); string currentRes = MakeResolutionString(hres, vres); -- 2.39.2