Application is now responsible for creating its own SDL window

This commit is contained in:
Iliyas Jorio 2021-01-06 20:29:33 +01:00
parent b8ca96a5c4
commit 0640b1356d
4 changed files with 9 additions and 68 deletions

View File

@ -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<GrafPortImpl>(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);

View File

@ -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();
}

View File

@ -3,6 +3,7 @@
#include "PommeTypes.h"
#include <istream>
#include <vector>
#include <SDL_video.h>
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; }

View File

@ -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();
}