diff --git a/src/Graphics/Graphics.cpp b/src/Graphics/Graphics.cpp index 9b1ac01..d12f18d 100644 --- a/src/Graphics/Graphics.cpp +++ b/src/Graphics/Graphics.cpp @@ -86,13 +86,6 @@ static UInt32 penBG = 0xFF'00'00'FF; static int penX = 0; static int penY = 0; -// ---------------------------------------------------------------------------- - -// Globals - -extern "C" { -SDL_Window* gSDLWindow = nullptr; -} - // ---------------------------------------------------------------------------- - // Initialization @@ -101,53 +94,13 @@ CGrafPtr Pomme::Graphics::GetScreenPort(void) return &screenPort->port; } -void Pomme::Graphics::Init( - const char* windowTitle, - int windowWidth, - int windowHeight, - int msaaSamples) +void Pomme::Graphics::Init() { - if (0 != SDL_Init(SDL_INIT_VIDEO)) - { - throw std::runtime_error("Couldn't initialize SDL video subsystem."); - } - - SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); -#ifndef _WIN32 - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); -#endif - - if (msaaSamples != 0) - { - SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); - SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, msaaSamples); - } - - gSDLWindow = SDL_CreateWindow( - windowTitle, - SDL_WINDOWPOS_UNDEFINED, - SDL_WINDOWPOS_UNDEFINED, - windowWidth, - windowHeight, - SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_SHOWN); - - if (!gSDLWindow) - { - throw std::runtime_error("Couldn't create SDL window."); - } - Rect boundsRect = {0, 0, 480, 640}; screenPort = std::make_unique(boundsRect); curPort = screenPort.get(); } -void Pomme::Graphics::Shutdown() -{ - SDL_DestroyWindow(gSDLWindow); - gSDLWindow = nullptr; -} - // ---------------------------------------------------------------------------- - // Internal utils @@ -703,7 +656,7 @@ void DrawChar(char c) // ---------------------------------------------------------------------------- // Icons -void Pomme::Graphics::SetWindowIconFromIcl8Resource(short icl8ID) +void Pomme::Graphics::SetWindowIconFromIcl8Resource(SDL_Window* window, short icl8ID) { Handle colorIcon = GetResource('icl8', icl8ID); if (1024 != GetHandleSize(colorIcon)) @@ -740,7 +693,7 @@ void Pomme::Graphics::SetWindowIconFromIcl8Resource(short icl8ID) *out++ = argb; } } - SDL_SetWindowIcon(gSDLWindow, icon); + SDL_SetWindowIcon(window, icon); SDL_FreeSurface(icon); DisposeHandle(colorIcon); DisposeHandle(bwIcon); diff --git a/src/Pomme.cpp b/src/Pomme.cpp index 603c5e9..9e1438a 100644 --- a/src/Pomme.cpp +++ b/src/Pomme.cpp @@ -66,11 +66,11 @@ void HideCursor() //----------------------------------------------------------------------------- // Our own init -void Pomme::Init(const InitParams& params) +void Pomme::Init() { Pomme::Time::Init(); Pomme::Files::Init(); - Pomme::Graphics::Init(params.windowName, params.windowWidth, params.windowHeight, params.msaaSamples); + Pomme::Graphics::Init(); Pomme::Sound::Init(); Pomme::Input::Init(); } @@ -78,5 +78,4 @@ void Pomme::Init(const InitParams& params) void Pomme::Shutdown() { Pomme::Sound::Shutdown(); - Pomme::Graphics::Shutdown(); } diff --git a/src/PommeGraphics.h b/src/PommeGraphics.h index bf523f4..2e04fe2 100644 --- a/src/PommeGraphics.h +++ b/src/PommeGraphics.h @@ -3,6 +3,7 @@ #include "PommeTypes.h" #include #include +#include namespace Pomme::Graphics { @@ -41,11 +42,7 @@ namespace Pomme::Graphics { return (UInt32*) &data.data()[4 * (y * width + x)]; } }; - void Init( - const char* windowTitle, - int windowWidth, - int windowHeight, - int msaaSamples = 0); + void Init(); void Shutdown(); @@ -57,7 +54,7 @@ namespace Pomme::Graphics CGrafPtr GetScreenPort(void); - void SetWindowIconFromIcl8Resource(short i); + void SetWindowIconFromIcl8Resource(SDL_Window* sdlWindow, short i); inline int Width(const Rect& r) { return r.right - r.left; } diff --git a/src/PommeInit.h b/src/PommeInit.h index 1836aa5..1ccdaaa 100644 --- a/src/PommeInit.h +++ b/src/PommeInit.h @@ -9,15 +9,7 @@ namespace Pomme virtual const char* what() const noexcept; }; - struct InitParams - { - const char* windowName; - int windowWidth; - int windowHeight; - int msaaSamples; - }; - - void Init(const InitParams& params); + void Init(); void Shutdown(); }