About: dancing characters rendered 1:1 and scaled up with nearest filtering
Framebuffer gains a filter setting (linear by default); the characters' canvases use nearest so they stay pixelated at their larger size. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e713c15030
commit
d8ab5ff018
3 files changed
+21
-13
No files matched your search
+2
-2
@@ -30,8 +30,8 @@ namespace anm2ed
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.x, size.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
|
||||
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ namespace anm2ed
|
||||
GLuint texture{};
|
||||
glm::vec2 size{};
|
||||
glm::vec2 previousSize{};
|
||||
GLint filter{GL_LINEAR}; // how the texture is sampled when drawn scaled; takes effect on the next resize
|
||||
|
||||
Framebuffer();
|
||||
~Framebuffer();
|
||||
|
||||
+18
-11
@@ -167,7 +167,11 @@ namespace anm2ed::imgui::wizard
|
||||
|
||||
void friend_state_load(About::FriendState& state, const resource::friends::Info& info)
|
||||
{
|
||||
if (!state.canvas) state.canvas = std::make_unique<Canvas>(vec2(1.0f, 1.0f));
|
||||
if (!state.canvas)
|
||||
{
|
||||
state.canvas = std::make_unique<Canvas>(vec2(1.0f, 1.0f));
|
||||
state.canvas->filter = GL_NEAREST;
|
||||
}
|
||||
|
||||
state.model = model::Model{};
|
||||
state.textures.clear();
|
||||
@@ -217,12 +221,21 @@ namespace anm2ed::imgui::wizard
|
||||
return ImVec2(std::max(width, 1.0f), std::max(height, 1.0f));
|
||||
}
|
||||
|
||||
void friend_canvas_draw(About::FriendState& state, Resources& resources, ImVec2 displaySize)
|
||||
// The animation's bounds with some room around them.
|
||||
vec4 friend_rect_get(const About::FriendState& state)
|
||||
{
|
||||
auto rect = state.rect;
|
||||
auto padding = std::max(2.0f, std::max(rect.z, rect.w) * FRIEND_PADDING_RATIO);
|
||||
return {rect.x - padding, rect.y - padding, rect.z + padding * 2.0f, rect.w + padding * 2.0f};
|
||||
}
|
||||
|
||||
// Rendered 1:1 into its canvas, which is drawn scaled up with nearest filtering so the pixels stay sharp.
|
||||
void friend_canvas_draw(About::FriendState& state, Resources& resources)
|
||||
{
|
||||
if (!state.isLoaded || !state.canvas) return;
|
||||
|
||||
auto canvasSize = vec2(std::max(displaySize.x, 1.0f), std::max(displaySize.y, 1.0f));
|
||||
state.canvas->size_set(canvasSize);
|
||||
auto rect = friend_rect_get(state);
|
||||
state.canvas->size_set(glm::max(vec2(rect.z, rect.w), vec2(1.0f)));
|
||||
state.canvas->bind();
|
||||
state.canvas->viewport_set();
|
||||
state.canvas->clear(vec4(0.0f));
|
||||
@@ -236,12 +249,6 @@ namespace anm2ed::imgui::wizard
|
||||
|
||||
float zoom = 100.0f;
|
||||
vec2 pan{};
|
||||
auto rect = state.rect;
|
||||
auto padding = std::max(2.0f, std::max(rect.z, rect.w) * FRIEND_PADDING_RATIO);
|
||||
rect.x -= padding;
|
||||
rect.y -= padding;
|
||||
rect.z += padding * 2.0f;
|
||||
rect.w += padding * 2.0f;
|
||||
state.canvas->set_to_rect(zoom, pan, rect);
|
||||
|
||||
auto transform = state.canvas->transform_get(zoom, pan);
|
||||
@@ -288,7 +295,7 @@ namespace anm2ed::imgui::wizard
|
||||
{
|
||||
auto& state = about.friendStates[index];
|
||||
auto size = friend_size_get(state, height);
|
||||
friend_canvas_draw(state, resources, size);
|
||||
friend_canvas_draw(state, resources);
|
||||
if (state.isLoaded)
|
||||
image_premultiplied_draw(drawList, (ImTextureID)(intptr_t)state.canvas->texture, ImVec2(left, max.y - size.y),
|
||||
ImVec2(left + size.x, max.y));
|
||||
|
||||
Reference in new issue
Block a user