ULRE/example/GUI/DrawText.cpp

93 lines
1.9 KiB
C++
Raw Normal View History

2024-07-26 03:27:32 +08:00
#include<hgl/io/LoadString.h>
2022-02-16 23:26:50 +08:00
#include<hgl/graph/font/TextRender.h>
2020-07-08 21:56:39 +08:00
#include"VulkanAppFramework.h"
2020-06-28 22:16:07 +08:00
using namespace hgl;
2020-07-08 21:56:39 +08:00
using namespace hgl::graph;
2020-07-31 18:01:28 +08:00
constexpr uint32_t SCREEN_WIDTH =1280;
2020-08-04 18:28:34 +08:00
constexpr uint32_t SCREEN_HEIGHT=SCREEN_WIDTH/16*9;
2020-07-08 21:56:39 +08:00
2024-07-26 03:27:32 +08:00
class TestApp:public CameraAppFramework
2022-02-16 18:19:41 +08:00
{
private:
TextRender * text_render =nullptr;
TextPrimitive * text_primitive =nullptr;
Renderable * render_obj =nullptr;
2022-02-16 18:19:41 +08:00
public:
~TestApp()
{
SAFE_CLEAR(text_render)
}
2022-02-16 18:19:41 +08:00
private:
bool InitTextRenderable()
{
2025-01-04 14:14:47 +08:00
U16String str;
LoadStringFromTextFile(str,OS_TEXT("res/text/DaoDeBible.txt"));
if(str.IsEmpty())return(false);
2022-02-17 20:02:59 +08:00
FontSource *fs=AcquireFontSource(OS_TEXT("微软雅黑"),12);
2022-02-17 11:02:55 +08:00
text_render=CreateTextRender(device,fs,device_render_pass,ubo_camera_info,str.Length());
2022-02-17 11:02:55 +08:00
if(!text_render)
return(false);
text_primitive=text_render->CreatePrimitive(str);
if(!text_primitive)
2022-02-16 18:19:41 +08:00
return(false);
2020-09-28 11:16:45 +08:00
render_obj=text_render->CreateRenderable(text_primitive);
if(!render_obj)
2022-02-16 18:19:41 +08:00
return(false);
2022-02-16 18:19:41 +08:00
return(true);
}
2020-07-08 21:56:39 +08:00
public:
bool Init()
{
2020-07-31 18:01:28 +08:00
if(!VulkanApplicationFramework::Init(SCREEN_WIDTH,SCREEN_HEIGHT))
return(false);
if(!InitTextRenderable())
return(false);
2022-02-16 18:19:41 +08:00
2024-07-26 03:27:32 +08:00
VulkanApplicationFramework::BuildCommandBuffer(render_obj);
2020-07-08 21:56:39 +08:00
return(true);
}
2024-07-26 03:27:32 +08:00
void Resize(uint w,uint h)override
2020-07-08 21:56:39 +08:00
{
VulkanApplicationFramework::Resize(w,h);
2020-09-28 11:16:45 +08:00
2024-07-26 03:27:32 +08:00
VulkanApplicationFramework::BuildCommandBuffer(render_obj);
}
void BuildCommandBuffer(uint32_t index)
{
VulkanApplicationFramework::BuildCommandBuffer(index,render_obj);
2020-07-08 21:56:39 +08:00
}
};//class TestApp:public VulkanApplicationFramework
2020-07-31 18:01:28 +08:00
int main(int,char **)
2020-07-08 21:56:39 +08:00
{
TestApp app;
2020-06-28 22:16:07 +08:00
2020-07-08 21:56:39 +08:00
if(!app.Init())
return(-1);
2020-06-28 22:16:07 +08:00
2020-07-08 21:56:39 +08:00
while(app.Run());
2020-06-28 22:16:07 +08:00
2020-07-08 21:56:39 +08:00
return 0;
}