添加子纹理裁剪

This commit is contained in:
2025-05-24 13:13:47 +08:00
parent a91d640571
commit 1da0252d6a
10 changed files with 266 additions and 156 deletions

View File

@ -22,6 +22,7 @@
#include "Hazel/Renderer/Buffer.h"
#include "Hazel/Renderer/Shader.h"
#include "Hazel/Renderer/Texture.h"
#include "Hazel/Renderer/SubTexture2D.h"
#include "Hazel/Renderer/VertexArray.h"
#include "Hazel/Renderer/OrthographicCameraController.h"

View File

@ -19,5 +19,11 @@ namespace Hazel
template<typename T>
using Ref = std::shared_ptr<T>;
template<typename T, typename ... Args>
constexpr Ref<T> CreateRef(Args&& ... args)
{
return std::make_shared<T>(std::forward<Args>(args)...);
}
}

View File

@ -29,10 +29,10 @@ namespace Hazel
struct Renderer2DStorage
{
const uint32_t MaxQuad = 100;
const uint32_t MaxQuad = 10000;
const uint32_t MaxVertices = MaxQuad * 4;
const uint32_t MaxIndices = MaxQuad * 6;
static const uint32_t MaxTextureSlots = 32; //TODO: RenderCaps
static constexpr uint32_t MaxTextureSlots = 32; //TODO: RenderCaps
Ref<VertexArray> QuadVertexArray;
Ref<VertexBuffer> QuadVertexBuffer;
@ -159,57 +159,6 @@ namespace Hazel
s_Data.Stats.DrawCalls++;
}
void Renderer2D::DrawQuad(const glm::vec2& position, const glm::vec2& size, const glm::vec4& color)
{
DrawQuad({position.x, position.y, 0.0f}, size, color);
}
void Renderer2D::DrawQuad(const glm::vec3& position, const glm::vec2& size, const glm::vec4& color)
{
HZ_PROFILE_FUNCTION();
if (s_Data.QuadIndexCount >= s_Data.MaxIndices)
{
FlushAndReset();
}
constexpr float texIndex = 0.0f;
constexpr float tilingFactor = 1.0f;
const glm::mat4 transform = glm::translate(glm::mat4(1.0f), position) * glm::scale(glm::mat4(1.0f), { size.x, size.y, 1.0f });
s_Data.QuadVertexBufferPtr->Position = transform * s_Data.QuadVertexPosition[0];
s_Data.QuadVertexBufferPtr->Color = color;
s_Data.QuadVertexBufferPtr->TexCoord = {0.0f, 0.0f};
s_Data.QuadVertexBufferPtr->TexIndex = texIndex;
s_Data.QuadVertexBufferPtr->TilingFactor = tilingFactor;
s_Data.QuadVertexBufferPtr ++;
s_Data.QuadVertexBufferPtr->Position = transform * s_Data.QuadVertexPosition[1];
s_Data.QuadVertexBufferPtr->Color = color;
s_Data.QuadVertexBufferPtr->TexCoord = {1.0f, 0.0f};
s_Data.QuadVertexBufferPtr->TexIndex = texIndex;
s_Data.QuadVertexBufferPtr->TilingFactor = tilingFactor;
s_Data.QuadVertexBufferPtr ++;
s_Data.QuadVertexBufferPtr->Position = transform * s_Data.QuadVertexPosition[2];
s_Data.QuadVertexBufferPtr->Color = color;
s_Data.QuadVertexBufferPtr->TexCoord = {1.0f, 1.0f};
s_Data.QuadVertexBufferPtr->TexIndex = texIndex;
s_Data.QuadVertexBufferPtr->TilingFactor = tilingFactor;
s_Data.QuadVertexBufferPtr ++;
s_Data.QuadVertexBufferPtr->Position = transform * s_Data.QuadVertexPosition[3];
s_Data.QuadVertexBufferPtr->Color = color;
s_Data.QuadVertexBufferPtr->TexCoord = {0.0f, 1.0f};
s_Data.QuadVertexBufferPtr->TexIndex = texIndex;
s_Data.QuadVertexBufferPtr->TilingFactor = tilingFactor;
s_Data.QuadVertexBufferPtr ++;
s_Data.QuadIndexCount += 6;
s_Data.Stats.QuadCount ++;
}
void Renderer2D::Shutdown()
{
HZ_PROFILE_FUNCTION();
@ -236,10 +185,46 @@ namespace Hazel
}
void Renderer2D::DrawQuad(const glm::vec2& position, const glm::vec2& size, const glm::vec4& color)
{
DrawQuad({position.x, position.y, 0.0f}, size, color);
}
void Renderer2D::DrawQuad(const glm::vec3& position, const glm::vec2& size, const glm::vec4& color)
{
HZ_PROFILE_FUNCTION();
if (s_Data.QuadIndexCount >= s_Data.MaxIndices)
{
FlushAndReset();
}
constexpr float texIndex = 0.0f;
constexpr float tilingFactor = 1.0f;
glm::vec2 texCoords[] = {{0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f}};
const glm::mat4 transform = glm::translate(glm::mat4(1.0f), position) * glm::scale(glm::mat4(1.0f), { size.x, size.y, 1.0f });
for (unsigned int i = 0; i < 4; i++)
{
s_Data.QuadVertexBufferPtr->Position = transform * s_Data.QuadVertexPosition[i];
s_Data.QuadVertexBufferPtr->Color = color;
s_Data.QuadVertexBufferPtr->TexCoord = texCoords[i];
s_Data.QuadVertexBufferPtr->TexIndex = texIndex;
s_Data.QuadVertexBufferPtr->TilingFactor = tilingFactor;
s_Data.QuadVertexBufferPtr++;
}
s_Data.QuadIndexCount += 6;
s_Data.Stats.QuadCount ++;
}
void Renderer2D::DrawQuad(const glm::vec2& position, const glm::vec2& size, const Ref<Texture2D>& texture, const float tilingFactor, const glm::vec4& tintColor)
{
DrawQuad({position.x, position.y, 0.0f}, size, texture, tilingFactor, tintColor);
}
void Renderer2D::DrawQuad(const glm::vec3& position, const glm::vec2& size, const Ref<Texture2D>& texture, const float tilingFactor, const glm::vec4& tintColor)
{
HZ_PROFILE_FUNCTION();
@ -248,7 +233,7 @@ namespace Hazel
FlushAndReset();
}
constexpr glm::vec4 color = {1.0f, 1.0f, 1.0f, 1.0f};
glm::vec2 texCoords[] = {{0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f}};
float textureIndex = 0.0f;
@ -271,39 +256,72 @@ namespace Hazel
const glm::mat4 transform = glm::translate(glm::mat4(1.0f), position) * glm::scale(glm::mat4(1.0f), { size.x, size.y, 1.0f });
s_Data.QuadVertexBufferPtr->Position = transform * s_Data.QuadVertexPosition[0];
s_Data.QuadVertexBufferPtr->Color = color;
s_Data.QuadVertexBufferPtr->TexCoord = {0.0f, 0.0f};
for (unsigned int i = 0; i < 4; i++)
{
s_Data.QuadVertexBufferPtr->Position = transform * s_Data.QuadVertexPosition[i];
s_Data.QuadVertexBufferPtr->Color = tintColor;
s_Data.QuadVertexBufferPtr->TexCoord = texCoords[i];
s_Data.QuadVertexBufferPtr->TexIndex = textureIndex;
s_Data.QuadVertexBufferPtr->TilingFactor = tilingFactor;
s_Data.QuadVertexBufferPtr++;
s_Data.QuadVertexBufferPtr->Position = transform * s_Data.QuadVertexPosition[1];
s_Data.QuadVertexBufferPtr->Color = color;
s_Data.QuadVertexBufferPtr->TexCoord = {1.0f, 0.0f};
s_Data.QuadVertexBufferPtr->TexIndex = textureIndex;
s_Data.QuadVertexBufferPtr->TilingFactor = tilingFactor;
s_Data.QuadVertexBufferPtr ++;
s_Data.QuadVertexBufferPtr->Position = transform * s_Data.QuadVertexPosition[2];
s_Data.QuadVertexBufferPtr->Color = color;
s_Data.QuadVertexBufferPtr->TexCoord = {1.0f, 1.0f};
s_Data.QuadVertexBufferPtr->TexIndex = textureIndex;
s_Data.QuadVertexBufferPtr->TilingFactor = tilingFactor;
s_Data.QuadVertexBufferPtr ++;
s_Data.QuadVertexBufferPtr->Position = transform * s_Data.QuadVertexPosition[3];
s_Data.QuadVertexBufferPtr->Color = color;
s_Data.QuadVertexBufferPtr->TexCoord = {0.0f, 1.0f};
s_Data.QuadVertexBufferPtr->TexIndex = textureIndex;
s_Data.QuadVertexBufferPtr->TilingFactor = tilingFactor;
s_Data.QuadVertexBufferPtr ++;
}
s_Data.QuadIndexCount += 6;
s_Data.Stats.QuadCount ++;
}
void Renderer2D::DrawQuad(const glm::vec2& position, const glm::vec2& size, const Ref<SubTexture2D>& subTexture, const float tilingFactor, const glm::vec4& tintColor)
{
DrawQuad({position.x, position.y, 0.0f}, size, subTexture, tilingFactor, tintColor);
}
void Renderer2D::DrawQuad(const glm::vec3& position, const glm::vec2& size, const Ref<SubTexture2D>& subTexture, const float tilingFactor, const glm::vec4& tintColor)
{
HZ_PROFILE_FUNCTION();
if (s_Data.QuadIndexCount >= s_Data.MaxIndices)
{
FlushAndReset();
}
const glm::vec2* texCoords = subTexture->GetTexCoords();
const Ref<Texture2D> texture = subTexture->GetTexture();
float textureIndex = 0.0f;
for (uint32_t i = 1; i < s_Data.TextureSlotIndex; i++)
{
if (*s_Data.TextureSlots[i].get() == *texture.get())
{
textureIndex = (float)i;
break;
}
}
if (textureIndex == 0.0f)
{
textureIndex = (float)s_Data.TextureSlotIndex;
s_Data.TextureSlots[s_Data.TextureSlotIndex] = texture;
s_Data.TextureSlotIndex++;
}
const glm::mat4 transform = glm::translate(glm::mat4(1.0f), position) * glm::scale(glm::mat4(1.0f), { size.x, size.y, 1.0f });
for (unsigned int i = 0; i < 4; i++)
{
s_Data.QuadVertexBufferPtr->Position = transform * s_Data.QuadVertexPosition[i];
s_Data.QuadVertexBufferPtr->Color = tintColor;
s_Data.QuadVertexBufferPtr->TexCoord = texCoords[i];
s_Data.QuadVertexBufferPtr->TexIndex = textureIndex;
s_Data.QuadVertexBufferPtr->TilingFactor = tilingFactor;
s_Data.QuadVertexBufferPtr++;
}
s_Data.QuadIndexCount += 6;
s_Data.Stats.QuadCount ++;
}
void Renderer2D::DrawRotateQuad(const glm::vec2& position, const glm::vec2& size, const float rotation,
const glm::vec4& color)
{
@ -323,38 +341,19 @@ namespace Hazel
constexpr float texIndex = 0.0f;
constexpr float tilingFactor = 1.0f;
glm::vec2 texCoords[] = {{0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f}};
const glm::mat4 transform = glm::translate(glm::mat4(1.0f), position) * glm::rotate(glm::mat4(1.0f), rotation, {0.0f, 0.0f, 1.0f}) * glm::scale(glm::mat4(1.0f), { size.x, size.y, 1.0f });
s_Data.QuadVertexBufferPtr->Position = transform * s_Data.QuadVertexPosition[0];
for (unsigned int i = 0; i < 4; i++)
{
s_Data.QuadVertexBufferPtr->Position = transform * s_Data.QuadVertexPosition[i];
s_Data.QuadVertexBufferPtr->Color = color;
s_Data.QuadVertexBufferPtr->TexCoord = {0.0f, 0.0f};
s_Data.QuadVertexBufferPtr->TexCoord = texCoords[i];
s_Data.QuadVertexBufferPtr->TexIndex = texIndex;
s_Data.QuadVertexBufferPtr->TilingFactor = tilingFactor;
s_Data.QuadVertexBufferPtr++;
s_Data.QuadVertexBufferPtr->Position = transform * s_Data.QuadVertexPosition[1];
s_Data.QuadVertexBufferPtr->Color = color;
s_Data.QuadVertexBufferPtr->TexCoord = {1.0f, 0.0f};
s_Data.QuadVertexBufferPtr->TexIndex = texIndex;
s_Data.QuadVertexBufferPtr->TilingFactor = tilingFactor;
s_Data.QuadVertexBufferPtr ++;
s_Data.QuadVertexBufferPtr->Position = transform * s_Data.QuadVertexPosition[2];
s_Data.QuadVertexBufferPtr->Color = color;
s_Data.QuadVertexBufferPtr->TexCoord = {1.0f, 1.0f};
s_Data.QuadVertexBufferPtr->TexIndex = texIndex;
s_Data.QuadVertexBufferPtr->TilingFactor = tilingFactor;
s_Data.QuadVertexBufferPtr ++;
s_Data.QuadVertexBufferPtr->Position = transform * s_Data.QuadVertexPosition[3];
s_Data.QuadVertexBufferPtr->Color = color;
s_Data.QuadVertexBufferPtr->TexCoord = {0.0f, 1.0f};
s_Data.QuadVertexBufferPtr->TexIndex = texIndex;
s_Data.QuadVertexBufferPtr->TilingFactor = tilingFactor;
s_Data.QuadVertexBufferPtr ++;
}
s_Data.QuadIndexCount += 6;
s_Data.Stats.QuadCount ++;
@ -377,6 +376,7 @@ namespace Hazel
}
float textureIndex = 0.0f;
glm::vec2 texCoords[] = {{0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f}};
for (uint32_t i = 1; i < s_Data.TextureSlotIndex; i++)
{
@ -396,38 +396,69 @@ namespace Hazel
const glm::mat4 transform = glm::translate(glm::mat4(1.0f), position) * glm::rotate(glm::mat4(1.0f), rotation, {0.0f, 0.0f, 1.0f}) * glm::scale(glm::mat4(1.0f), { size.x, size.y, 1.0f });
s_Data.QuadVertexBufferPtr->Position = transform * s_Data.QuadVertexPosition[0];
for (unsigned int i = 0; i < 4; i++)
{
s_Data.QuadVertexBufferPtr->Position = transform * s_Data.QuadVertexPosition[i];
s_Data.QuadVertexBufferPtr->Color = tintColor;
s_Data.QuadVertexBufferPtr->TexCoord = {0.0f, 0.0f};
s_Data.QuadVertexBufferPtr->TexCoord = texCoords[i];
s_Data.QuadVertexBufferPtr->TexIndex = textureIndex;
s_Data.QuadVertexBufferPtr->TilingFactor = tilingFactor;
s_Data.QuadVertexBufferPtr++;
s_Data.QuadVertexBufferPtr->Position = transform * s_Data.QuadVertexPosition[1];
s_Data.QuadVertexBufferPtr->Color = tintColor;
s_Data.QuadVertexBufferPtr->TexCoord = {1.0f, 0.0f};
s_Data.QuadVertexBufferPtr->TexIndex = textureIndex;
s_Data.QuadVertexBufferPtr->TilingFactor = tilingFactor;
s_Data.QuadVertexBufferPtr ++;
s_Data.QuadVertexBufferPtr->Position = transform * s_Data.QuadVertexPosition[2];
s_Data.QuadVertexBufferPtr->Color = tintColor;
s_Data.QuadVertexBufferPtr->TexCoord = {1.0f, 1.0f};
s_Data.QuadVertexBufferPtr->TexIndex = textureIndex;
s_Data.QuadVertexBufferPtr->TilingFactor = tilingFactor;
s_Data.QuadVertexBufferPtr ++;
s_Data.QuadVertexBufferPtr->Position = transform * s_Data.QuadVertexPosition[3];
s_Data.QuadVertexBufferPtr->Color = tintColor;
s_Data.QuadVertexBufferPtr->TexCoord = {0.0f, 1.0f};
s_Data.QuadVertexBufferPtr->TexIndex = textureIndex;
s_Data.QuadVertexBufferPtr->TilingFactor = tilingFactor;
s_Data.QuadVertexBufferPtr ++;
}
s_Data.QuadIndexCount += 6;
s_Data.Stats.QuadCount ++;
}
void Renderer2D::DrawRotateQuad(const glm::vec2& position, const glm::vec2& size, const float rotation,
const Ref<SubTexture2D>& subTexture, const float tilingFactor, const glm::vec4& tintColor)
{
DrawRotateQuad({position.x, position.y, 0.0f}, size, rotation, subTexture, tilingFactor, tintColor);
}
void Renderer2D::DrawRotateQuad(const glm::vec3& position, const glm::vec2& size, const float rotation,
const Ref<SubTexture2D>& subTexture, const float tilingFactor, const glm::vec4& tintColor)
{
HZ_PROFILE_FUNCTION();
if (s_Data.QuadIndexCount >= s_Data.MaxIndices)
{
FlushAndReset();
}
float textureIndex = 0.0f;
const glm::vec2* texCoords = subTexture->GetTexCoords();
const Ref<Texture2D>& texture = subTexture->GetTexture();
for (uint32_t i = 1; i < s_Data.TextureSlotIndex; i++)
{
if (*s_Data.TextureSlots[i].get() == *texture.get())
{
textureIndex = (float)i;
break;
}
}
if (textureIndex == 0.0f)
{
textureIndex = (float)s_Data.TextureSlotIndex;
s_Data.TextureSlots[s_Data.TextureSlotIndex] = texture;
s_Data.TextureSlotIndex++;
}
const glm::mat4 transform = glm::translate(glm::mat4(1.0f), position) * glm::rotate(glm::mat4(1.0f), rotation, {0.0f, 0.0f, 1.0f}) * glm::scale(glm::mat4(1.0f), { size.x, size.y, 1.0f });
for (unsigned int i = 0; i < 4; i++)
{
s_Data.QuadVertexBufferPtr->Position = transform * s_Data.QuadVertexPosition[i];
s_Data.QuadVertexBufferPtr->Color = tintColor;
s_Data.QuadVertexBufferPtr->TexCoord = texCoords[i];
s_Data.QuadVertexBufferPtr->TexIndex = textureIndex;
s_Data.QuadVertexBufferPtr->TilingFactor = tilingFactor;
s_Data.QuadVertexBufferPtr++;
}
s_Data.QuadIndexCount += 6;
s_Data.Stats.QuadCount ++;
}
}

View File

@ -6,6 +6,7 @@
#define RENDERER2D_H
#include "OrthographicCamera.h"
#include "SubTexture2D.h"
#include "Texture.h"
#include "Hazel/Core/Core.h"
@ -24,11 +25,15 @@ namespace Hazel
static void DrawQuad(const glm::vec3& position, const glm::vec2& size, const glm::vec4& color);
static void DrawQuad(const glm::vec2& position, const glm::vec2& size, const Ref<Texture2D>& texture, float tilingFactor = 1.0f, const glm::vec4& tintColor = glm::vec4(1.0f));
static void DrawQuad(const glm::vec3& position, const glm::vec2& size, const Ref<Texture2D>& texture, float tilingFactor = 1.0f, const glm::vec4& tintColor = glm::vec4(1.0f));
static void DrawQuad(const glm::vec2& position, const glm::vec2& size, const Ref<SubTexture2D>& subTexture, float tilingFactor = 1.0f, const glm::vec4& tintColor = glm::vec4(1.0f));
static void DrawQuad(const glm::vec3& position, const glm::vec2& size, const Ref<SubTexture2D>& subTexture, float tilingFactor = 1.0f, const glm::vec4& tintColor = glm::vec4(1.0f));
static void DrawRotateQuad(const glm::vec2& position, const glm::vec2& size, float rotation, const glm::vec4& color);
static void DrawRotateQuad(const glm::vec3& position, const glm::vec2& size, float rotation, const glm::vec4& color);
static void DrawRotateQuad(const glm::vec2& position, const glm::vec2& size, float rotation, const Ref<Texture2D>& texture, float tilingFactor = 1.0f, const glm::vec4& tintColor = glm::vec4(1.0f));
static void DrawRotateQuad(const glm::vec3& position, const glm::vec2& size, float rotation, const Ref<Texture2D>& texture, float tilingFactor = 1.0f, const glm::vec4& tintColor = glm::vec4(1.0f));
static void DrawRotateQuad(const glm::vec2& position, const glm::vec2& size, float rotation, const Ref<SubTexture2D>& subTexture, float tilingFactor = 1.0f, const glm::vec4& tintColor = glm::vec4(1.0f));
static void DrawRotateQuad(const glm::vec3& position, const glm::vec2& size, float rotation, const Ref<SubTexture2D>& subTexture, float tilingFactor = 1.0f, const glm::vec4& tintColor = glm::vec4(1.0f));
static void Shutdown();

View File

@ -0,0 +1,25 @@
//
// Created by sfd on 25-5-24.
//
#include "SubTexture2D.h"
namespace Hazel
{
SubTexture2D::SubTexture2D(const Ref<Texture2D>& texture, const glm::vec2& min, const glm::vec2& max)
: m_Texture(texture)
{
m_TexCoords[0] = {min.x, min.y};
m_TexCoords[1] = {max.x, min.y};
m_TexCoords[2] = {max.x, max.y};
m_TexCoords[3] = {min.x, max.y};
}
Ref<SubTexture2D> SubTexture2D::CreateFromCoords(const Ref<Texture2D>& texture, const glm::vec2& coords, const glm::vec2& cellSize, const glm::vec2& spriteSize)
{
glm::vec2 min = {(coords.x * cellSize.x) / texture->GetWidth(), (coords.y * cellSize.y) / texture->GetHeight()};
glm::vec2 max = {((coords.x + spriteSize.x) * cellSize.x) / texture->GetWidth(), ((coords.y + spriteSize.y) * cellSize.y) / texture->GetHeight()};
return CreateRef<SubTexture2D>(texture, min, max);
}
}

View File

@ -0,0 +1,31 @@
//
// Created by sfd on 25-5-24.
//
#ifndef SUBTEXTURE2D_H
#define SUBTEXTURE2D_H
#include <Hazel/Core/Core.h>
#include "Texture.h"
#include "glm/vec2.hpp"
namespace Hazel
{
class HAZEL_API SubTexture2D
{
public:
SubTexture2D(const Ref<Texture2D>& texture, const glm::vec2& min, const glm::vec2& max);
const Ref<Texture2D>& GetTexture() const { return m_Texture; }
const glm::vec2* GetTexCoords() const { return m_TexCoords; }
static Ref<SubTexture2D> CreateFromCoords(const Ref<Texture2D>& texture, const glm::vec2& coords, const glm::vec2& cellSize, const glm::vec2& spriteSize = {1.0f,1.0f});
private:
Ref<Texture2D> m_Texture;
glm::vec2 m_TexCoords[4];
};
}
#endif //SUBTEXTURE2D_H

Binary file not shown.

After

Width:  |  Height:  |  Size: 328 KiB

View File

@ -43,7 +43,7 @@ private:
};
std::vector<Particle> m_particlePool;
uint32_t m_PoolIndex = 5000;
uint32_t m_PoolIndex = 1000;
};

View File

@ -17,10 +17,12 @@ void SandBox2D::OnAttach()
{
HZ_PROFILE_FUNCTION();
m_LogoTexture = Hazel::Texture2D::Create("assets/textures/iceLogo.png");
m_Texture = Hazel::Texture2D::Create("assets/textures/spritesheet-tiles-double.png");
m_SubTexture = Hazel::SubTexture2D::CreateFromCoords(m_Texture, {8, 5}, {128, 128}, {1, 2});
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};
m_Particle.SizeBegin = 0.5f, m_Particle.SizeVariation = 0.3f, m_Particle.SizeEnd = 0.0f;
m_Particle.SizeBegin = 0.3f, m_Particle.SizeVariation = 0.3f, m_Particle.SizeEnd = 0.0f;
m_Particle.LifeTime = 1.0f;
m_Particle.Velocity = {0.0f, 0.0f};
m_Particle.VelocityVariation = {2.0f, 2.0f};
@ -53,22 +55,25 @@ void SandBox2D::OnUpdate(Hazel::TimeStep& ts)
Hazel::Renderer2D::BeginScene(m_CameraController.GetCamera());
Hazel::Renderer2D::DrawRotateQuad({0.0f, 0.0f}, {1.0f, 1.0f}, 45.f, {1.0f, 1.0f, 1.0f, 1.0f});
// Hazel::Renderer2D::DrawQuad({0, 0}, {1.0f,1.0f}, {1.0f, 1.0f, 1.0f, 1.0f});
Hazel::Renderer2D::DrawRotateQuad({-0.5f, 0}, {1.0f,1.0f}, glm::radians(0.f), m_LogoTexture);
// Hazel::Renderer2D::DrawQuad({0.5f, 0}, {1.0f,1.0f}, m_Texture);
Hazel::Renderer2D::DrawQuad({0.5f, 0}, {1.0f,2.0f}, m_SubTexture);
// Hazel::Renderer2D::DrawRotateQuad({-1.0f, 0.0f}, {0.5f, 0.5f}, 75.f, {1.0f, 0.0f, 1.0f, 1.0f});
// Hazel::Renderer2D::DrawRotateQuad({0.0f, 0.0f}, {1.0f, 1.0f}, rotation, m_LogoTexture, 10.f);
// for (float y = -5.0f; y < 5.0f; y += 0.5f)
// {
// for (float x = -5.0f; x < 5.0f; x += 0.5f)
// {
// auto color = glm::vec4((x + 5.0f ) /10.0f, 0.4f, (y + 5.0f) / 10.0f, 1.0f);
// Hazel::Renderer2D::DrawQuad({x, y}, {0.45f, 0.45f}, color);
// }
// }
for (float y = -5.0f; y < 5.0f; y += 0.5f)
{
for (float x = -5.0f; x < 5.0f; x += 0.5f)
{
auto color = glm::vec4((x + 5.0f ) /10.0f, 0.4f, (y + 5.0f) / 10.0f, 1.0f);
Hazel::Renderer2D::DrawQuad({x, y, -0.1f}, {0.45f, 0.45f}, m_LogoTexture, 1, color);
}
}
Hazel::Renderer2D::EndScene();
if (mouseState & SDL_BUTTON_LMASK)
if ((mouseState & SDL_BUTTON_LMASK) && m_CurrentWindowID == Hazel::Application::Get().GetWindow().GetMainWindowID())
{
auto width = Hazel::Application::Get().GetWindow().GetWidth();
auto height = Hazel::Application::Get().GetWindow().GetHeight();
@ -145,5 +150,8 @@ void SandBox2D::OnImGuiRender()
void SandBox2D::OnEvent(SDL_Event& e)
{
if (m_CurrentWindowID != e.window.windowID)
m_CurrentWindowID = e.window.windowID;
m_CameraController.OnEvent(e);
}

View File

@ -24,6 +24,7 @@ private:
Hazel::Ref<Hazel::Shader> m_FlatColorShader;
Hazel::Ref<Hazel::Texture2D> m_Texture;
Hazel::Ref<Hazel::Texture2D> m_LogoTexture;
Hazel::Ref<Hazel::SubTexture2D> m_SubTexture;
glm::vec4 m_BackgroundColor = {0.2f, 0.2f, 0.2f, 1.0f};
@ -37,6 +38,8 @@ private:
ParticleSystem m_ParticleSystem;
ParticleProp m_Particle;
SDL_WindowID m_CurrentWindowID;
};