launcher: avoid crashing with original version of GLUT, move cuInit call into ui.h (function setup in framework.h), allow changing resolution of borderless mode

This commit is contained in:
somewhatlurker
2019-08-05 08:07:23 +10:00
parent 16bbe3c05f
commit 78c5ee6b0a
3 changed files with 25 additions and 22 deletions
@@ -9,13 +9,6 @@ using namespace System::Windows::Forms;
[STAThread]
int showUI() {
SetProcessDPIAware();
// trick Optimus into switching to the NVIDIA GPU
HMODULE nvcudaModule = LoadLibraryW(L"nvcuda.dll");
// cuInit actually returns a CUresult, but we don't really care about it
void(WINAPI * cuInit)(unsigned int flags) = (void(WINAPI*)(unsigned int flags))GetProcAddress(nvcudaModule, "cuInit");
if (cuInit != NULL) cuInit(0);
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
Application::Run(gcnew Launcher::ui());
@@ -257,4 +257,14 @@ void PrependFile(LPCSTR newStr, LPCWSTR fileName)
fileStream.seekg(0, std::ios::beg);
fileStream << outStr;
fileStream.close();
}
}
// used to trick Optimus into switching to the NVIDIA GPU
HMODULE nvcudaModule = LoadLibraryW(L"nvcuda.dll");
// cuInit actually returns a CUresult, but we don't really care about it
void(WINAPI * cuInit)(unsigned int flags) = (void(WINAPI*)(unsigned int flags))GetProcAddress(nvcudaModule, "cuInit");
// needed to close the OpenGL window (freeglut only)
HMODULE glutModule = LoadLibraryW(L"glut32.dll");
void(__stdcall * glutMainLoopEventDynamic)() = (void(__stdcall*)())GetProcAddress(glutModule, "glutMainLoopEventDynamic");
+14 -14
View File
@@ -112,18 +112,27 @@ namespace Launcher {
this->panel_Components->ResumeLayout(false);
this->panel_Components->PerformLayout();
// trick Optimus into switching to the NVIDIA GPU
if (cuInit != NULL) cuInit(0);
int argc = 1;
char* argv[1] = { (char*)"" };
glutInit(&argc, argv);
int window = glutCreateWindow("glut");
int window = glutCreateWindow("glut"); // a context must be created to use glGetString
String^ vendor = gcnew String((char*)glGetString(GL_VENDOR));
String^ renderer = gcnew String((char*)glGetString(GL_RENDERER));
String^ version = gcnew String((char*)glGetString(GL_VERSION));
glutDestroyWindow(window);
glutMainLoopEvent();
glutDestroyWindow(window); // destroy the window so it doesn't remain on screen
if (glutMainLoopEventDynamic != NULL) glutMainLoopEventDynamic(); // freeglut needs this
this->labelGPU->Text = "Vendor: " + vendor + "\nRenderer: " + renderer + "\nOpenGL: " + version;
if (vendor != "NVIDIA Corporation") SkinnedMessageBox::Show(this, "Your graphics card is not supported! Only NVIDIA GPUs are currently supported.", "PD Launcher", MessageBoxButtons::OK, MessageBoxIcon::Warning);
else if ((int)(version[0]) - 48 < 3) SkinnedMessageBox::Show(this, "Your GPU is too old. The game might not render PVs correctly!", "PD Launcher", MessageBoxButtons::OK, MessageBoxIcon::Warning);
if (!vendor->Contains("NVIDIA")) SkinnedMessageBox::Show(this, "Your graphics card is not supported! Only NVIDIA GPUs are currently supported.", "PD Launcher", MessageBoxButtons::OK, MessageBoxIcon::Warning);
else if (version[0] < '3') SkinnedMessageBox::Show(this, "Your GPU is too old. The game might not render PVs correctly!", "PD Launcher", MessageBoxButtons::OK, MessageBoxIcon::Warning);
}
protected:
@@ -474,15 +483,6 @@ private: System::Void InternalResEnabledChangedHandler(System::Object^ sender, S
private: System::Void DisplayTypeChangedHandler(System::Object^ sender, System::EventArgs^ e) {
int idx = ((ComboBox^)ComboBox::FromHandle(DisplayModeDropdown->mainControlHandle))->SelectedIndex;
if (idx == 0 || idx == 2) // windowed or fullscreen
{
((Control^)Control::FromHandle(DisplayResolutionOption->mainControlHandle))->Enabled = true;
}
else
{
((Control^)Control::FromHandle(DisplayResolutionOption->mainControlHandle))->Enabled = false;
}
if (idx == 2) // fullscreen
{
for (ConfigOptionBase* option : screenResolutionArray)