Text Rendering

This commit is contained in:
Isuru Samarathunga
2025-10-20 23:39:54 +05:30
parent d4e93b047c
commit b10aacaee7
40 changed files with 1295 additions and 297 deletions

View File

@ -0,0 +1,54 @@
// IAEngine: 2D Game Engine by IA
// Copyright (C) 2025 IASoft (PVT) LTD (oss@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <IAEngine/Base.hpp>
#include <SDL3/SDL.h>
namespace ia::iae
{
class FontManager
{
public:
struct Character
{
IVec2 Size;
IVec2 Bearing; // Offset from baseline to left/top of glyph
UINT32 Advance; // Horizontal offset to advance to next glyph
SDL_GPUTexture *Texture{};
};
struct Font
{
Character Chars[0x80];
};
public:
STATIC VOID Initialize();
STATIC VOID Terminate();
STATIC VOID LoadFont(IN CONST String &name, IN CONST String &path);
STATIC CONST Font &GetFont(IN CONST String &name)
{
return s_fonts[name];
}
private:
STATIC Map<String, Font> s_fonts;
};
} // namespace ia::iae

View File

@ -24,41 +24,70 @@ namespace ia::iae
{
class InputManager
{
public:
struct KeyboardGamePadMapping
{
IN InputKey AxisLeft;
IN InputKey AxisRight;
IN InputKey AxisDown;
IN InputKey AxisUp;
IN InputKey ButtonA;
IN InputKey ButtonB;
IN InputKey ButtonC;
IN InputKey ButtonD;
};
public:
STATIC VOID Initialize();
STATIC VOID Terminate();
STATIC VOID OnSDLEvent(IN SDL_Event *event);
STATIC Vec2 GetAxis();
STATIC VOID SwitchModeToText();
STATIC VOID SwitchModeToAction();
STATIC Vec2 GetPointerPosition();
STATIC BOOL IsKeyDown(IN InputKey key);
STATIC BOOL WasKeyPressed(IN InputKey key);
STATIC BOOL WasKeyReleased(IN InputKey key);
STATIC BOOL IsActionDown(IN Handle action);
STATIC BOOL WasActionPressed(IN Handle action);
STATIC BOOL WasActionReleased(IN Handle action);
STATIC BOOL IsActionDown(IN CONST String& action);
STATIC BOOL WasActionPressed(IN CONST String& action);
STATIC BOOL WasActionReleased(IN CONST String& action);
STATIC Handle BindAction(IN CONST String &name, IN InputKey key);
STATIC VOID BindAxis(IN InputKey upKey, IN InputKey downKey, IN InputKey leftKey, IN InputKey rightKey);
STATIC VOID SetAxisUp(IN BOOL v);
STATIC VOID SetAxisDown(IN BOOL v);
STATIC VOID SetAxisLeft(IN BOOL v);
STATIC VOID SetAxisRight(IN BOOL v);
STATIC VOID SetKey(IN InputKey key, IN BOOL state);
STATIC VOID SetAxis(IN BOOL up, IN BOOL down, IN BOOL left, IN BOOL right);
STATIC VOID SetupOnScreenGamePad();
STATIC VOID SetupKeyboardGamePad(IN CONST KeyboardGamePadMapping& mapping);
STATIC BOOL GetButtonA();
STATIC BOOL GetButtonB();
STATIC BOOL GetButtonC();
STATIC BOOL GetButtonD();
STATIC INT16 GetVerticalAxis();
STATIC INT16 GetHorizontalAxis();
STATIC IVec2 GetDirectionalInput();
STATIC VOID SetButtonA(IN BOOL value);
STATIC VOID SetButtonB(IN BOOL value);
STATIC VOID SetButtonC(IN BOOL value);
STATIC VOID SetButtonD(IN BOOL value);
STATIC VOID SetVerticalAxis(IN INT16 value);
STATIC VOID SetHorizontalAxis(IN INT16 value);
private:
STATIC BOOL s_buttonA;
STATIC BOOL s_buttonB;
STATIC BOOL s_buttonC;
STATIC BOOL s_buttonD;
STATIC INT16 s_verticalAxis;
STATIC INT16 s_horizontalAxis;
STATIC BOOL s_keys[256];
STATIC BOOL s_prevKeys[256];
STATIC Vec2 s_pointerPosition;
STATIC InputKey s_axisInputs[4];
STATIC Map<String, Handle> s_actionNames;
STATIC Vector<Vector<InputKey>> s_actions;
STATIC BOOL s_onScreenGamePadEnabled;
STATIC BOOL s_keyboardGamePadEnabled;
STATIC KeyboardGamePadMapping s_keyboardGamePadMapping;
private:
STATIC VOID Initialize();
STATIC VOID Terminate();
STATIC VOID Draw();
STATIC VOID Update();
STATIC VOID OnSDLEvent(IN SDL_Event *event);
friend class __Internal_Engine;
};
} // namespace ia::iae

View File

@ -71,6 +71,7 @@ namespace ia::iae
STATIC VOID DestroyGeometry(IN Geometry* handle);
STATIC VOID DrawGeometry(IN Geometry* handle, IN UINT8 layer, IN UINT16 sortIndex);
STATIC VOID DrawText(IN CONST String& text, IN Vec2 position, IN FLOAT32 scale, IN FLOAT32 rotation, IN UINT8 layer, IN UINT16 sortIndex);
STATIC SDL_GPUTextureFormat GetRenderTargetFormat();
@ -89,6 +90,7 @@ namespace ia::iae
STATIC Pipeline* s_geometryPipeline;
STATIC Pipeline* s_postprocessPipeline;
STATIC Geometry* s_quadGeometry;
STATIC Geometry* s_circleGeometry;
STATIC Vector<DrawEntry> s_drawEntries;
STATIC SDL_GPURenderPass* s_activeRenderPass;
STATIC SDL_GPUCommandBuffer* s_activeCommandBuffer;

View File

@ -37,12 +37,12 @@ namespace ia::iae
public:
STATIC Scene *GetActiveScene();
STATIC VOID ChangeActiveScene(IN RefPtr<Scene> scene);
STATIC VOID ChangeActiveScene(IN Scene* scene);
STATIC VOID AddNodeToActiveScene(IN RefPtr<INode> node);
STATIC INode *GetNodeFromActiveScene(IN CONST String &name);
STATIC VOID RemoveNodeFromActiveScene(IN CONST String &name);
private:
STATIC RefPtr<Scene> s_activeScene;
STATIC Scene* s_activeScene;
};
} // namespace ia::iae