Components¶
spriterender加上纹理
#include "Hazel/Renderer/Texture.h"
{
Ref<Texture2D> Texture;
float TilingFactor = 1.0f;
}
SceneHierachyPanel¶
主要就还是增加了一个texture的按钮,并检测是否有被拖拽,有的话就根据路径读一下文件并创建材质
DrawComponent<SpriteRendererComponent>("Sprite Renderer", entity, [](auto& component)
{
ImGui::ColorEdit4("Color", glm::value_ptr(component.Color));
ImGui::Button("Texture", ImVec2(100.0f, 0.0f));
if (ImGui::BeginDragDropTarget())
{
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("CONTENT_BROWSER_ITEM"))
{
const wchar_t* path = (const wchar_t*)payload->Data;
std::filesystem::path texturePath = std::filesystem::path(g_AssetPath) / path;
component.Texture = Texture2D::Create(texturePath.string());
}
ImGui::EndDragDropTarget();
}
ImGui::DragFloat("Tiling Factor", &component.TilingFactor, 0.1f, 0.0f, 100.0f);
});
Renderer2D.cpp¶
有材质,画图形,没材质,画color
void Renderer2D::DrawSprite(const glm::mat4& transform, SpriteRendererComponent& src, int entityID)
{
if (src.Texture)
DrawQuad(transform, src.Texture, src.TilingFactor, src.Color, entityID);
else
DrawQuad(transform, src.Color, entityID);
}
展示效果¶
显然还有Fighting的问题