diff --git a/src/GameWindow.cpp b/src/GameWindow.cpp index 8124be0..7e1a74b 100644 --- a/src/GameWindow.cpp +++ b/src/GameWindow.cpp @@ -1,5 +1,6 @@ #include "GameWindow.hpp" +#include #include #include @@ -18,6 +19,7 @@ #include "render/gl/Debug.hpp" #include "util/Log.hpp" #include "util/MemoryTracker.hpp" +#include "util/StringUtil.hpp" namespace diggler { @@ -50,10 +52,28 @@ GameWindow::GameWindow(Game *G) : G(G) { m_w = 640; m_h = 480; - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); - glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API /*GLFW_OPENGL_ES_API*/); - //glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE); + if (GlobalProperties::GfxOverrides != nullptr) { + for (const std::string &opt : Util::StringUtil::explode(GlobalProperties::GfxOverrides, ',')) { + if (opt.size() == 4 && opt[0] == 'g' && opt[1] == 'l' && + isdigit(opt[2]) && isdigit(opt[3])) { + glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API); + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, opt[2] - '0'); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, opt[3] - '0'); + } else if (opt.size() == 6 && opt[0] == 'g' && opt[1] == 'l' && + opt[2] == 'e' && opt[3] == 's' && isdigit(opt[4]) && isdigit(opt[5])) { + glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API); + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, opt[4] - '0'); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, opt[5] - '0'); + } else if (opt == "fwd") { + glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE); + } else if (opt == "compat") { + glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE); + } else if (opt == "core") { + glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); + } + } + } + glfwWindowHint(GLFW_SAMPLES, 0); // Gimme aliasing everywhere //glfwWindowHint(GLFW_STENCIL_BITS, 8); diff --git a/src/GlobalProperties.cpp b/src/GlobalProperties.cpp index 96fcad3..33f4734 100644 --- a/src/GlobalProperties.cpp +++ b/src/GlobalProperties.cpp @@ -15,5 +15,6 @@ bool GlobalProperties::IsSoundEnabled = true; int GlobalProperties::UIScale = 2; +char *GlobalProperties::GfxOverrides = nullptr; } diff --git a/src/GlobalProperties.hpp b/src/GlobalProperties.hpp index c9f97f5..ce59690 100644 --- a/src/GlobalProperties.hpp +++ b/src/GlobalProperties.hpp @@ -16,6 +16,8 @@ namespace GlobalProperties { extern bool IsSoundEnabled; extern int UIScale; + + extern char *GfxOverrides; } } diff --git a/src/main.cpp b/src/main.cpp index dd86c30..79934ed 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -68,7 +68,7 @@ int main(int argc, char **argv) { string host = GlobalProperties::DefaultServerHost; int port = GlobalProperties::DefaultServerPort; - for (int i=1; i < argc; i++) { + for (int i=1; i < argc; ++i) { if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { showHelp(argv); @@ -95,6 +95,8 @@ int main(int argc, char **argv) { GlobalProperties::PlayerName = argv[++i]; Log(Info, TAG) << "Player's name set to " << GlobalProperties::PlayerName; } + } else if (strcmp(argv[i], "-g") == 0) { + GlobalProperties::GfxOverrides = argv[++i]; } else { // For now, assume it's the server address host = argv[i]; diff --git a/src/util/StringUtil.cpp b/src/util/StringUtil.cpp index 4132d8b..97ae17a 100644 --- a/src/util/StringUtil.cpp +++ b/src/util/StringUtil.cpp @@ -6,7 +6,7 @@ namespace diggler { namespace Util { -std::vector explode(const std::string &s, char delim) { +std::vector StringUtil::explode(const std::string &s, char delim) { std::vector result; std::istringstream iss(s); for (std::string token; std::getline(iss, token, delim); ) { @@ -15,7 +15,7 @@ std::vector explode(const std::string &s, char delim) { return result; } -std::vector explode(const std::u32string &s, char32_t delim) { +std::vector StringUtil::explode(const std::u32string &s, char32_t delim) { std::vector result; std::basic_istringstream iss(s); for (std::u32string token; std::getline(iss, token, delim); ) {