mirror of https://github.com/jorio/Pomme.git
Application is now responsible for creating its own SDL window
This commit is contained in:
parent
b8ca96a5c4
commit
0640b1356d
|
@ -86,13 +86,6 @@ static UInt32 penBG = 0xFF'00'00'FF;
|
||||||
static int penX = 0;
|
static int penX = 0;
|
||||||
static int penY = 0;
|
static int penY = 0;
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------- -
|
|
||||||
// Globals
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
SDL_Window* gSDLWindow = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------- -
|
// ---------------------------------------------------------------------------- -
|
||||||
// Initialization
|
// Initialization
|
||||||
|
|
||||||
|
@ -101,53 +94,13 @@ CGrafPtr Pomme::Graphics::GetScreenPort(void)
|
||||||
return &screenPort->port;
|
return &screenPort->port;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pomme::Graphics::Init(
|
void Pomme::Graphics::Init()
|
||||||
const char* windowTitle,
|
|
||||||
int windowWidth,
|
|
||||||
int windowHeight,
|
|
||||||
int msaaSamples)
|
|
||||||
{
|
{
|
||||||
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};
|
Rect boundsRect = {0, 0, 480, 640};
|
||||||
screenPort = std::make_unique<GrafPortImpl>(boundsRect);
|
screenPort = std::make_unique<GrafPortImpl>(boundsRect);
|
||||||
curPort = screenPort.get();
|
curPort = screenPort.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pomme::Graphics::Shutdown()
|
|
||||||
{
|
|
||||||
SDL_DestroyWindow(gSDLWindow);
|
|
||||||
gSDLWindow = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------- -
|
// ---------------------------------------------------------------------------- -
|
||||||
// Internal utils
|
// Internal utils
|
||||||
|
|
||||||
|
@ -703,7 +656,7 @@ void DrawChar(char c)
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Icons
|
// Icons
|
||||||
|
|
||||||
void Pomme::Graphics::SetWindowIconFromIcl8Resource(short icl8ID)
|
void Pomme::Graphics::SetWindowIconFromIcl8Resource(SDL_Window* window, short icl8ID)
|
||||||
{
|
{
|
||||||
Handle colorIcon = GetResource('icl8', icl8ID);
|
Handle colorIcon = GetResource('icl8', icl8ID);
|
||||||
if (1024 != GetHandleSize(colorIcon))
|
if (1024 != GetHandleSize(colorIcon))
|
||||||
|
@ -740,7 +693,7 @@ void Pomme::Graphics::SetWindowIconFromIcl8Resource(short icl8ID)
|
||||||
*out++ = argb;
|
*out++ = argb;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SDL_SetWindowIcon(gSDLWindow, icon);
|
SDL_SetWindowIcon(window, icon);
|
||||||
SDL_FreeSurface(icon);
|
SDL_FreeSurface(icon);
|
||||||
DisposeHandle(colorIcon);
|
DisposeHandle(colorIcon);
|
||||||
DisposeHandle(bwIcon);
|
DisposeHandle(bwIcon);
|
||||||
|
|
|
@ -66,11 +66,11 @@ void HideCursor()
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Our own init
|
// Our own init
|
||||||
|
|
||||||
void Pomme::Init(const InitParams& params)
|
void Pomme::Init()
|
||||||
{
|
{
|
||||||
Pomme::Time::Init();
|
Pomme::Time::Init();
|
||||||
Pomme::Files::Init();
|
Pomme::Files::Init();
|
||||||
Pomme::Graphics::Init(params.windowName, params.windowWidth, params.windowHeight, params.msaaSamples);
|
Pomme::Graphics::Init();
|
||||||
Pomme::Sound::Init();
|
Pomme::Sound::Init();
|
||||||
Pomme::Input::Init();
|
Pomme::Input::Init();
|
||||||
}
|
}
|
||||||
|
@ -78,5 +78,4 @@ void Pomme::Init(const InitParams& params)
|
||||||
void Pomme::Shutdown()
|
void Pomme::Shutdown()
|
||||||
{
|
{
|
||||||
Pomme::Sound::Shutdown();
|
Pomme::Sound::Shutdown();
|
||||||
Pomme::Graphics::Shutdown();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "PommeTypes.h"
|
#include "PommeTypes.h"
|
||||||
#include <istream>
|
#include <istream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <SDL_video.h>
|
||||||
|
|
||||||
namespace Pomme::Graphics
|
namespace Pomme::Graphics
|
||||||
{
|
{
|
||||||
|
@ -41,11 +42,7 @@ namespace Pomme::Graphics
|
||||||
{ return (UInt32*) &data.data()[4 * (y * width + x)]; }
|
{ return (UInt32*) &data.data()[4 * (y * width + x)]; }
|
||||||
};
|
};
|
||||||
|
|
||||||
void Init(
|
void Init();
|
||||||
const char* windowTitle,
|
|
||||||
int windowWidth,
|
|
||||||
int windowHeight,
|
|
||||||
int msaaSamples = 0);
|
|
||||||
|
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
|
|
||||||
|
@ -57,7 +54,7 @@ namespace Pomme::Graphics
|
||||||
|
|
||||||
CGrafPtr GetScreenPort(void);
|
CGrafPtr GetScreenPort(void);
|
||||||
|
|
||||||
void SetWindowIconFromIcl8Resource(short i);
|
void SetWindowIconFromIcl8Resource(SDL_Window* sdlWindow, short i);
|
||||||
|
|
||||||
inline int Width(const Rect& r)
|
inline int Width(const Rect& r)
|
||||||
{ return r.right - r.left; }
|
{ return r.right - r.left; }
|
||||||
|
|
|
@ -9,15 +9,7 @@ namespace Pomme
|
||||||
virtual const char* what() const noexcept;
|
virtual const char* what() const noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct InitParams
|
void Init();
|
||||||
{
|
|
||||||
const char* windowName;
|
|
||||||
int windowWidth;
|
|
||||||
int windowHeight;
|
|
||||||
int msaaSamples;
|
|
||||||
};
|
|
||||||
|
|
||||||
void Init(const InitParams& params);
|
|
||||||
|
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue