V2.03 Added DrawStringDecal()

And FreeBSD flags...
pull/113/head v2.03
Javidx9 5 years ago committed by GitHub
parent 13bb251672
commit a483740926
  1. 48
      olcPixelGameEngine.h

@ -2,7 +2,7 @@
olcPixelGameEngine.h olcPixelGameEngine.h
+-------------------------------------------------------------+ +-------------------------------------------------------------+
| OneLoneCoder Pixel Game Engine v2.02 | | OneLoneCoder Pixel Game Engine v2.03 |
| "What do you need? Pixels... Lots of Pixels..." - javidx9 | | "What do you need? Pixels... Lots of Pixels..." - javidx9 |
+-------------------------------------------------------------+ +-------------------------------------------------------------+
@ -132,6 +132,7 @@
2.01: Made renderer and platform static for multifile projects 2.01: Made renderer and platform static for multifile projects
2.02: Added Decal destructor, optimised Pixel constructor 2.02: Added Decal destructor, optimised Pixel constructor
2.03: Added FreeBSD flags, Added DrawStringDecal()
*/ */
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
@ -218,7 +219,7 @@ int main()
#endif #endif
#endif #endif
#if defined(__linux__) || defined(__MINGW32__) || defined(__EMSCRIPTEN__) #if defined(__linux__) || defined(__MINGW32__) || defined(__EMSCRIPTEN__) || defined(__FreeBSD__)
#if __cplusplus >= 201703L #if __cplusplus >= 201703L
#undef USE_EXPERIMENTAL_FS #undef USE_EXPERIMENTAL_FS
#endif #endif
@ -653,6 +654,7 @@ namespace olc
void DrawRotatedDecal(const olc::vf2d& pos, olc::Decal* decal, const float fAngle, const olc::vf2d& center = { 0.0f, 0.0f }, const olc::vf2d& scale = { 1.0f,1.0f }, const olc::Pixel& tint = olc::WHITE); void DrawRotatedDecal(const olc::vf2d& pos, olc::Decal* decal, const float fAngle, const olc::vf2d& center = { 0.0f, 0.0f }, const olc::vf2d& scale = { 1.0f,1.0f }, const olc::Pixel& tint = olc::WHITE);
void DrawStringDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f });
// Draws a single line of text // Draws a single line of text
void DrawString(int32_t x, int32_t y, const std::string& sText, Pixel col = olc::WHITE, uint32_t scale = 1); void DrawString(int32_t x, int32_t y, const std::string& sText, Pixel col = olc::WHITE, uint32_t scale = 1);
@ -688,6 +690,7 @@ namespace olc
float fFrameTimer = 1.0f; float fFrameTimer = 1.0f;
int nFrameCount = 0; int nFrameCount = 0;
Sprite* fontSprite = nullptr; Sprite* fontSprite = nullptr;
Decal* fontDecal = nullptr;
Sprite* pDefaultDrawTarget = nullptr; Sprite* pDefaultDrawTarget = nullptr;
std::vector<LayerDesc> vLayers; std::vector<LayerDesc> vLayers;
uint8_t nTargetLayer = 0; uint8_t nTargetLayer = 0;
@ -1192,8 +1195,7 @@ namespace olc
if (vPixelSize.x <= 0 || vPixelSize.y <= 0 || vScreenSize.x <= 0 || vScreenSize.y <= 0) if (vPixelSize.x <= 0 || vPixelSize.y <= 0 || vScreenSize.x <= 0 || vScreenSize.y <= 0)
return olc::FAIL; return olc::FAIL;
// Construct default font sheet
olc_ConstructFontSheet();
return olc::OK; return olc::OK;
} }
@ -1890,6 +1892,25 @@ namespace olc
DrawWarpedDecal(decal, &pos[0], tint); DrawWarpedDecal(decal, &pos[0], tint);
} }
void PixelGameEngine::DrawStringDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col, const olc::vf2d& scale)
{
olc::vf2d spos = { 0.0f, 0.0f };
for (auto c : sText)
{
if (c == '\n')
{
spos.x = 0; spos.y += 8.0f * scale.y;
}
else
{
int32_t ox = (c - 32) % 16;
int32_t oy = (c - 32) / 16;
DrawPartialDecal(pos + spos, fontDecal, { float(ox) * 8.0f, float(oy) * 8.0f }, { 8.0f, 8.0f }, scale, col);
spos.x += 8.0f * scale.x;
}
}
}
void PixelGameEngine::DrawString(const olc::vi2d& pos, const std::string& sText, Pixel col, uint32_t scale) void PixelGameEngine::DrawString(const olc::vi2d& pos, const std::string& sText, Pixel col, uint32_t scale)
{ DrawString(pos.x, pos.y, sText, col, scale); } { DrawString(pos.x, pos.y, sText, col, scale); }
@ -2058,6 +2079,9 @@ namespace olc
// Start OpenGL, the context is owned by the game thread // Start OpenGL, the context is owned by the game thread
if (platform->CreateGraphics(bFullScreen, bEnableVSYNC, vViewPos, vViewSize) == olc::FAIL) return; if (platform->CreateGraphics(bFullScreen, bEnableVSYNC, vViewPos, vViewSize) == olc::FAIL) return;
// Construct default font sheet
olc_ConstructFontSheet();
// Create Primary Layer "0" // Create Primary Layer "0"
CreateLayer(); CreateLayer();
vLayers[0].bUpdate = true; vLayers[0].bUpdate = true;
@ -2210,6 +2234,8 @@ namespace olc
if (++py == 48) { px++; py = 0; } if (++py == 48) { px++; py = 0; }
} }
} }
fontDecal = new olc::Decal(fontSprite);
} }
// Need a couple of statics as these are singleton instances // Need a couple of statics as these are singleton instances
@ -2239,7 +2265,7 @@ namespace olc
typedef HGLRC glRenderContext_t; typedef HGLRC glRenderContext_t;
#endif #endif
#if defined(__linux__) #if defined(__linux__) || defined(__FreeBSD__)
#include <GL/gl.h> #include <GL/gl.h>
namespace X11 namespace X11
{ {
@ -2262,7 +2288,7 @@ namespace olc
glDeviceContext_t glDeviceContext = 0; glDeviceContext_t glDeviceContext = 0;
glRenderContext_t glRenderContext = 0; glRenderContext_t glRenderContext = 0;
#if defined(__linux__) #if defined(__linux__) || defined(__FreeBSD__)
X11::Display* olc_Display = nullptr; X11::Display* olc_Display = nullptr;
X11::Window* olc_Window = nullptr; X11::Window* olc_Window = nullptr;
X11::XVisualInfo* olc_VisualInfo = nullptr; X11::XVisualInfo* olc_VisualInfo = nullptr;
@ -2297,7 +2323,7 @@ namespace olc
if (wglSwapInterval && !bVSYNC) wglSwapInterval(0); if (wglSwapInterval && !bVSYNC) wglSwapInterval(0);
#endif #endif
#if defined(__linux__) #if defined(__linux__) || defined(__FreeBSD__)
using namespace X11; using namespace X11;
// Linux has tighter coupling between OpenGL and X11, so we store // Linux has tighter coupling between OpenGL and X11, so we store
// various "platform" handles in the renderer // various "platform" handles in the renderer
@ -2337,7 +2363,7 @@ namespace olc
wglDeleteContext(glRenderContext); wglDeleteContext(glRenderContext);
#endif #endif
#if defined(__linux__) #if defined(__linux__) || defined(__FreeBSD__)
glXMakeCurrent(olc_Display, None, NULL); glXMakeCurrent(olc_Display, None, NULL);
glXDestroyContext(olc_Display, glDeviceContext); glXDestroyContext(olc_Display, glDeviceContext);
#endif #endif
@ -2350,7 +2376,7 @@ namespace olc
SwapBuffers(glDeviceContext); SwapBuffers(glDeviceContext);
#endif #endif
#if defined(__linux__) #if defined(__linux__) || defined(__FreeBSD__)
X11::glXSwapBuffers(olc_Display, *olc_Window); X11::glXSwapBuffers(olc_Display, *olc_Window);
#endif #endif
} }
@ -2700,7 +2726,7 @@ namespace olc
// O------------------------------------------------------------------------------O // O------------------------------------------------------------------------------O
// | START PLATFORM: LINUX | // | START PLATFORM: LINUX |
// O------------------------------------------------------------------------------O // O------------------------------------------------------------------------------O
#if defined(__linux__) #if defined(__linux__) || defined(__FreeBSD__)
namespace olc namespace olc
{ {
class Platform_Linux : public olc::Platform class Platform_Linux : public olc::Platform
@ -3029,7 +3055,7 @@ namespace olc
platform = std::make_unique<olc::Platform_Windows>(); platform = std::make_unique<olc::Platform_Windows>();
#endif #endif
#if defined(__linux__) #if defined(__linux__) || defined(__FreeBSD__)
platform = std::make_unique<olc::Platform_Linux>(); platform = std::make_unique<olc::Platform_Linux>();
#endif #endif

Loading…
Cancel
Save