Permalink
Browse files

Enumerate available resolutions from SDL for options screen

  • Loading branch information...
1 parent 69e5004 commit 094d8946f6229e20384102703e2d97dd3755846b @nickg committed Aug 1, 2010
Showing with 43 additions and 5 deletions.
  1. +14 −0 src/OpenGL.cpp
  2. +9 −0 src/OpenGL.hpp
  3. +20 −5 src/Options.cpp
View
@@ -408,6 +408,20 @@ void OpenGL::SkipDisplay()
dodisplay = false;
}
+void OpenGL::EnumResolutions(vector<Resolution>& 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)
View
@@ -23,6 +23,8 @@
#include "Platform.hpp"
#include "Geometry.hpp"
+#include <vector>
+
#define WINDOW_TITLE "Lunar Lander"
#define FRAME_RATE 35
@@ -106,6 +108,13 @@ class OpenGL {
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<Resolution>& out) const;
bool IsTextureSizeSupported(int width, int height, int ncols=4,
GLenum format=GL_RGBA);
View
@@ -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<OpenGL::Resolution> 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<OpenGL::Resolution>::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);

0 comments on commit 094d894

Please sign in to comment.