添加 文本渲染
This commit is contained in:
@ -1,6 +1,19 @@
|
||||
set(PROJECT_NAME "Sandbox")
|
||||
set(PROJECT_NAME "Sandbox-Example")
|
||||
|
||||
# SandBox
|
||||
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin-int)
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin-int)
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
|
||||
# set MSVC output directory
|
||||
if(MSVC)
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
||||
endif ()
|
||||
|
||||
# SandBox-Example
|
||||
project(${PROJECT_NAME})
|
||||
file(GLOB_RECURSE SOURCES
|
||||
src/**.cpp
|
||||
@ -8,4 +21,4 @@ file(GLOB_RECURSE SOURCES
|
||||
|
||||
add_executable(${PROJECT_NAME} ${SOURCES})
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE Hazel)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE Hazel-shared)
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
#include <imgui.h>
|
||||
|
||||
#include "glm/gtc/type_ptr.hpp"
|
||||
#include "Hazel/Core/Input.h"
|
||||
|
||||
static constexpr uint32_t s_MapWidth = 24;
|
||||
static const char* s_MapTiles =
|
||||
@ -46,9 +47,11 @@ void SandBox2D::OnAttach()
|
||||
m_TextureMap['W'] = Hazel::SubTexture2D::CreateFromCoords(m_Texture, {0, 11}, {128, 128});
|
||||
// m_SubTexture = Hazel::SubTexture2D::CreateFromCoords(m_Texture, {8, 5}, {128, 128}, {1, 2});
|
||||
Hazel::FrameBufferSpecification specification;
|
||||
specification.Width = 1280;
|
||||
specification.Height = 720;
|
||||
m_FrameBuffer = Hazel::FrameBuffer::Create(specification);
|
||||
specification.Width = 1280;
|
||||
specification.Height = 720;
|
||||
specification.Attachments = {Hazel::FrameBufferTextureFormat::RGBA8, Hazel::FrameBufferTextureFormat::RED_INTEGER, Hazel::FrameBufferTextureFormat::DEPTH };
|
||||
m_FrameBuffer = Hazel::FrameBuffer::Create(specification);
|
||||
m_ViewPortSize = {specification.Width, m_ViewPortSize.y};
|
||||
|
||||
m_Particle.ColorBegin = {0 / 255.f, 212 / 255.f, 123 / 255.f, 1.0f};
|
||||
m_Particle.ColorEnd = {254 / 255.f, 109 / 255.f, 41 / 255.f, 1.0f};
|
||||
@ -66,13 +69,19 @@ void SandBox2D::OnDetech()
|
||||
|
||||
void SandBox2D::OnUpdate(Hazel::TimeStep& ts)
|
||||
{
|
||||
auto mouseState = SDL_GetMouseState(NULL, NULL);
|
||||
const auto mouseState = Hazel::Input::GetMouseState();
|
||||
// PROFILE_SCOPE("SandBox2D::OnUpdate");
|
||||
HZ_PROFILE_FUNCTION();
|
||||
|
||||
Hazel::Renderer2D::ResetStats();
|
||||
m_CameraController.OnUpdate(ts);
|
||||
|
||||
if (const auto& spec = m_FrameBuffer->GetSpecification();
|
||||
spec.Width != m_ViewPortSize.x || spec.Height != m_ViewPortSize.y)
|
||||
{
|
||||
m_FrameBuffer->Resize((uint32_t)m_ViewPortSize.x, (uint32_t)m_ViewPortSize.y);
|
||||
}
|
||||
|
||||
{
|
||||
HZ_PROFILE_SCOPE("Renderer Prep");
|
||||
|
||||
@ -112,7 +121,7 @@ void SandBox2D::OnUpdate(Hazel::TimeStep& ts)
|
||||
auto height = Hazel::Application::Get().GetWindow().GetHeight();
|
||||
|
||||
float x, y;
|
||||
SDL_GetMouseState(&x, &y);
|
||||
Hazel::Input::GetMouseState(&x, &y);
|
||||
auto bounds = m_CameraController.GetBounds();
|
||||
auto cameraPos = m_CameraController.GetCamera().GetPosition();
|
||||
|
||||
@ -135,11 +144,7 @@ void SandBox2D::OnUpdate(Hazel::TimeStep& ts)
|
||||
void SandBox2D::OnImGuiRender()
|
||||
{
|
||||
|
||||
ImGui::Begin("Settings");
|
||||
ImGui::Image(m_FrameBuffer->GetColorAttachmentID(), {1280.f, 720.f});
|
||||
ImGui::End();
|
||||
|
||||
static bool showDockspace = false;
|
||||
static bool showDockspace = true;
|
||||
if (showDockspace)
|
||||
{
|
||||
// const auto cameraRotation = m_CameraController.GetCamera().GetRotation();
|
||||
@ -220,6 +225,15 @@ void SandBox2D::OnImGuiRender()
|
||||
ImGui::EndMenuBar();
|
||||
}
|
||||
|
||||
{
|
||||
ImVec2 viewPortPanelSize = ImGui::GetContentRegionAvail();
|
||||
if (m_ViewPortSize != *reinterpret_cast<glm::vec2*>(&viewPortPanelSize))
|
||||
{
|
||||
m_ViewPortSize = {viewPortPanelSize.x, viewPortPanelSize.y};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
ImGui::Begin("Hazel Layer");
|
||||
|
||||
|
||||
@ -27,6 +27,7 @@ private:
|
||||
Hazel::Ref<Hazel::SubTexture2D> m_defaultTexture;
|
||||
Hazel::Ref<Hazel::FrameBuffer> m_FrameBuffer;
|
||||
|
||||
glm::vec2 m_ViewPortSize = {0.0f, 0.0f};
|
||||
glm::vec4 m_BackgroundColor = {0.2f, 0.2f, 0.2f, 1.0f};
|
||||
|
||||
struct ProfileResult
|
||||
|
||||
Reference in New Issue
Block a user